-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.mk
executable file
·218 lines (167 loc) · 3.44 KB
/
test.mk
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#
# Build & Test makefile for AM
#
# $ make -ftest.mk build
# $ touch am.c
# $ ./am test.mk
# $ ./am test.mk distclean
#
CC = cc
CFLAGS =
PROG = am
#
# Allow for empty macros.
#
EMPTY=
#
# Allow for white space in macro assignment.
#
TEXT_1=no white space
TEXT_2 =left hand side
TEXT_3= right hand side
TEXT_4 = both sides
TEXT_5 = tabs boths sides
#
# Test psuedo targets.
#
# This must be the first test target. See clean: build: and $(PROG): below.
#
all : build print_macros repeat redefine many flags multiple split errors done
print_macros : empty t1 t2 t3 t4 t5 t.all
#
# Targets with no dependencies.
#
empty :
echo EMPTY='$(EMPTY)'
t1 :
echo TEXT_1='$(TEXT_1)'
t2 :
echo TEXT_2='$(TEXT_2)'
t3 :
echo TEXT_3='$(TEXT_3)'
t4 :
echo TEXT_4='$(TEXT_4)'
t5 :
echo TEXT_5='$(TEXT_5)'
t.all :
echo $(TEXT_1) $(TEXT_2) $(TEXT_3) $(TEXT_4) $(TEXT_5)
#
# Test redefinition of macros. AM allows redefinition and
# evaluates macros immediately.
#
TEXT_1 =text number 1
TEXT_2 = test macro split \
across lines \
three lines
TEXT_3 = test dollar macro '$$'
TEXT_4 = test dollar again "$$(TEXT_1)"
TEXT_5 = imbeded macro '$(TEXT_1)'
redefine : r1 r2 r3 r4 r5
r1 :
echo TEXT_1='$(TEXT_1)'
r2 :
echo TEXT_2='$(TEXT_2)'
r3 :
echo TEXT_3='$(TEXT_3)'
r4 :
echo TEXT_4='$(TEXT_4)'
r5 :
echo TEXT_5='$(TEXT_5)'
#
# Try to update a prerequisite more than once. Subsequent occurences
# should be ignored once a prerequisite has been updated.
#
repeat: t1 repeat.a t3
repeat.a : t2 t1
#
# Target with multi-line recipe.
#
many : leaf.1 leaf.2
echo Execute recipe with multiple commands.
ls -1 leaf.*
echo Last line of recipe for target 'many'.
leaf.1 :
touch leaf.1
leaf.2 :
touch leaf.2
#
# Test recipe line flags.
#
flags : silence ignore always combination
# Command not displayed before execution.
silence :
echo You should not see the 'ls' command printed.
@ls leaf.*
# Ignore errors from command.
ignore :
echo The 'ls' command should fail but not terminate AM.
-ls unknown
# This flag is ignored by AM since we don't support a silence option (-n).
always :
+echo The '+' flag is accepted and ignored.
combination:
-@echo The next displayed line should not be 'ls unknown'
@-ls unknown
@+-echo Combined flags test completed.
#
# Multiple targets.
#
multiple : node.2 node.5
node.1 node.2 node.3 : leaf.1 leaf.2
touch node.1 node.2 node.3
node.4 node.5 : node.2 leaf.3
touch node.4 node.5
leaf.3 :
touch leaf.3
#
# Test split lines.
#
split : node.6 leaf.4 split.cmd
echo Completed split line tests.
# Target dependencies split across lines.
node.6 : leaf.1 \
leaf.2 \
leaf.3
echo Test dependency list split across lines.
touch node.6
# Target list split across lines.
split.tar \
leaf.4 \
leaf.5 :
echo Test target list split across lines
touch leaf.4 leaf.5
# Command lines split across lines.
split.cmd:
echo Try spliting command \
lines across more \
than one line.
#
# Test AM error reports and exit statuses.
#
errors:
-./$(PROG) test.mk error.1
-./$(PROG) test.mk error.2
-./$(PROG) test.mk error.3
# Target that does not exist, has no dependencies, and no commands.
error.1:
# Target where dependency does not exist.
error.2: unknown
# Recipe command causes error.
error.3: t1 fail t2
fail:
ls -l unknown
#
#
#
done: clean
echo AM Test Complete
#
# AM can build itself.
#
build: $(PROG)
$(PROG): am.c
$(CC) $(CFLAGS) -o $(PROG) am.c
clean:
-rm leaf.* node.*
distclean: clean
-rm ./$(PROG)