updated_example:
$(if $^,cp -rf $^ example && touch $@)
The recipe for a make rule (i.e., the bunch of shell commands) is stored as a single recursively expanded macro. When make decides it has to re-build a target, it
- Expands said macro
- Passes each line in the expansion one at a time to a shell invocation
In your version, the ifneq
is expanded as make is reading the Makefile, just as it's wondering what to put into the macro representing the recipe. At this point $^
does not exist. In my formulation, I use an $(if ...)
which sits inside the shell recipe. It is expanded only when make starts building updated_example, at which point $^
has appropriate value.