Reputation: 87
I have this makefile, it actually does the job, but I feel it's not pretty. My goal is simple, when someone call "make" for the first time, it will run both compile and staging, but consecutive call to make, it will call compile only. If user wants to run staging, user must call "make staging". Anyone has better idea?
all: compile
.PHONY: compile staging
compile:
@echo "compile"
@test -f ./.staging || make ./.staging
force_staging:
@rm -f ./.staging
staging: force_staging compile
@:
./.staging:
@echo "staging"
@touch $@
Upvotes: 0
Views: 100
Reputation: 3520
This sounds like a job for order only dependencies:
all: compile
compile: | .staging
echo $@
touch $@
.staging:
echo $@
touch $@
staging: .staging compile
Notice that if the user does make staging
, then .staging
will be a regular target and will rebuild if out of date. If the user does make all
, then .staging
will only be rebuilt if it does not exist.
Upvotes: 1
Reputation: 2079
Instead of testing for file existence I think you can add a dependency on .staging
all: compile
.PHONY: compile
compile: ./.staging
@echo "compile"
force_staging:
@rm -f ./.staging
staging: force_staging compile
@:
./.staging:
@echo "staging"
@touch $@
Upvotes: 0