A simple makefile consists of “rules” with the following shape:
target … : prerequisites …
recipe
…
…
A phony target is one that is not really the name of a file; rather it is just a name for a recipe to be executed when you make an explicit request.
.PHONY: foo # This recipe will always run when 'make foo' is invoked
foo:
echo "Hello!"
Example:
$ make foo
echo "Hello!"
Hello!
Normally
make
prints each line of the recipe before it is executed. (...) When a line starts with ‘@’, the echoing of that line is suppressed. (...) Typically you would use this for a command whose only effect is to print something
.PHONY: foo
foo:
@echo "Hello!"
Example:
$ make foo
Hello!
Occasionally, however (...) you want to impose a specific ordering on the rules to be invoked without forcing the target to be updated if one of those rules is executed. In that case, you want to define order-only prerequisites. Order-only prerequisites can be specified by placing a pipe symbol (|) in the prerequisites list: any prerequisites to the left of the pipe symbol are normal; any prerequisites to the right are order-only:
targets : normal-prerequisites | order-only-prerequisites
Example:
.PHONY: default
default: | start-mongo
.PHONY: start-mongo
start-mongo:
docker-compose up --build -d
.PHONY: stop-mongo
stop-mongo:
docker-compose down