-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
41 lines (32 loc) · 1.54 KB
/
Makefile
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
# It is common to disable the builtin rules. No need for Fortran rules....
# You can either run "make --no-builtin-rules" or add to this variable.
MAKEFLAGS += --no-builtin-rules
# A pattern rule is applied to any target that does not have any explicit rule.
# https://www.gnu.org/software/make/manual/html_node/Pattern-Rules.html
all: hello list_of_strings.txt hello.lines subset
.PHONY: all
# This rule is for demonstration purposes only, usually the rule is: %.o : %c to
# create object files. Given the target xyz, then this rule can be applied
# if there exists an xyz.c
% : %.c
gcc -c $< -o $@
# Here there is no good relation between the target and the sources,
# so its not really possible to write a pattern rule.
list_of_strings.txt: hello.c Makefile
cat $^ | grep -o '".*"' > list_of_strings.txt
# Easy correlation from xyz.lines to xyz.c
%.lines: %.c ; wc -l $< > $@
# You can apply a tailored pattern rule for only a subset of all files.
# The desired subset here is a single file: subset/hello.o, but the subset
# can be any number of files. Usually stored in a variable.
# This is called a static pattern rule: https://www.gnu.org/software/make/manual/html_node/Static-Pattern.html
# Try to use this if you can, since it will be more efficient than having all implicit rules.
# Also there is less risk that you will get confused with pattern rule will be applied by make.
subset/hello.o: subset/%.o : %.c
mkdir -p subset
gcc -c $< -o $@
subset: subset/hello.o
clean:
rm -rf hello list_of_strings.txt hello.lines subset
.PHONY: clean
hello : hello.h