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