The official cite is at: Manual
or use man make. The following are some templates for pasting.
Generate a sequence.
It’s useful in generate big datasets by many small files, e.g.,
| 1 | E:=$(shell seq -f "%03g" 1 1 100) | 
In shell, it can be replaced by: 
| 1 | E:=$(shell echo {1..5}) | 
The multiple iteration are also supported,
| 1 | E:=$(shell echo {1..5}_{1..5}) | 
A quickly way to avoid for each can be done by
| 1 | x:=$(shell echo {1..5}_{1..5}_{1..5}) | 
Get the input and output
We usually need to list filenames in a directory, they are always the input of the program, e.g., list all files with suffix .h5 
| 1 | srl:=$(wildcard ./input/*.h5) | 
The output often has the similar name with only string changed, e.g.,
| 1 | dst:=$(srl:./input/%.h5=./output/%.h5) | 
Target
the makefile need a target to execute, we focus on the target need iteration. For small iteration, you can
| 1 | E1:=$(shell echo {1..5}) | 
It is not recommended in large numbers, foreach is much faster.
| 1 | target := $(foreach x, $(E1), $\ | 
For complex situations, we use function to iterate, here is an template.
| 1 | xs:=$(shell seq -f "%03g" 0 1 9) | 
you also need a target:
| 1 | all:$(foreach x,$(xs),$(foreach y,$(ys),recon/$(x)_$(y).h5)) | 
Notice that
- DO NOT add blanks in the variable.
- In template most $need to be doubled, despite the local and global variables.
Bash style also works, but not recommanded.
| 1 | all: | 
Here is a more complex case, we need iterate multiple times (epoch), the results in each step should be recorded, we can use the following template:
| 1 | define tpl_iter | 
Automatic variables
| variable | mean | 
|---|---|
| $@ | target | 
| $% | target member name | 
| $< | first prerequisite | 
| $? | all prerequisites | 
| $* | match % | 
If we wart to specify the dependent file, use word,
| 1 | $(word 2, $<) | 
If we need a calculator, use bc:
| 1 | target:$(shell echo '$(x)+2000' | bc -l).h5 | 
Some frequent bugs:
- remember to create the path  1 
 2
 3mkdir -p $(dir $@) 
 # or
 mkdir -p $(dirname $@)
- tabis not equal to- space, be careful to the editor.