Mercurial > projects > dstress
annotate Makefile @ 109:0e5c059a7658
added diagnosis for GNUMake's $(eval ...), $(shell ...) and $(eval ... $(shell ...))
author | thomask |
---|---|
date | Sat, 06 Nov 2004 14:07:01 +0000 |
parents | aa6478748245 |
children | 553c8aaa0982 |
rev | line source |
---|---|
46 | 1 # GnuMakefile for DStress http://dmd.kuehne.cn/dstress.html |
2 # Copyright (C) 2004 Thomas Kuehne | |
3 # | |
4 # This program is free software; you can redistribute it and/or modify | |
5 # it under the terms of the GNU General Public License as published by | |
6 # the Free Software Foundation; either version 2 of the License, or | |
7 # (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
14 # You should have received a copy of the GNU General Public License | |
15 # along with this program; if not, write to the Free Software | |
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 # | |
0 | 18 |
46 | 19 # dir: temp objects will be placed there |
32 | 20 ifndef OBJ_DIR |
0 | 21 OBJ_DIR = obj |
32 | 22 endif |
23 | |
46 | 24 # file: append compiler messages and runtime assertions |
83 | 25 # NOTE: this has to be an absolut path (required for some complex.mak files) |
32 | 26 ifndef LOG |
46 | 27 LOG = $(PWD)/log.txt |
32 | 28 endif |
0 | 29 |
46 | 30 # executeable: the compiler |
0 | 31 ifndef DMD |
32 DMD = dmd | |
33 endif | |
34 | |
46 | 35 # executeable: a GNU findutils compatible find (e.g.: find path -regex "?\\.*something") |
0 | 36 ifndef FIND |
37 FIND = find | |
38 endif | |
39 | |
46 | 40 # executeable: remove zero or more files (e.g.: rm -f a b c) |
0 | 41 ifndef RM |
46 | 42 RM = rm -f |
0 | 43 endif |
44 | |
46 | 45 # executeable: change to a given dir (e.g. cd some/other/dir) |
46 ifndef CD | |
47 CD = cd | |
48 endif | |
49 | |
50 # executeable: display a message test (e.g. echo "something to say) | |
0 | 51 ifndef ECHO |
52 ECHO = echo | |
53 endif | |
54 | |
46 | 55 # executeable: update the timestamp of an existing file or create a new empty file |
0 | 56 ifndef TOUCH |
57 TOUCH = touch | |
58 endif | |
59 | |
46 | 60 ############################################################################### |
61 ############################################################################### | |
62 # | |
63 # nothing to customize below | |
64 # | |
65 ############################################################################### | |
66 ############################################################################### | |
6 | 67 |
83 | 68 # tools |
69 return__ = ./return__ | |
70 ifeq__ = ./ifeq__ | |
71 extract__ = ./extract__ | |
72 | |
72 | 73 # settings |
0 | 74 to_log = >> $(LOG) 2>&1 |
75 ext_run = exe | |
76 ext_norun = bin | |
77 ext_nocompile = no | |
78 ext_compile = o | |
79 ext_source = d | |
6 | 80 ext_source_html = html |
46 | 81 complex_todo = complex.mak |
82 complex_done = complex.done | |
85
659bb018c489
1) changed "?DSTRESS_FLAGS?" to "__DSTRESS_DFLAGS__" in order to cope with botched shells
thomask
parents:
83
diff
changeset
|
83 flag_pattern = __DSTRESS_DFLAGS__ |
0 | 84 |
72 | 85 |
86 .PHONY: all basic_tools compile nocompile run norun complex clean distclean clean_log log | |
46 | 87 # |
88 # test everything | |
89 # | |
90 all : Makefile compile nocompile run norun complex | |
6 | 91 |
46 | 92 # |
72 | 93 # the tools |
94 # | |
83 | 95 $(return__) : return__.c Makefile |
96 $(CC) $(CFLAGS) $< -o $@ | |
97 | |
98 $(ifeq__) : ifeq__.c Makefile | |
72 | 99 $(CC) $(CFLAGS) $< -o $@ |
100 | |
83 | 101 $(extract__) : extract__.c Makefile |
72 | 102 $(CC) $(CFLAGS) $< -o $@ |
103 | |
83 | 104 basic_tools : $(ifeq__) $(return__) $(extract__) |
72 | 105 |
83 | 106 |
72 | 107 # |
46 | 108 # include complex test cases |
109 # | |
110 complex_makefiles = $(sort $(shell $(FIND) complex -regex ".*$(complex_todo)")) | |
111 include $(complex_makefiles) | |
6 | 112 |
83 | 113 # |
114 # extract potential compiling flags from the test case sources | |
115 # | |
116 define extract_z_flags | |
117 $(eval z_flags = $(shell $(extract__) $(flag_pattern) < $<)) | |
118 endef | |
119 | |
46 | 120 # |
121 # target should fail to compile | |
122 # | |
41
84e813a3e99b
fixed Makefile so that an edited makefile triggers a rebuild of outdated targets
thomask
parents:
32
diff
changeset
|
123 nocompile : Makefile $(sort $(subst .$(ext_source),.$(ext_nocompile),$(shell $(FIND) nocompile -regex ".*\\.$(ext_source)" ) ) $(subst .$(ext_source_html),.$(ext_nocompile),$(shell $(FIND) nocompile -regex ".*\\.$(ext_source_html)" ) ) ) |
17 | 124 |
75 | 125 define analyse_nocompile |
72 | 126 @if $(ifeq__) $(z_return) 0 ; then \ |
46 | 127 $(ECHO) "XPASS: $(z_name)"; $(RM) $@; \ |
128 else \ | |
72 | 129 if $(ifeq__) $(z_return) 256 ; then \ |
130 $(ECHO) "XFAIL: $(z_name)"; $(TOUCH) $@; \ | |
131 else \ | |
75 | 132 $(ECHO) "ERROR: $(z_name) [$(z_return)]"; $(RM) $@; \ |
72 | 133 fi \ |
46 | 134 fi |
75 | 135 endef |
136 | |
137 %.$(ext_nocompile) : %.$(ext_source) basic_tools | |
138 $(eval z_name = $(subst .$(ext_nocompile),,$@)) | |
83 | 139 $(extract_z_flags) |
92 | 140 $(eval z_return = $(shell $(return__) "$(DMD) $(DFLAGS) $(z_flags) -c -od$(OBJ_DIR) $< $(to_log)")) |
75 | 141 $(analyse_nocompile) |
142 | |
143 %.$(ext_nocompile) : %.$(ext_source_html) basic_tools | |
144 $(eval z_name = $(subst .$(ext_nocompile),,$@)) | |
83 | 145 $(extract_z_flags) |
92 | 146 $(eval z_return = $(shell $(return__) "$(DMD) $(DFLAGS) $(z_flags) -c -od$(OBJ_DIR) $< $(to_log)")) |
75 | 147 $(analyse_nocompile) |
32 | 148 |
46 | 149 # |
150 # target should compile (excludes linking) | |
151 # | |
41
84e813a3e99b
fixed Makefile so that an edited makefile triggers a rebuild of outdated targets
thomask
parents:
32
diff
changeset
|
152 compile : Makefile $(sort $(subst .$(ext_source),.$(ext_compile),$(shell $(FIND) compile -regex ".*\\.$(ext_source)" ) ) $(subst .$(ext_source_html),.$(ext_compile),$(shell $(FIND) compile -regex ".*\\.$(ext_source_html)" ) ) ) |
0 | 153 |
75 | 154 define analyse_compile |
72 | 155 @if $(ifeq__) $(z_return) 0 ; then \ |
156 $(ECHO) "PASS: $(z_name)"; \ | |
46 | 157 else \ |
72 | 158 if $(ifeq__) $(z_return) 256 ; then \ |
159 $(ECHO) "FAIL: $(z_name)"; $(RM) $@; \ | |
160 else \ | |
75 | 161 $(ECHO) "ERROR: $(z_name) [$(z_return)]"; $(RM) $@; \ |
72 | 162 fi \ |
46 | 163 fi |
75 | 164 endef |
165 | |
166 %.$(ext_compile) : %.$(ext_source) basic_tools | |
167 $(eval z_name = $(subst .$(ext_compile),,$@)) | |
83 | 168 $(extract_z_flags) |
169 $(eval z_return = $(shell $(return__) "$(DMD) $(DFLAGS) $(z_flags) -c -of$@ $< $(to_log)")) | |
75 | 170 $(analyse_compile) |
171 | |
0 | 172 |
72 | 173 %.$(ext_compile) : %.$(ext_source_html) basic_tools |
46 | 174 $(eval z_name = $(subst .$(ext_compile),,$@)) |
83 | 175 $(extract_z_flags) |
176 $(eval z_return = $(shell $(return__) "$(DMD) $(DFLAGS) $(z_flags) -c -of$@ $< $(to_log)")) | |
75 | 177 $(analyse_compile) |
6 | 178 |
46 | 179 # |
180 # target should compile, link and run | |
181 # | |
41
84e813a3e99b
fixed Makefile so that an edited makefile triggers a rebuild of outdated targets
thomask
parents:
32
diff
changeset
|
182 run : Makefile $(sort $(subst .$(ext_source),.$(ext_run),$(shell $(FIND) run -regex ".*\\.$(ext_source)" ) ) $(subst .$(ext_source_html),.$(ext_run),$(shell $(FIND) run -regex ".*\\.$(ext_source_html)" ) ) ) |
0 | 183 |
75 | 184 define analyse_run |
72 | 185 @if $(ifeq__) $(z_return) 0 ; then \ |
80 | 186 $(eval z_return2 = $(shell $(return__) "./$@ $(to_log)")) \ |
187 if $(ifeq__) $(z_return2) 0 ; then \ | |
46 | 188 $(ECHO) "PASS: $(z_name)"; \ |
189 else \ | |
80 | 190 if $(ifeq__) $(z_return2) 256 ; then \ |
191 $(ECHO) "FAIL: $(z_name)"; $(RM) $@; \ | |
192 else \ | |
193 $(ECHO) "ERROR: $(z_name) [run: $(z_return2)]"; $(RM) $@; \ | |
194 fi \ | |
46 | 195 fi \ |
196 else \ | |
72 | 197 if $(ifeq__) $(z_return) 256 ; then \ |
198 $(ECHO) "FAIL: $(z_name) (compiling error)"; \ | |
199 else \ | |
75 | 200 $(ECHO) "ERROR: $(z_name) [$(z_return)]"; \ |
72 | 201 fi \ |
46 | 202 fi |
75 | 203 endef |
46 | 204 |
75 | 205 %.$(ext_run) : %.$(ext_source) basic_tools |
72 | 206 $(eval z_name = $(subst .$(ext_run),,$@)) |
83 | 207 $(extract_z_flags) |
208 $(eval z_return = $(shell $(return__) "$(DMD) $(DFLAGS) $(z_flags) -od$(OBJ_DIR) -of$@ $< $(to_log)")) | |
75 | 209 $(analyse_run) |
0 | 210 |
72 | 211 %.$(ext_run) : %.$(ext_source_html) basic_tools |
63 | 212 $(eval z_name = $(subst .$(ext_run),,$@)) |
83 | 213 $(extract_z_flags) |
214 $(eval z_return = $(shell $(return__) "$(DMD) $(DFLAGS) $(z_flags) -od$(OBJ_DIR) -of$@ $< $(to_log)")) | |
75 | 215 $(analyse_run) |
6 | 216 |
46 | 217 # |
108 | 218 # target should compile, link and run |
219 # (used for Makefile diagnosis) | |
220 # | |
221 %.diagnose.$(ext_run) : %.$(ext_source) basic_tools | |
222 # destination: $@ | |
223 # source: $< | |
109
0e5c059a7658
added diagnosis for GNUMake's $(eval ...), $(shell ...) and $(eval ... $(shell ...))
thomask
parents:
108
diff
changeset
|
224 $(eval y_tmp = OK) |
0e5c059a7658
added diagnosis for GNUMake's $(eval ...), $(shell ...) and $(eval ... $(shell ...))
thomask
parents:
108
diff
changeset
|
225 # eval: $(y_tmp) |
0e5c059a7658
added diagnosis for GNUMake's $(eval ...), $(shell ...) and $(eval ... $(shell ...))
thomask
parents:
108
diff
changeset
|
226 # shell: |
0e5c059a7658
added diagnosis for GNUMake's $(eval ...), $(shell ...) and $(eval ... $(shell ...))
thomask
parents:
108
diff
changeset
|
227 @$(ECHO) $(shell $(ECHO) "OK") |
0e5c059a7658
added diagnosis for GNUMake's $(eval ...), $(shell ...) and $(eval ... $(shell ...))
thomask
parents:
108
diff
changeset
|
228 $(eval y_tmp = $(shell $(ECHO) "OK")) |
0e5c059a7658
added diagnosis for GNUMake's $(eval ...), $(shell ...) and $(eval ... $(shell ...))
thomask
parents:
108
diff
changeset
|
229 # eval.shell: $(y_tmp) |
108 | 230 $(eval z_name = $(subst .diagnose.$(ext_run),,$@)) |
231 # name: $(z_name) | |
232 # extract__: $(extract__) | |
233 # extract__.cmd: $(extract__) $(flag_pattern) < $< | |
234 $(extract_z_flags) | |
235 # extract__.result: $(z_flags) | |
236 # ifeq__: $(ifeq__) | |
237 # continue if ifeq__ works | |
238 $(ifeq__) someString someString | |
239 # return__: $(return__) | |
240 # dmd: $(DMD) | |
241 $(eval y_tmp = $(shell $(return__) "$(ifeq__) 1 1")) | |
242 # return__.return_code_0: $(y_tmp) (expect=0) | |
243 $(eval y_tmp = $(shell $(return__) "$(DMD) > /dev/null")) | |
244 # return__.return_code_1: $(y_tmp) (expect=256) | |
245 # dmd.cmd: $(DMD) $(DFLAGS) $(z_flags) -od$(OBJ_DIR) -of$@ $< $(to_log) | |
246 $(eval z_return = $(shell $(return__) "$(DMD) $(DFLAGS) $(z_flags) -od$(OBJ_DIR) -of$@ $< $(to_log)")) | |
247 # dmd.return: $(z_return) | |
248 # for analyse_run diagnosis: '@if' -> 'if' in 'define analyse_run' (line 185) | |
249 $(analyse_run) | |
250 | |
251 # | |
46 | 252 # target should compile and link but fail to run |
253 # | |
41
84e813a3e99b
fixed Makefile so that an edited makefile triggers a rebuild of outdated targets
thomask
parents:
32
diff
changeset
|
254 norun : Makefile $(sort $(subst .$(ext_source),.$(ext_norun),$(shell $(FIND) norun -regex ".*\\.$(ext_source)" ) ) $(subst .$(ext_source_html),.$(ext_norun),$(shell $(FIND) norun -regex ".*\\.$(ext_source_html)" ) ) ) |
0 | 255 |
75 | 256 define analyse_norun |
72 | 257 @if $(ifeq__) $(z_return) 0; then \ |
258 if ./$@ $(to_log); \ | |
58 | 259 then $(ECHO) "XPASS: $(z_name)"; $(RM) $@; \ |
46 | 260 else \ |
72 | 261 $(ECHO) "XFAIL: $(z_name)"; \ |
46 | 262 fi \ |
263 else \ | |
72 | 264 if $(ifeq__) $(z_return) 256 ; then \ |
265 $(ECHO) "FAIL: $(z_name) (compiling error)"; $(RM) $@; \ | |
266 else \ | |
75 | 267 $(ECHO) "ERROR: $(z_name) [$(z_return)]"; \ |
72 | 268 fi \ |
46 | 269 fi |
75 | 270 endef |
271 | |
272 %.$(ext_norun) : %.$(ext_source) basic_tools | |
273 $(eval z_name = $(subst .$(ext_norun),,$@)) | |
83 | 274 $(extract_z_flags) |
275 $(eval z_return = $(shell $(return__) "$(DMD) $(DFLAGS) $(z_flags) -od$(OBJ_DIR) -of$@ $< $(to_log)")) | |
75 | 276 $(analyse_norun) |
0 | 277 |
72 | 278 %.$(ext_norun) : %.$(ext_source_html) Makefile |
46 | 279 $(eval z_name = $(subst .$(ext_norun),,$@)) |
83 | 280 $(extract_z_flags) |
281 $(eval z_return = $(shell $(return__) "$(DMD) $(DFLAGS) $(z_flags) -od$(OBJ_DIR) -of$@ $< $(to_log)")) | |
75 | 282 $(analyse_norun) |
283 | |
46 | 284 |
285 # | |
286 # run all complex test cases | |
287 # | |
288 complex : $(sort $(subst $(complex_todo),$(complex_done),$(complex_makefiles))) | |
6 | 289 |
32 | 290 |
17 | 291 log : distclean all |
32 | 292 |
46 | 293 # |
294 # | |
295 # | |
17 | 296 distclean : clean_log clean |
83 | 297 $(RM) $(shell $(FIND) . -regex ".*~") $(shell $(FIND) . -regex "\\..*\\.swp") |
298 $(RM) return__ ifeq__ extract__ www/*.class | |
6 | 299 |
46 | 300 # |
301 # remove compiler and assertion messages | |
302 # | |
0 | 303 clean_log : |
304 $(RM) $(LOG) | |
305 | |
46 | 306 # |
307 # remove targets and all temp objects | |
308 # | |
309 clean : $(sort $(subst $(complex_todo),clean,$(complex_makefiles))) | |
310 $(RM) $(OBJ_DIR)/?*.?* | |
311 $(RM) run/?*.$(ext_run) norun/?*.$(ext_norun) compile/?*.$(ext_compile) nocompile/?*.$(ext_nocompile) | |
83 | 312 |
313 # the empty line above has to remain, otherwise some weired problems can arise |