root/Makefile

Revision 1628:c6ef09dfba4d, 9.4 kB (checked in by Moritz Warning <moritzwarning@web.de>, 1 year ago)

add mini test set from ldc project

Line 
1 # $HeadURL$
2 # $Date$
3 # $Author$
4 #
5 # GnuMakefile for DStress http://dstress.kuehne.cn/www/dstress.html
6 # Copyright (C) 2004, 2005, 2006 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 #                                             
22
23 # dir: temp objects will be placed there
24 ifndef OBJ_DIR
25 OBJ_DIR := obj
26 endif
27
28 # file: append compiler messages and runtime assertions
29 # NOTE: this has to be an absolut path (required for some complex.mak files)
30 ifndef LOG
31 LOG := $(PWD)/log.txt
32 endif
33
34 # executeable: the compiler
35 ifndef DMD
36 DMD := dmd
37 endif
38
39 # executeable: a GNU findutils compatible find (e.g.: find path -regex "?\\.*something")
40 ifndef FIND
41 FIND    := find
42 endif 
43
44 # executeable: remove zero or more files (e.g.: rm -f a b c)
45 ifndef RM
46 RM  := rm -f --
47 endif
48
49 # executeable: change to a given dir (e.g. cd some/other/dir)
50 ifndef CD
51 CD  := cd
52 endif
53
54 # executeable: display a message test (e.g. echo "something to say")
55 ifndef ECHO
56 ECHO    := echo
57 endif
58
59 # executeable: update the timestamp of an existing file or create a new empty file
60 ifndef TOUCH
61 TOUCH   := touch
62 endif
63
64 # executeable: detect if stdin contains "Internal error" (dmd) or "gcc.gnu.org/bugs" (gcd)
65 ifndef GREP
66 GREP := grep -s '\(Internal error\)\|\(gcc.gnu.org/bugs\)' > /dev/null 2>&1
67 endif
68
69 # executeable: used to concat files
70 ifndef CAT
71 CAT := cat
72 endif
73
74 ###############################################################################
75 ###############################################################################
76 #
77 # nothing to customize below
78 #
79 ###############################################################################
80 ###############################################################################
81
82 # tools
83 return__    := $(PWD)/return__
84 ifeq__      := ./ifeq__
85 extract__   := ./extract__
86 dstress__   := ./dstress
87 crashRun__  := ./crashRun
88
89 # settings
90 to_log      := >> $(LOG) 2>&1
91 ext_run     := exe
92 ext_norun   := bin
93 ext_nocompile   := no
94 ext_compile     := o
95 ext_source  := d
96 ext_source_html := html
97 ext_log     := log
98 complex_todo    := complex.mak
99 complex_done    := complex.done
100 flag_pattern    := __DSTRESS_DFLAGS__
101
102 .PHONY:: all version basic_tools compile nocompile run norun complex clean distclean clean_log
103
104 .SUFFIXES:: $(ext_run) $(ext_norun) $(ext_nocompile) $(ext_compile)
105 #
106 # test everything
107 #
108 all : Makefile version compile nocompile run norun complex
109
110 #
111 # the tools
112 #
113 % : %.c Makefile
114     $(CC) $(CFLAGS) $< -o $@
115
116 $(dstress__) : dstress.c $(crashRun__) Makefile
117     $(CC) $(CFLAGS) $< -o $@
118
119 basic_tools : $(ifeq__) $(return__) $(extract__) $(dstress__)
120
121 #
122 # kludge to get version information from DMD and GDC's dmd wraper
123 #
124 version:
125     @$(ECHO) ">>>> VERSION <<<<"
126     @date +"%a, %e %b %Y %T %z"
127     @uname -s -m -r
128     -@$(DMD)
129     -@$(DMD) --version version_dummy.d 
130     @$(ECHO) "<<<< VERSION >>>>"
131
132 #
133 # include complex test cases
134 #
135 complex_makefiles := $(sort $(shell $(FIND) complex -regex ".*$(complex_todo)"))
136 include $(complex_makefiles)
137
138 #
139 # extract potential compiling flags from the test case sources
140 #
141 define extract_z_flags
142     $(eval z_flags = $(shell $(extract__) $(flag_pattern) < $<))
143 endef
144
145 #
146 # target should fail to compile
147 #
148 nocompile : $(dstress__) nocompile_clean
149     echo '#!/bin/sh' > nocompile.sh
150     find nocompile -type f | grep -v ".svn" | sort -f | xargs -n 1 echo "$(dstress__) nocompile" >> nocompile.sh
151     chmod +x nocompile.sh
152     ./nocompile.sh 2>> $(LOG)
153
154 nocompile_clean :
155     $(eval z_rm = $(shell find nocompile -type f  -name "*\\.o" | grep -v ".svn"))
156     $(RM) $(z_rm)
157
158 # used in some complex test cases
159 define analyse_nocompile
160     @if $(ifeq__) $(z_return) 0 ; then \
161         $(ECHO) "Torture-Sub-1/31-XPASS: $(z_name)"; $(RM) $@; \
162     else \
163         if $(CAT) $(z_log) | $(GREP) ; then \
164             $(ECHO) "Torture-Sub-1/31-ERROR: $(z_name) [Internal compiler error]"; $(RM) $@; \
165         else \
166             if $(ifeq__) $(z_return) 256 ; then \
167                 $(ECHO) "Torture-Sub-1/31-XFAIL: $(z_name)"; $(TOUCH) $@; \
168             else \
169                 $(ECHO) "Torture-Sub-1/31-ERROR: $(z_name) [$(z_return)]"; $(RM) $@; \
170             fi \
171         fi \
172     fi
173 endef
174
175 #
176 # target should compile (excludes linking)
177 #
178 compile : $(dstress__) compile_clean
179     echo '#!/bin/sh' > compile.sh
180     find compile -type f | grep -v ".svn" | sort -f | xargs -n 1 echo "$(dstress__) compile" >> compile.sh
181     chmod +x compile.sh
182     ./compile.sh 2>> $(LOG)
183
184 compile_clean :
185     $(eval z_rm = $(shell find compile -type f  -name "*\\.o" | grep -v ".svn"))
186     $(RM) $(z_rm)
187     $(eval z_rm = $(shell find compile -type f  -name "*\\.exe" | grep -v ".svn"))
188     $(RM) $(z_rm)
189
190 # used in some complex test cases
191 define analyse_compile
192     @if $(ifeq__) $(z_return) 0 ; then \
193         $(ECHO) "Torture-Sub-1/31-PASS:  $(z_name)"; $(TOUCH) $@; \
194     else \
195         if $(ifeq__) $(z_return) 256 ; then \
196             $(ECHO) "Torture-Sub-1/31-FAIL:  $(z_name)"; $(RM) $@; \
197         else \
198             $(ECHO) "Torture-Sub-1/31-ERROR: $(z_name) [$(z_return)]"; $(RM) $@; \
199         fi \
200     fi
201 endef
202
203 #
204 # target should compile, link and run
205 #
206 run : $(dstress__) run_clean
207     echo '#!/bin/sh' > run.sh
208     find run -type f -name "*\\.d" | grep -v ".svn" | sort -f | xargs -n 1 echo "$(dstress__) run" >> run.sh
209     chmod +x run.sh
210     ./run.sh 2>> $(LOG)
211
212 run_clean :
213     $(eval z_rm = $(shell find run -type f  -name "*\\.exe" | grep -v ".svn"))
214     $(RM) $(z_rm)
215
216 # used in some complex testcases
217 define analyse_run
218     @if $(ifeq__) $(z_return) 0 ; then \
219         $(eval z_return2 = $(shell $(return__) "./$@ $(to_log)")) \
220         if $(ifeq__) $(z_return2) 0 ; then \
221             $(ECHO) "Torture-Sub-1/31-PASS:  $(z_name)"; \
222         else \
223             if $(ifeq__) $(z_return2) 256 ; then \
224                 $(ECHO) "Torture-Sub-1/31-FAIL:  $(z_name)"; $(RM) $@; \
225             else \
226                 $(ECHO) "Torture-Sub-1/31-ERROR: $(z_name) [run: $(z_return2)]"; $(RM) $@; \
227             fi \
228         fi \
229     else \
230         if $(ifeq__) $(z_return) 256 ; then \
231             $(ECHO) "Torture-Sub-1/31-FAIL:  $(z_name) (compiling error)"; \
232         else \
233             $(ECHO) "Torture-Sub-1/31-ERROR: $(z_name) [$(z_return)]"; \
234         fi \
235     fi
236 endef
237
238 #
239 # target should compile, link and run
240 # (used for Makefile diagnosis)
241 #
242 %.diagnose.$(ext_run) : %.$(ext_source) basic_tools
243     # destination: $@
244     # source: $<
245     $(eval y_tmp = OK)
246     # eval: $(y_tmp)
247     # shell:
248     @$(ECHO) $(shell $(ECHO) "OK")
249     $(eval y_tmp = $(shell $(ECHO) "OK"))
250     # eval.shell: $(y_tmp)
251     $(eval z_name = $(subst .diagnose.$(ext_run),,$@))
252     # name: $(z_name)
253     # extract__: $(extract__)
254     # extract__.cmd: $(extract__) $(flag_pattern) < $<
255     $(extract_z_flags)
256     # extract__.result: $(z_flags)
257     # ifeq__: $(ifeq__)
258     # continue if ifeq__ works
259     $(ifeq__) someString someString
260     # return__: $(return__)
261     # dmd: $(DMD)
262     $(eval y_tmp = $(shell $(return__) "$(ifeq__) 1 1"))
263     # return__.return_code_0: $(y_tmp) (expect=0)
264     $(eval y_tmp = $(shell $(return__) "$(DMD) > /dev/null"))
265     # return__.return_code_1: $(y_tmp) (expect=256)
266     # dmd.cmd: $(DMD) $(DFLAGS) $(z_flags) -od$(OBJ_DIR) -of$@ $< $(to_log)
267     $(eval z_return = $(shell $(return__) "$(DMD) $(DFLAGS) $(z_flags) -od$(OBJ_DIR) -of$@ $< $(to_log)"))
268     # dmd.return: $(z_return)
269     # for analyse_run diagnosis: '@if' -> 'if' in 'define analyse_run' (line 185)
270     $(analyse_run)
271    
272 #
273 # target should compile and link but fail to run
274 #
275 norun : $(dstress__) norun_clean
276     echo '#!/bin/sh' > norun.sh
277     find norun -type f -name "*\\.d" | grep -v ".svn" | sort -f | xargs -n 1 echo "$(dstress__) norun" >> norun.sh
278     chmod +x norun.sh
279     ./norun.sh 2>> $(LOG)
280
281 norun_clean :
282     $(eval z_rm = $(shell find norun -type f  -name "*\\.exe" | grep -v ".svn"))
283     $(RM) $(z_rm)
284
285 # used in some complex test cases
286 define analyse_norun
287     @if $(ifeq__) $(z_return) 0; then \
288         if ./$@ $(to_log); \
289             then $(ECHO) "Torture-Sub-1/31-XPASS: $(z_name)"; $(RM) $@; \
290         else \
291             $(ECHO) "Torture-Sub-1/31-XFAIL: $(z_name)"; \
292         fi \
293     else \
294         if $(ifeq__) $(z_return) 256 ; then \
295             $(ECHO) "Torture-Sub-1/31-FAIL:  $(z_name) (compiling error)"; $(RM) $@; \
296         else \
297             $(ECHO) "Torture-Sub-1/31-ERROR: $(z_name) [$(z_return)]"; \
298         fi \
299     fi
300 endef
301
302 #
303 # run all complex test cases
304 #
305 complex : basic_tools $(sort $(subst $(complex_todo),$(complex_done),$(complex_makefiles)))
306
307 #
308 #
309 #
310 distclean : clean_log clean
311     $(RM) $(shell $(FIND) . -regex ".*~")
312     $(RM) $(shell $(FIND) . -regex "\\..*\\.swp")
313     $(RM) $(shell $(FIND) . -regex "#.*#")
314     $(RM) $(shell $(FIND) . -regex ".*\\.map")
315     $(RM) $(shell $(FIND) . -regex ".*\\.bak")
316     $(RM) $(crashRun__) $(return__) $(ifeq__) $(extract__) $(dstress__) www/*.class
317
318 #
319 # remove compiler and assertion messages
320 #
321 clean_log :
322     $(RM) $(LOG)
323
324 #
325 # remove targets and all temp objects
326 #
327 complex_clean : $(sort $(subst $(complex_todo),clean,$(complex_makefiles)))
328    
329 clean :: complex_clean nocompile_clean compile_clean norun_clean run_clean
330     $(RM) $(OBJ_DIR)/[A-E]*.*
331     $(RM) $(OBJ_DIR)/[F-J]*.*
332     $(RM) $(OBJ_DIR)/[K-O]*.*
333     $(RM) $(OBJ_DIR)/[P-T]*.*
334     $(RM) $(OBJ_DIR)/[U-Z]*.*
335     $(RM) $(OBJ_DIR)/[a-e]*.*
336     $(RM) $(OBJ_DIR)/[f-j]*.*
337     $(RM) $(OBJ_DIR)/[k-o]*.*
338     $(RM) $(OBJ_DIR)/[p-t]*.*
339     $(RM) $(OBJ_DIR)/[u-z]*.*
340     $(RM) -rf $(OBJ_DIR)/*
341     $(RM) run.sh norun.sh compile.sh nocompile.sh
342
343 # the empty line above has to remain, otherwise some weired problems can arise
Note: See TracBrowser for help on using the browser.