I wrote a makefile in an empty directory like this:
@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.
$(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