Skip to content

Instantly share code, notes, and snippets.

@InsulaVentus
Created August 29, 2019 08:54
Show Gist options
  • Save InsulaVentus/e751d990dd6003c6af9cf39e5cc0d3cb to your computer and use it in GitHub Desktop.
Save InsulaVentus/e751d990dd6003c6af9cf39e5cc0d3cb to your computer and use it in GitHub Desktop.

GNU Makefile manual

A simple makefile consists of “rules” with the following shape:

target … : prerequisites …
        recipe
        …
        …

Phony Targets:

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! 

Recipe Echoing

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! 

Types of Prereuisites

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment