Only folder1 is created, whereas, check_dep should be checked twice? Since it is part of .PHONY ?
No. make
determines at most once per run whether any given target is up to date, and it runs any given target's recipe at most once per run. .PHONY
affects only how make
determines whether targets are up to date.
Any solution to this?
It's unclear what "this" you mean.
You could get make
to build check_dep
twice by running make
twice (or more). Via a submake, for example. And it would be horrible.
You could ensure that folders dep1
and dep2
are present and have their timestamps updated by writing proper rules for them. Or only one rule for both targets, if I were doing it:
.PHONY: dep1 dep2
dep1 dep2:
mkdir -p $@
touch $@
Note there that the .PHONY
is needed only because you apparently want unconditionally to touch
the folders. It would be more natural to leave them non-phony, since they correspond to real files (of the directory flavor), and to explicitly update their timestamps only at need, as determined by their prerequisites, if any. In practice, it is rarely necessary to have make
explicitly update directory timestamps.
Note also that your check_dep
target and DEP
variable are wholly unneeded for this alternative.