当前位置: 动力学知识库 > 问答 > 编程问答 >

makefile - what wrong the $(wildcard )?

问题描述:

I wrote a makefile in an empty directory like this:

file_src=$(wildcard *.c)

display_file:

@touch o.c&&echo $(file_src)

Then I ran make, but nothing was printed. Why is there no "o.c" printed?

网友答案:

Because you have the order of operations wrong.

You are expecting make to expand $(file_src) (and thus the $(wildcard) call) after it runs the touch but that's not what happens.

Make expands $(file_src) (and the $(wildcard) call) before executing any of the recipe contents.

You can see this here:

$ cat Makefile
$(info echo Manual shell check)$(shell ls *.created)

file_src=$(shell touch make.created)

all:
        echo First recipe line; ls *.created
        echo $(file_src)
        touch recipe.created
        echo Final recipe line; ls *.created
$ ls
Makefile
$ make
echo Manual shell check
ls: *.created: No such file or directory
echo First recipe line; ls *.created
First recipe line
make.created
echo

touch recipe.created
echo Final recipe line; ls *.created
Final recipe line
make.created  recipe.created
分享给朋友:
您可能感兴趣的文章:
随机阅读: