As a variation of [1], I am trying to implement auto-dependency generation
without tracking a list of sources (SRCS). I've managed to get everything
working on make 4.4, and with a few hacks everything except empty recipe
forcing for pattern rules on make 3.8.2. Specifically, I am trying to
effect the following for pattern rules:

"""
If a rule has no prerequisites or recipe, and the target of the rule is a
nonexistent file, then make imagines this target to have been updated
whenever its rule is run. This implies that all targets depending on this
one will always have their recipe run.
"""

I've sketched out a few various test-cases, none of which work. Is it
possible to get this working on 3.8.2?

```
.SUFFIXES:
.SECONDEXPANSION:

#mod.a/test.a:
#test.a:
#mod.a/test.b:
#test.b:
#mod.a/test.c:
#test.c:
#mod.a/test.d:
test.d:

# Not working (empty-recipe forcing)
%.a : foo/[email protected]
@echo "top/a:"
@echo "  @: $@"
@echo "  ^: $^"
mkdir -p foo/$(dir $@)
touch foo/[email protected]
touch $@

# Not working (empty-recipe forcing)
%.b : foo/$$*.z
@echo "top/b:"
@echo "  @: $@"
@echo "  ^: $^"
@echo "  *: $*"
mkdir -p foo/$(dir $*)
touch foo/$*.z
touch $@

# Not working (empty-recipe forcing)
%.c : %.z foo/[email protected]
@echo "top/a:"
@echo "  @: $@"
@echo "  ^: $^"
mkdir -p foo/$(dir $@)
touch foo/[email protected]
touch $@

# Not working (empty-recipe forcing)
%.d : foo/%.z
@echo "top/a:"
@echo "  @: $@"
@echo "  ^: $^"
@echo "  *: $*"
mkdir -p foo/$(dir $@)
touch foo/$*.z
touch $@


# Not working
#%.z:
#
#foo/%.z: FORCE
#FORCE:

# Working as targets only:
%.z: ;
#foo/%.z: ;

# Working as targets + empty-recipe forcing
#foo/mod.a/test.a.z:
#foo/mod.a/test.b.z:
#foo/mod.a/test.c.z:
#foo/test.a.z:
#foo/test.b.z:
#foo/test.c.z:


# Not working (???):
#.PRECIOUS:
#.PRECIOUS: %.a.z
#.PRECIOUS: foo/mod.a/%.a.z
#.PRECIOUS: foo/mod.a/%.z

# Sometimes working (???):
# * It seems to depend on the exact rule above.
.PRECIOUS: %.z
#.PRECIOUS: foo/%.z
#.PRECIOUS: foo/mod.a/test.a.z


clean:
rm -rf mod.a/test.{a..y}
rm -rf test.{a..y}

.PHONY: clean
```

This is the somewhat confusing debug output:

```
Considering target file `mod.a/test.a'.
 Looking for an implicit rule for `mod.a/test.a'.
 Trying pattern rule with stem `test'.
 Trying implicit prerequisite `foo/mod.a/test.a.z'.
 Trying pattern rule with stem `test'.
 Trying implicit prerequisite `foo/mod.a/test.a.z'.
 Looking for a rule with intermediate file `foo/mod.a/test.a.z'.
  Avoiding implicit rule recursion.
  Trying pattern rule with stem `mod.a/test.a'.
 Found an implicit rule for `mod.a/test.a'.
 Finished prerequisites of target file `mod.a/test.a'.
 Prerequisite `foo/mod.a/test.a.z' of target `mod.a/test.a' does not exist.
No need to remake target `mod.a/test.a'.
```

Thanks,


[1]
https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/

Reply via email to