-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmake.txt
109 lines (90 loc) · 2.68 KB
/
make.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# make
-f Makefile
-B // always rebuild target
-j n // number of jobs to be run in parallel
# variables
$@ // target
$* // match pattern in pattern rule
target-%:
echo $* // target-X prints X
$< // first prerequisite
$+, $^ // all prerequisites
$(@D), $(@F) // directory and filename of $@
$(<D), $(<F) // directory and filename of $<
$(+D), $(+F) // directory and filename of $+
$$HOME // escape/mask shell variable
\: // escape colon
$HOME // environment variables become Make variables
## assignments
x = value
x ?= value // only if not defined
x := value // overwrite
target: x = value // target specific variable
# multiple commands per line
seqmonk: txt
mkdir -p seqmonk && \
for infile in $$(ls txt/*txt); do \
outfile=seqmonk/$$(basename $$infile); \
./txt_to_seqmonk.py $$infile > $$outfile; \
done
# functions
$(patsubst RSC_%,cell_%, RSC_1 RSC_2) // cell_1 cell_2
$(RSC_1 RSC_2:RSC_%=cell_%) // same as before; no space around ':'!
$(subst what,by,string) // substitute substring
$(filter-out %.txt,vars) // filter out by pattern
$(wildcard dir/*.dir) // glob files; ls dir/*.dir
$(dir /dir/file.txt) // /dir
$(notdir /dir/file.txt) // file.txt
$(suffix /dir/file.txt) // .txt
$(basename /dir/file.txt) // /dir/file; -> remove suffix
$(addprefix prefix, list) // a b, .txt -> a.txt b.txt
$(addsuffix suffix, list)
$(shell ls) // shell command
# control structures
## if
$(if var,true,false) // if var not empty
$(if ,true,false) // -> true
## loops
$(foreach var,list,foo $(var) bar) // loop over list
## functions
reverse = $(2) $(1) // reverse 1st and 2nd arg; $(0) is name of function
$(call reverse,word1,word2) // $(call NAME,arg1,arg2)
## example
parse_k = $(shell python -c 'import re; print(re.search("_k(\d+)", "$(1)").group(1))')
k = $(call parse_k,file_k123_w100.h5)
## assert
$(error Message) // stop with error message
$(warning Message) // stop with error message
# pattern rule
%.o: %.c
gcc -o $@ $<
## different directories
$(a_dir)/%.a:
cmd
$(b_dir)/%.b: $(a_dir)/%.a
cmd
## wildcards
%.o: $(dir)/*%*.c
NOTE: $(wildcard $(dir)/*%*.c) does not work! % not in functions!
# suffix rule // deprecated
.c.o:
gcc -o $@ $<
# static pattern rule
list_targets : pattern : pattern_pre
apply command to each target that matches pattern individually
file1.h5 file2.h5 file3.h5: %:
echo $@ // file1.h5; file2.h5; file3.h5
File1.h5 file2.h5 file3.h5: F%:
echo $@ // file2.h5; file3.h5 --> File1.h5 filtered out
objects = foo.o bar.o
$(object): %.o : %.c
gcc -c $@ $^
# order-only prerequisites
* are always executed before all other prerequisites
target: pre | order-only
# print value of variable
print-var:
echo $($*)
# supress echo of command
target:
@command