let subst env rule =
let subst_resources = List.map (Resource.subst env) in
let subst_resource_patterns = List.map (Resource.subst_pattern env) in
let finder next_finder p = next_finder (Resource.subst_any env p) in
let stamp = match rule.stamp with None -> None | Some x -> Some (Resource.subst_pattern env x) in
let prods = subst_resource_patterns rule.prods in
{ (rule) with name = sbprintf "%s (%a)" rule.name Resource.print_env env;
prods = prods;
deps = subst_resources rule.deps;
stamp = stamp;
code = (fun env -> rule.code (finder env)) }