Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
439 views
in Technique[技术] by (71.8m points)

makefile - target fails to build in some cases

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...