Makefile executes phonytargets of a file only if the file does not exist

Is there any way to execute a fake file dependency if this file does not exist?

If the file does not have a fake dependency, it works and only executes the content of this rule. But if I add a fake target as a dependency, it continues to execute the dependency rule and the existing file generation rule.

I simplified my Makefile so you can see my problem:

 .PHONY: phonytarget all clean all: $(CURDIR)/aa @echo done $(CURDIR)/aa: phonytarget @touch $@ phonytarget: @echo what the heck is wrong with you 
+8
dependencies makefile
source share
1 answer

Use the prerequisites for ordering :

Sometimes, however, you have a situation where you want to impose a specific order in the rules that should be invoked, without forcing the target to be updated if one of these rules is met. In this case, you want to determine the prerequisites for the order only. Prerequisites for ordering can be specified by placing the pipe symbol ( | ) in the list of prerequisites: any prerequisites to the left of the pipe symbol are normal; any prerequisites on the right have only the order:

 targets : normal-prerequisites | order-only-prerequisites 

Of course, the normal section of prerequisites may be empty. In addition, you can still declare multiple lines of prerequisites for the same purpose: they are appended appropriately (the usual prerequisites are added to the list of usual prerequisites, and the pre-conditions for the order only are added to the list of prerequisites for the order only).

 .PHONY: phonytarget all clean all: $(CURDIR)/aa @echo done $(CURDIR)/aa: | phonytarget @touch $@ phonytarget: @echo what the hack is wrong with you 
+7
source share

All Articles