1
- # sources
1
+ # # sources
2
2
# http://www.jfranken.de/homepages/johannes/vortraege/make_inhalt.en.html
3
3
# http://www-cip.physik.uni-bonn.de/pool/infos/make/advanced.html
4
4
5
- # motivation
5
+ # # motivation
6
6
7
7
# takes care of dependencies
8
+
8
9
# only builds if requirements were changed! (looks at timestamps)
9
10
10
- # basics
11
+ # # basics
11
12
12
13
target: dep1 dep2
13
14
23
24
24
25
# $make target #makes target
25
26
26
- # conventional targets
27
+ # #conventional targets
28
+
29
+ # #phony targets
27
30
28
- # phony targets
29
31
# if you don't give phony, make thinks you want to build a file
30
32
# if a file install exists, make does nothing!
31
33
# http://stackoverflow.com/questions/2145590/what-is-the-purpose-of-phony-in-a-makefile
75
77
install:
76
78
@mv out $(DIRINPATH)
77
79
78
- # variables
80
+ # # variables
79
81
80
82
CC=gcc
81
83
CXX=$(CC)
142
144
143
145
# use hyphens '-' or '_' instead
144
146
145
- # include
147
+ # #include
148
+
146
149
# sources a file
147
150
include make.inc
148
151
149
152
# continue even if missing
150
153
-include make.inc
151
154
152
- # implicit rules
155
+ # # implicit rules
153
156
154
157
# An explicit rule assigns the commands for several targets
155
158
coat shoes mobile sweater socks trousers\
163
166
trousers: pants shirt
164
167
shirt: undershirt
165
168
166
- # duplicate rules ::
169
+ # #duplicate rules
170
+
167
171
# must use double colons
168
172
169
173
# socks will build both
170
174
socks:: ; @echo get into left sock
171
175
socks:: ; @echo get into right sock
172
176
173
- # call other makefiles
174
- $(MAKE)
175
-
176
- # builtin function
177
+ # #call other makefiles
177
178
178
- # wildcard. makes an array with wildcard.
179
- SRCS = $(wildcard *$(INEXT))
180
-
181
- # pathsub. makes an array with wildcard.
182
- OUTS = $(patsubst %$(INEXT),%$(OUTEXT),$(SRCS))
183
-
184
- # compile all files of a type
185
- INEXT=.c
186
- OUTEXT=
187
- SRCS = $(wildcard *$(INEXT))
188
- OUTS = $(patsubst %$(INEXT),%$(OUTEXT),$(SRCS))
189
- all: $(OUTS)
190
- %: %$(INEXT)
191
- $(CC) $(CFLAGS) -o $@$(OUTEXT) $<
192
-
193
- # @
179
+ $(MAKE)
194
180
195
- # silent
181
+ # #silent
196
182
197
183
# normally build shows the commands it does
198
- # with @ , it omits the commands
184
+ # with `@` , it omits the commands
199
185
# BUT the stdout/err of the command still shows!
200
186
all:
201
187
@echo asdf
205
191
# "asdf"
206
192
@echo asdf
207
193
208
- # ignore errors -
194
+ # #ignore errors
195
+
209
196
# normally build stops if error
210
- # not if -
197
+ # not if `-`
211
198
all:
212
199
-gcc a.c
213
200
214
- # ignore error and silent
201
+ # #ignore error and silent
202
+
215
203
all:
216
204
@-gcc a.c
217
205
218
- # compile all c files into one target
219
- SRC =$(wildcard * .c)
220
- all : $(SRC )
221
- gcc $(CFLAGS ) -o $@ $^ $(LIBS )
222
-
223
- # command line variables
206
+ # #command line variables
224
207
225
208
# ##
226
209
$make run A='"1"'
@@ -249,7 +232,7 @@ all: $(SRC)
249
232
echo $(A)
250
233
# as df
251
234
252
- # conditionals
235
+ # #conditional
253
236
254
237
A=defined
255
238
all: a.out
@@ -259,7 +242,22 @@ all: $(SRC)
259
242
echo undefined
260
243
endif
261
244
262
- # builtin funcs
245
+ # #builtin functions
246
+
247
+ # wildcard. makes an array with wildcard.
248
+ SRCS = $(wildcard *$(INEXT))
249
+
250
+ # pathsub. makes an array with wildcard.
251
+ OUTS = $(patsubst %$(INEXT),%$(OUTEXT),$(SRCS))
252
+
253
+ # compile all files of a type
254
+ INEXT=.c
255
+ OUTEXT=
256
+ SRCS = $(wildcard *$(INEXT))
257
+ OUTS = $(patsubst %$(INEXT),%$(OUTEXT),$(SRCS))
258
+ all: $(OUTS)
259
+ %: %$(INEXT)
260
+ $(CC) $(CFLAGS) -o $@$(OUTEXT) $<
263
261
264
262
$(subst from,to,text) Replace from with to in text.
265
263
$(patsubst pattern,replacement,text) Replace words matching pattern with replacement in text.
@@ -292,7 +290,7 @@ all: $(SRC)
292
290
293
291
$(eval X := $(AUX_DIR)$* ) define a variable inside a rule
294
292
295
- # submake
293
+ # # submake
296
294
297
295
# call other makefiles
298
296
@@ -308,9 +306,25 @@ all:
308
306
309
307
make
310
308
311
- # recipes
309
+ # #multiline commands
310
+
311
+ # when `\` ends the line
312
+
313
+ # simply make continues reading next line
314
+
315
+ # `\` is passed to bash
316
+
317
+ all :
318
+
319
+ ( \
320
+ cd d ;\
321
+ pwd ;\
322
+ )
323
+
324
+ # #recipes
325
+
326
+ # #make all files of an extension inside given path
312
327
313
- # make all files of an extension inside given path
314
328
CC=pdflatex
315
329
IN_EXT=.tex
316
330
IN_DIR=src/
336
350
rm -rf $(OUT_DIR) $(AUX_DIR)
337
351
# rm *.$(OUT_EXT)
338
352
# compile command
339
-
0 commit comments