The basic structure of a Makefile is as follows:
dependency-one:
command1
command2
dependency-two:
command3
end-goal: dependency-one dependency-two
command4
command5
# ...
commandN
When you invoke make end-goal
, the following would happen:
- dependency-one (command1, command2)
- dependency-two (command3)
- end-goal (command4, command5, commandN)
Everything after it is a comment, until the next line break.
These are different ways of setting values to variables.
START_TIME := $(shell date)
CURRENT_TIME = $(shell date)
ENABLED ?= no
Returns the value of the variable VAR
.
VIM_DIR := $(HOME)/.vim
Do not echo the command that follows.
ninja:
@echo ""
NOTE: The @
does not need to be right before the command name; the next example works just fine, as the previous one:
lazy-ninja:
@ echo ""
If, for some reason, you need to check what command would be executed, just invoke the make
with the -n
option, like this:
make -n lazy-ninja
say-my-name-%:
@echo Given the target $@, your name is $*!
$@
to represent the full target name of the current target$*
returns the text that corresponds to % in the target
Defines the shell program to interpret each goal. Defaults to /bin/sh
SHELL = /bin/bash
.DEFAULT_GOAL = my-second-goal
The definitions that follows it should not be interpreted as files.
.PHONY: release-major release-minor release-patch
release-major:
$(XYZ) --increment major
release-minor:
$(XYZ) --increment minor
release-patch:
$(XYZ) --increment patch
Executes a shell command and return its output.
NOW = $(shell date)
define print_title
echo -----------------
echo $(1)
echo -----------------
endef
main-menu:
@$(call print_title,"main menu")
PIP3 := $(shell command -v pip3 2> /dev/null)
ifndef PIP3
define MSG
PIP3 does not seem to be installed.
To install it, follow the instructions found at this website:
https://pip.pypa.io/en/stable/installing/
endef
$(error $(MSG))
endif