I have a Makefile
:
foo:
touch foo
touch bar
%/:
mkdir -p $@
dir/%: % | dir/
rm -f $@
ln $< $@
foobar: dir/foo dir/bar
But it doesn't work as one might think it should:
$ rm -rf dir foo bar; make foobar
touch foo
touch bar
mkdir -p dir/
rm -f dir/foo
ln foo dir/foo
make: *** No rule to make target 'dir/bar', needed by 'foobar'. Stop.
Everything looks good for dir/bar
to be created:
$ ls -l foo bar dir/
-rw-rw-r--. 1 brian brian 0 Jan 28 12:53 bar
-rw-rw-r--. 2 brian brian 0 Jan 28 12:53 foo
dir/:
total 0
-rw-rw-r--. 2 brian brian 0 Jan 28 12:53 foo
Subsequently trying to create dir/bar
even works:
$ make dir/bar
rm -f dir/bar
ln bar dir/bar
What am I missing?
question from:https://stackoverflow.com/questions/65944715/target-fails-to-build-in-some-cases