tests: Minor adjustments selecting which tests are run on each platform.
[tinycc.git] / Makefile
blobcdaad28b5e12e04df4453b19aa0e9abc89c017f9
2 # Tiny C Compiler Makefile
5 TOP ?= .
6 include $(TOP)/config.mak
8 CFLAGS_P=$(CFLAGS) -pg -static -DCONFIG_TCC_STATIC
9 LIBS_P=
11 ifneq ($(GCC_MAJOR),2)
12 CFLAGS+=-fno-strict-aliasing
13 ifneq ($(GCC_MAJOR),3)
14 CFLAGS+=-Wno-pointer-sign -Wno-sign-compare -D_FORTIFY_SOURCE=0
15 endif
16 endif
18 ifneq ($(TARGETOS),Darwin)
19 ifeq ($(ARCH),i386)
20 CFLAGS+=-mpreferred-stack-boundary=2
21 ifeq ($(GCC_MAJOR),2)
22 CFLAGS+=-m386 -malign-functions=0
23 else
24 CFLAGS+=-march=i386 -falign-functions=0
25 endif
26 endif
27 endif
29 ifdef CONFIG_WIN64
30 CONFIG_WIN32=yes
31 endif
33 ifndef CONFIG_WIN32
34 LIBS=-lm
35 ifndef CONFIG_NOLDL
36 LIBS+=-ldl
37 endif
38 endif
40 ifeq ($(ARCH),i386)
41 NATIVE_DEFINES=-DTCC_TARGET_I386
42 NATIVE_DEFINES+=$(if $(wildcard /lib/i386-linux-gnu),-DCONFIG_MULTIARCHDIR=\"i386-linux-gnu\")
43 NATIVE_DEFINES+=$(if $(wildcard /lib/i386-kfreebsd-gnu),-DCONFIG_MULTIARCHDIR=\"i386-kfreebsd-gnu\")
44 NATIVE_DEFINES+=$(if $(wildcard /lib/i386-gnu),-DCONFIG_MULTIARCHDIR=\"i386-gnu\")
45 CFLAGS+=-m32
46 else
47 ifeq ($(ARCH),x86-64)
48 NATIVE_DEFINES=-DTCC_TARGET_X86_64
49 CFLAGS+=-m64
50 NATIVE_DEFINES+=$(if $(wildcard /usr/lib64),-DCONFIG_LDDIR=\"lib64\")
51 NATIVE_DEFINES+=$(if $(wildcard /lib/x86_64-linux-gnu),-DCONFIG_MULTIARCHDIR=\"x86_64-linux-gnu\")
52 NATIVE_DEFINES+=$(if $(wildcard /lib/x86_64-kfreebsd-gnu),-DCONFIG_MULTIARCHDIR=\"x86_64-kfreebsd-gnu\")
53 endif
54 endif
56 ifeq ($(ARCH),arm)
57 NATIVE_DEFINES=-DTCC_TARGET_ARM
58 NATIVE_DEFINES+=-DWITHOUT_LIBTCC
59 NATIVE_DEFINES+=$(if $(wildcard /lib/ld-linux.so.3),-DTCC_ARM_EABI)
60 NATIVE_DEFINES+=$(if $(wildcard /lib/arm-linux-gnueabi),-DCONFIG_MULTIARCHDIR=\"arm-linux-gnueabi\")
61 NATIVE_DEFINES+=$(if $(shell grep -l "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo),-DTCC_ARM_VFP)
62 # To use ARM hardfloat calling convension
63 #NATIVE_DEFINES+=-DTCC_ARM_HARDFLOAT
64 endif
66 ifdef CONFIG_WIN32
67 NATIVE_DEFINES+=-DTCC_TARGET_PE
68 endif
70 ifneq ($(wildcard /lib/ld-uClibc.so.0),)
71 NATIVE_DEFINES+=-DTCC_UCLIBC
72 CONFIG_UCLIBC = 1
73 endif
75 # make libtcc as static or dynamic library?
76 ifdef DISABLE_STATIC
77 LIBTCC=libtcc.so.1.0
78 LINK_LIBTCC=-Wl,-rpath,"$(libdir)"
79 ifdef DISABLE_RPATH
80 LINK_LIBTCC=
81 endif
82 else
83 LIBTCC=libtcc.a
84 LINK_LIBTCC=
85 endif
87 ifeq ($(TOP),.)
89 PROGS=tcc$(EXESUF)
90 I386_CROSS = i386-tcc$(EXESUF)
91 WIN32_CROSS = i386-win32-tcc$(EXESUF)
92 WIN64_CROSS = x86_64-win32-tcc$(EXESUF)
93 WINCE_CROSS = arm-win32-tcc$(EXESUF)
94 X64_CROSS = x86_64-tcc$(EXESUF)
95 ARM_FPA_CROSS = arm-fpa-tcc$(EXESUF)
96 ARM_FPA_LD_CROSS = arm-fpa-ld-tcc$(EXESUF)
97 ARM_VFP_CROSS = arm-vfp-tcc$(EXESUF)
98 ARM_EABI_CROSS = arm-eabi-tcc$(EXESUF)
99 ARM_CROSS = $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS)
100 C67_CROSS = c67-tcc$(EXESUF)
102 CORE_FILES = tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
103 CORE_FILES += tcc.h config.h libtcc.h tcctok.h
104 I386_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h
105 WIN32_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
106 WIN64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h tccpe.c
107 WINCE_FILES = $(CORE_FILES) arm-gen.c tccpe.c
108 X86_64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h
109 ARM_FILES = $(CORE_FILES) arm-gen.c
110 C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c
112 ifdef CONFIG_WIN64
113 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
114 NATIVE_FILES=$(WIN64_FILES)
115 PROGS_CROSS=$(WIN32_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
116 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a
117 LIBTCC1=libtcc1.a
118 else
119 ifdef CONFIG_WIN32
120 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
121 NATIVE_FILES=$(WIN32_FILES)
122 PROGS_CROSS=$(WIN64_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
123 LIBTCC1_CROSS=lib/x86_64-win32/libtcc1.a
124 LIBTCC1=libtcc1.a
125 else
126 ifeq ($(ARCH),i386)
127 NATIVE_FILES=$(I386_FILES)
128 PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
129 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a
130 LIBTCC1=libtcc1.a
131 BCHECK_O=bcheck.o
132 else
133 ifeq ($(ARCH),x86-64)
134 NATIVE_FILES=$(X86_64_FILES)
135 PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
136 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a lib/i386/libtcc1.a
137 LIBTCC1=libtcc1.a
138 else
139 ifeq ($(ARCH),arm)
140 NATIVE_FILES=$(ARM_FILES)
141 PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(C67_CROSS)
142 endif
143 endif
144 endif
145 endif
146 endif
148 ifdef CONFIG_UCLIBC
149 BCHECK_O=
150 endif
151 ifeq ($(TARGETOS),Darwin)
152 BCHECK_O=
153 PROGS+=tiny_libmaker$(EXESUF)
154 endif
156 ifdef CONFIG_USE_LIBGCC
157 LIBTCC1=
158 endif
160 TCCLIBS = $(LIBTCC1) $(LIBTCC) $(BCHECK_O)
161 TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info
163 ifdef CONFIG_CROSS
164 PROGS+=$(PROGS_CROSS)
165 TCCLIBS+=$(LIBTCC1_CROSS)
166 endif
168 all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
170 # Host Tiny C Compiler
171 tcc$(EXESUF): tcc.o $(LIBTCC)
172 $(CC) -o $@ $^ $(LIBS) $(CFLAGS) $(LDFLAGS) $(LINK_LIBTCC)
174 # Cross Tiny C Compilers
175 %-tcc$(EXESUF):
176 $(CC) -o $@ tcc.c -DONE_SOURCE $(DEFINES) $(CFLAGS) $(LIBS) $(LDFLAGS)
178 $(I386_CROSS): DEFINES = -DTCC_TARGET_I386 \
179 -DCONFIG_TCCDIR="\"$(tccdir)/i386\""
180 $(X64_CROSS): DEFINES = -DTCC_TARGET_X86_64
181 $(WIN32_CROSS): DEFINES = -DTCC_TARGET_I386 -DTCC_TARGET_PE \
182 -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
183 -DCONFIG_TCC_LIBPATHS="\"{B}/lib/32;{B}/lib\""
184 $(WIN64_CROSS): DEFINES = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE \
185 -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
186 -DCONFIG_TCC_LIBPATHS="\"{B}/lib/64;{B}/lib\""
187 $(WINCE_CROSS): DEFINES = -DTCC_TARGET_PE
188 $(C67_CROSS): DEFINES = -DTCC_TARGET_C67
189 $(ARM_FPA_CROSS): DEFINES = -DTCC_TARGET_ARM
190 $(ARM_FPA_LD_CROSS)$(EXESUF): DEFINES = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
191 $(ARM_VFP_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_VFP
192 $(ARM_EABI_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_EABI
194 $(I386_CROSS): $(I386_FILES)
195 $(X64_CROSS): $(X86_64_FILES)
196 $(WIN32_CROSS): $(WIN32_FILES)
197 $(WIN64_CROSS): $(WIN64_FILES)
198 $(WINCE_CROSS): $(WINCE_FILES)
199 $(C67_CROSS): $(C67_FILES)
200 $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS): $(ARM_FILES)
202 # libtcc generation and test
203 ifndef ONE_SOURCE
204 LIBTCC_OBJ = $(filter-out tcc.o,$(patsubst %.c,%.o,$(filter %.c,$(NATIVE_FILES))))
205 LIBTCC_INC = $(filter %.h,$(CORE_FILES)) $(filter-out $(CORE_FILES),$(NATIVE_FILES))
206 else
207 LIBTCC_OBJ = libtcc.o
208 LIBTCC_INC = $(NATIVE_FILES)
209 libtcc.o : NATIVE_DEFINES += -DONE_SOURCE
210 endif
212 $(LIBTCC_OBJ) tcc.o : %.o : %.c $(LIBTCC_INC)
213 $(CC) -o $@ -c $< $(NATIVE_DEFINES) $(CFLAGS)
215 libtcc.a: $(LIBTCC_OBJ)
216 $(AR) rcs $@ $^
218 libtcc.so.1.0: $(LIBTCC_OBJ)
219 $(CC) -shared -Wl,-soname,$@ -o $@ $^
221 libtcc.so.1.0: CFLAGS+=-fPIC
223 # profiling version
224 tcc_p$(EXESUF): $(NATIVE_FILES)
225 $(CC) -o $@ $< $(NATIVE_DEFINES) $(CFLAGS_P) $(LIBS_P)
227 # windows utilities
228 tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
229 $(CC) -o $@ $< $(CFLAGS)
230 tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
231 $(CC) -o $@ $< $(CFLAGS)
233 # TinyCC runtime libraries
234 libtcc1.a : FORCE
235 @$(MAKE) -C lib native
236 lib/%/libtcc1.a : FORCE $(PROGS_CROSS)
237 @$(MAKE) -C lib cross TARGET=$*
238 bcheck.o : lib/bcheck.c
239 gcc -c $< -o $@ $(CFLAGS)
240 FORCE:
242 # install
243 TCC_INCLUDES = stdarg.h stddef.h stdbool.h float.h varargs.h tcclib.h
244 INSTALL=install
245 ifdef STRIP_BINARIES
246 INSTALLBIN=$(INSTALL) -s
247 else
248 INSTALLBIN=$(INSTALL)
249 endif
251 ifndef CONFIG_WIN32
252 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
253 mkdir -p "$(bindir)"
254 ifeq ($(CC),tcc)
255 $(INSTALL) -m755 $(PROGS) "$(bindir)"
256 else
257 $(INSTALLBIN) -m755 $(PROGS) "$(bindir)"
258 endif
259 mkdir -p "$(mandir)/man1"
260 -$(INSTALL) tcc.1 "$(mandir)/man1"
261 mkdir -p "$(infodir)"
262 -$(INSTALL) tcc-doc.info "$(infodir)"
263 mkdir -p "$(tccdir)"
264 mkdir -p "$(tccdir)/include"
265 ifneq ($(LIBTCC1),)
266 $(INSTALL) -m644 $(LIBTCC1) "$(tccdir)"
267 endif
268 ifneq ($(BCHECK_O),)
269 $(INSTALL) -m644 $(BCHECK_O) "$(tccdir)"
270 endif
271 $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
272 mkdir -p "$(libdir)"
273 $(INSTALL) -m755 $(LIBTCC) "$(libdir)"
274 ifdef DISABLE_STATIC
275 ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so.1"
276 ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so"
277 endif
278 mkdir -p "$(includedir)"
279 $(INSTALL) -m644 libtcc.h "$(includedir)"
280 mkdir -p "$(docdir)"
281 -$(INSTALL) -m644 tcc-doc.html "$(docdir)"
282 ifdef CONFIG_CROSS
283 mkdir -p "$(tccdir)/win32/lib/32"
284 mkdir -p "$(tccdir)/win32/lib/64"
285 ifeq ($(ARCH),x86-64)
286 mkdir -p "$(tccdir)/i386"
287 $(INSTALL) -m644 lib/i386/libtcc1.a "$(tccdir)/i386"
288 cp -r "$(tccdir)/include" "$(tccdir)/i386"
289 endif
290 $(INSTALL) -m644 win32/lib/*.def "$(tccdir)/win32/lib"
291 $(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/win32/lib/32"
292 $(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/win32/lib/64"
293 cp -r win32/include/. "$(tccdir)/win32/include"
294 cp -r include/. "$(tccdir)/win32/include"
295 endif
297 uninstall:
298 rm -fv $(foreach P,$(PROGS),"$(bindir)/$P")
299 rm -fv $(foreach P,$(LIBTCC1) $(BCHECK_O),"$(tccdir)/$P")
300 rm -fv $(foreach P,$(TCC_INCLUDES),"$(tccdir)/include/$P")
301 rm -fv "$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
302 rm -fv "$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
303 rm -fv "$(libdir)/libtcc.so*"
304 rm -rf "$(tccdir)/win32"
305 -rmdir $(tccdir)/include
306 ifeq ($(ARCH),x86-64)
307 rm -rf "$(tccdir)/i386"
308 endif
309 else
310 # on windows
311 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
312 mkdir -p "$(tccdir)"
313 mkdir -p "$(tccdir)/lib"
314 mkdir -p "$(tccdir)/include"
315 mkdir -p "$(tccdir)/examples"
316 mkdir -p "$(tccdir)/doc"
317 mkdir -p "$(tccdir)/libtcc"
318 $(INSTALLBIN) -m755 $(PROGS) "$(tccdir)"
319 $(INSTALL) -m644 $(LIBTCC1) win32/lib/*.def "$(tccdir)/lib"
320 cp -r win32/include/. "$(tccdir)/include"
321 cp -r win32/examples/. "$(tccdir)/examples"
322 $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
323 $(INSTALL) -m644 tcc-doc.html win32/tcc-win32.txt "$(tccdir)/doc"
324 $(INSTALL) -m644 $(LIBTCC) libtcc.h "$(tccdir)/libtcc"
325 ifdef CONFIG_CROSS
326 mkdir -p "$(tccdir)/lib/32"
327 mkdir -p "$(tccdir)/lib/64"
328 -$(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/lib/32"
329 -$(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/lib/64"
330 endif
332 uninstall:
333 rm -rfv "$(tccdir)/*"
334 endif
336 # documentation and man page
337 tcc-doc.html: tcc-doc.texi
338 -texi2html -monolithic -number $<
340 tcc.1: tcc-doc.texi
341 -./texi2pod.pl $< tcc.pod
342 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@
344 tcc-doc.info: tcc-doc.texi
345 -makeinfo tcc-doc.texi
347 .PHONY: all clean tar distclean install uninstall FORCE
349 # tar release (use 'make -k tar' on a checkouted tree)
350 TCC-VERSION=tcc-$(shell cat VERSION)
351 tar:
352 rm -rf /tmp/$(TCC-VERSION)
353 cp -r . /tmp/$(TCC-VERSION)
354 ( cd /tmp ; tar zcvf ~/$(TCC-VERSION).tar.gz $(TCC-VERSION) --exclude CVS )
355 rm -rf /tmp/$(TCC-VERSION)
357 # in tests subdir
358 export LIBTCC1
360 %est:
361 $(MAKE) -C tests2 $@
362 $(MAKE) -C tests $@
364 clean:
365 rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.so* *.out *.exe libtcc_test$(EXESUF)
366 $(MAKE) -C tests2 $@
367 $(MAKE) -C tests $@
368 ifneq ($(LIBTCC1),)
369 $(MAKE) -C lib $@
370 endif
372 distclean: clean
373 rm -vf config.h config.mak config.texi tcc.1 tcc-doc.info tcc-doc.html
375 config.mak:
376 @echo "Please run ./configure."
377 @exit 1
379 endif # ifeq ($(TOP),.)