Add make testspp.all/testspp.20
[tinycc.git] / Makefile
blob02d36258f88ac44dcff87573c1abddfae381d18f
1 # --------------------------------------------------------------------------
3 # Tiny C Compiler Makefile
6 ifndef TOP
7 TOP = .
8 INCLUDED = no
9 endif
11 include $(TOP)/config.mak
13 ifeq (-$(CC)-$(GCC_MAJOR)-$(findstring $(GCC_MINOR),56789)-,-gcc-4--)
14 CFLAGS += -D_FORTIFY_SOURCE=0
15 endif
17 LIBTCC = libtcc.a
18 LIBTCC1 = libtcc1.a
19 LINK_LIBTCC =
20 LIBS =
21 CFLAGS += -I$(TOP)
22 CFLAGS += $(CPPFLAGS)
23 VPATH = $(TOPSRC)
25 ifdef CONFIG_WIN32
26 ifneq ($(CONFIG_static),yes)
27 LIBTCC = libtcc$(DLLSUF)
28 LIBTCCDEF = libtcc.def
29 endif
30 CFGWIN = -win
31 NATIVE_TARGET = $(ARCH)-win$(if $(findstring arm,$(ARCH)),ce,32)
32 else
33 LIBS=-lm
34 ifneq ($(CONFIG_ldl),no)
35 LIBS+=-ldl
36 endif
37 # make libtcc as static or dynamic library?
38 ifeq ($(CONFIG_static),no)
39 LIBTCC=libtcc$(DLLSUF)
40 export LD_LIBRARY_PATH := $(CURDIR)/$(TOP)
41 ifneq ($(CONFIG_rpath),no)
42 LINK_LIBTCC += -Wl,-rpath,"$(libdir)"
43 endif
44 endif
45 CFGWIN =-unx
46 NATIVE_TARGET = $(ARCH)
47 ifdef CONFIG_OSX
48 NATIVE_TARGET = $(ARCH)-osx
49 LDFLAGS += -flat_namespace -undefined warning
50 export MACOSX_DEPLOYMENT_TARGET := 10.2
51 endif
52 endif
54 # run local version of tcc with local libraries and includes
55 TCCFLAGS-unx = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP)
56 TCCFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP)
57 TCCFLAGS = $(TCCFLAGS$(CFGWIN))
58 TCC = $(TOP)/tcc$(EXESUF) $(TCCFLAGS)
59 ifdef CONFIG_OSX
60 TCCFLAGS += -D_ANSI_SOURCE
61 endif
63 CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC -DTCC_PROFILE
64 LIBS_P = $(LIBS)
65 LDFLAGS_P = $(LDFLAGS)
67 CONFIG_$(ARCH) = yes
68 NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
69 NATIVE_DEFINES_$(CONFIG_x86_64) += -DTCC_TARGET_X86_64
70 NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE
71 NATIVE_DEFINES_$(CONFIG_OSX) += -DTCC_TARGET_MACHO
72 NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC
73 NATIVE_DEFINES_$(CONFIG_musl) += -DTCC_MUSL
74 NATIVE_DEFINES_$(CONFIG_libgcc) += -DCONFIG_USE_LIBGCC
75 NATIVE_DEFINES_$(CONFIG_selinux) += -DHAVE_SELINUX
76 NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM
77 NATIVE_DEFINES_$(CONFIG_arm_eabihf) += -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT
78 NATIVE_DEFINES_$(CONFIG_arm_eabi) += -DTCC_ARM_EABI
79 NATIVE_DEFINES_$(CONFIG_arm_vfp) += -DTCC_ARM_VFP
80 NATIVE_DEFINES_$(CONFIG_arm64) += -DTCC_TARGET_ARM64
81 NATIVE_DEFINES += $(NATIVE_DEFINES_yes)
83 ifeq ($(INCLUDED),no)
84 # --------------------------------------------------------------------------
85 # running top Makefile
87 PROGS = tcc$(EXESUF)
88 TCCLIBS = $(LIBTCC1) $(LIBTCC) $(LIBTCCDEF)
89 TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info
91 all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
93 # cross compiler targets to build
94 TCC_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince c67
95 # TCC_X += arm-fpa arm-fpa-ld arm-vfp arm-eabi
97 # cross libtcc1.a targets to build
98 LIBTCC1_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince
100 PROGS_CROSS = $(foreach X,$(TCC_X),$X-tcc$(EXESUF))
101 LIBTCC1_CROSS = $(foreach X,$(LIBTCC1_X),$X-libtcc1.a)
103 # build cross compilers & libs
104 cross: $(LIBTCC1_CROSS) $(PROGS_CROSS)
106 # build specific cross compiler & lib
107 cross-%: %-tcc$(EXESUF) %-libtcc1.a ;
109 install: ; @$(MAKE) --no-print-directory install$(CFGWIN)
110 install-strip: ; @$(MAKE) --no-print-directory install$(CFGWIN) CONFIG_strip=yes
111 uninstall: ; @$(MAKE) --no-print-directory uninstall$(CFGWIN)
113 ifdef CONFIG_cross
114 all : cross
115 endif
117 # --------------------------------------------
119 T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown)
120 X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-)
122 DEF-i386 = -DTCC_TARGET_I386
123 DEF-x86_64 = -DTCC_TARGET_X86_64
124 DEF-i386-win32 = -DTCC_TARGET_PE -DTCC_TARGET_I386
125 DEF-x86_64-win32= -DTCC_TARGET_PE -DTCC_TARGET_X86_64
126 DEF-x86_64-osx = -DTCC_TARGET_MACHO -DTCC_TARGET_X86_64
127 DEF-arm-wince = -DTCC_TARGET_PE -DTCC_TARGET_ARM -DTCC_ARM_EABI -DTCC_ARM_VFP -DTCC_ARM_HARDFLOAT
128 DEF-arm64 = -DTCC_TARGET_ARM64
129 DEF-c67 = -DTCC_TARGET_C67 -w # disable warnigs
130 DEF-arm-fpa = -DTCC_TARGET_ARM
131 DEF-arm-fpa-ld = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
132 DEF-arm-vfp = -DTCC_TARGET_ARM -DTCC_ARM_VFP
133 DEF-arm-eabi = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DTCC_ARM_EABI
134 DEF-arm-eabihf = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT
135 DEF-arm = $(DEF-arm-eabihf)
136 DEF-$(NATIVE_TARGET) = $(NATIVE_DEFINES)
138 DEFINES += $(DEF-$T) $(DEF-all)
139 DEFINES += $(if $(ROOT-$T),-DCONFIG_SYSROOT="\"$(ROOT-$T)\"")
140 DEFINES += $(if $(CRT-$T),-DCONFIG_TCC_CRTPREFIX="\"$(CRT-$T)\"")
141 DEFINES += $(if $(LIB-$T),-DCONFIG_TCC_LIBPATHS="\"$(LIB-$T)\"")
142 DEFINES += $(if $(INC-$T),-DCONFIG_TCC_SYSINCLUDEPATHS="\"$(INC-$T)\"")
143 DEFINES += $(DEF-$(or $(findstring win,$T),unx))
145 ifneq ($(X),)
146 ifeq ($(CONFIG_WIN32),yes)
147 DEF-win += -DTCC_LIBTCC1="\"$(X)libtcc1.a\""
148 DEF-unx += -DTCC_LIBTCC1="\"lib/$(X)libtcc1.a\""
149 else
150 DEF-all += -DTCC_LIBTCC1="\"$(X)libtcc1.a\""
151 DEF-win += -DCONFIG_TCCDIR="\"$(tccdir)/win32\""
152 endif
153 endif
155 # include custom configuration (see make help)
156 -include config-extra.mak
158 CORE_FILES = tcc.c tcctools.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
159 CORE_FILES += tcc.h config.h libtcc.h tcctok.h
160 i386_FILES = $(CORE_FILES) i386-gen.c i386-link.c i386-asm.c i386-asm.h i386-tok.h
161 i386-win32_FILES = $(i386_FILES) tccpe.c
162 x86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h
163 x86_64-win32_FILES = $(x86_64_FILES) tccpe.c
164 x86_64-osx_FILES = $(x86_64_FILES)
165 arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c
166 arm-wince_FILES = $(arm_FILES) tccpe.c
167 arm64_FILES = $(CORE_FILES) arm64-gen.c arm64-link.c
168 c67_FILES = $(CORE_FILES) c67-gen.c c67-link.c tcccoff.c
170 # libtcc sources
171 LIBTCC_SRC = $(filter-out tcc.c tcctools.c,$(filter %.c,$($T_FILES)))
173 ifeq ($(ONE_SOURCE),yes)
174 LIBTCC_OBJ = $(X)libtcc.o
175 LIBTCC_INC = $($T_FILES)
176 TCC_FILES = $(X)tcc.o
177 tcc.o : DEFINES += -DONE_SOURCE=0
178 else
179 LIBTCC_OBJ = $(patsubst %.c,$(X)%.o,$(LIBTCC_SRC))
180 LIBTCC_INC = $(filter %.h %-gen.c %-link.c,$($T_FILES))
181 TCC_FILES = $(X)tcc.o $(LIBTCC_OBJ)
182 $(TCC_FILES) : DEFINES += -DONE_SOURCE=0
183 endif
185 # target specific object rule
186 $(X)%.o : %.c $(LIBTCC_INC)
187 $(CC) -o $@ -c $< $(DEFINES) $(CFLAGS)
189 # additional dependencies
190 $(X)tcc.o : tcctools.c
192 # Host Tiny C Compiler
193 tcc$(EXESUF): tcc.o $(LIBTCC)
194 $(CC) -o $@ $^ $(LIBS) $(LDFLAGS) $(LINK_LIBTCC)
196 # Cross Tiny C Compilers
197 %-tcc$(EXESUF): FORCE
198 @$(MAKE) --no-print-directory $@ CROSS_TARGET=$* ONE_SOURCE=$(or $(ONE_SOURCE),yes)
200 $(CROSS_TARGET)-tcc$(EXESUF): $(TCC_FILES)
201 $(CC) -o $@ $^ $(LIBS) $(LDFLAGS)
203 # profiling version
204 tcc_p$(EXESUF): $($T_FILES)
205 $(CC) -o $@ $< $(DEFINES) $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P)
207 # static libtcc library
208 libtcc.a: $(LIBTCC_OBJ)
209 $(AR) rcs $@ $^
211 # dynamic libtcc library
212 libtcc.so: $(LIBTCC_OBJ)
213 $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDFLAGS)
215 libtcc.so: CFLAGS+=-fPIC
216 libtcc.so: LDFLAGS+=-fPIC
218 # windows dynamic libtcc library
219 libtcc.dll : $(LIBTCC_OBJ)
220 $(CC) -shared -o $@ $^ $(LDFLAGS)
221 libtcc.dll : DEFINES += -DLIBTCC_AS_DLL
223 # import file for windows libtcc.dll
224 libtcc.def : libtcc.dll tcc$(EXESUF)
225 $(XTCC) -impdef $< -o $@
226 XTCC ?= ./tcc$(EXESUF)
228 # TinyCC runtime libraries
229 libtcc1.a : tcc$(EXESUF) FORCE
230 @$(MAKE) -C lib DEFINES='$(DEF-$T)'
232 # Cross libtcc1.a
233 %-libtcc1.a : %-tcc$(EXESUF) FORCE
234 @$(MAKE) -C lib DEFINES='$(DEF-$*)' CROSS_TARGET=$*
236 .PRECIOUS: %-libtcc1.a
237 FORCE:
239 # --------------------------------------------------------------------------
240 # documentation and man page
241 tcc-doc.html: tcc-doc.texi
242 makeinfo --no-split --html --number-sections -o $@ $< || true
244 tcc.1: tcc-doc.texi
245 $(TOPSRC)/texi2pod.pl $< tcc.pod \
246 && pod2man --section=1 --center="Tiny C Compiler" --release="$(VERSION)" tcc.pod >tmp.1 \
247 && mv tmp.1 $@ || rm -f tmp.1
249 tcc-doc.info: tcc-doc.texi
250 makeinfo $< || true
252 # --------------------------------------------------------------------------
253 # install
255 INSTALL = install -m644
256 INSTALLBIN = install -m755 $(STRIP_$(CONFIG_strip))
257 STRIP_yes = -s
259 LIBTCC1_W = $(filter %-win32-libtcc1.a %-wince-libtcc1.a,$(LIBTCC1_CROSS))
260 LIBTCC1_U = $(filter-out $(LIBTCC1_W),$(LIBTCC1_CROSS))
261 IB = $(if $1,mkdir -p $2 && $(INSTALLBIN) $1 $2)
262 IBw = $(call IB,$(wildcard $1),$2)
263 IF = $(if $1,mkdir -p $2 && $(INSTALL) $1 $2)
264 IFw = $(call IF,$(wildcard $1),$2)
265 IR = mkdir -p $2 && cp -r $1/. $2
267 # install progs & libs
268 install-unx:
269 $(call IBw,$(PROGS) $(PROGS_CROSS),"$(bindir)")
270 $(call IFw,$(LIBTCC1) $(LIBTCC1_U),"$(tccdir)")
271 $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/include")
272 $(call $(if $(findstring .so,$(LIBTCC)),IBw,IFw),$(LIBTCC),"$(libdir)")
273 $(call IF,$(TOPSRC)/libtcc.h,"$(includedir)")
274 $(call IFw,tcc.1,"$(mandir)/man1")
275 $(call IFw,tcc-doc.info,"$(infodir)")
276 $(call IFw,tcc-doc.html,"$(docdir)")
277 ifneq "$(wildcard $(LIBTCC1_W))" ""
278 $(call IFw,$(TOPSRC)/win32/lib/*.def $(LIBTCC1_W),"$(tccdir)/win32/lib")
279 $(call IR,$(TOPSRC)/win32/include,"$(tccdir)/win32/include")
280 $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/win32/include")
281 endif
283 # uninstall
284 uninstall-unx:
285 @rm -fv $(foreach P,$(PROGS) $(PROGS_CROSS),"$(bindir)/$P")
286 @rm -fv "$(libdir)/libtcc.a" "$(libdir)/libtcc.so" "$(includedir)/libtcc.h"
287 @rm -fv "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
288 @rm -fv "$(docdir)/tcc-doc.html"
289 rm -r "$(tccdir)"
291 # install progs & libs on windows
292 install-win:
293 $(call IBw,$(PROGS) $(PROGS_CROSS) $(subst libtcc.a,,$(LIBTCC)),"$(bindir)")
294 $(call IF,$(TOPSRC)/win32/lib/*.def,"$(tccdir)/lib")
295 $(call IFw,libtcc1.a $(LIBTCC1_W),"$(tccdir)/lib")
296 $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/include")
297 $(call IR,$(TOPSRC)/win32/include,"$(tccdir)/include")
298 $(call IR,$(TOPSRC)/win32/examples,"$(tccdir)/examples")
299 $(call IF,$(TOPSRC)/tests/libtcc_test.c,"$(tccdir)/examples")
300 $(call IFw,$(TOPSRC)/libtcc.h $(subst .dll,.def,$(LIBTCC)),"$(libdir)")
301 $(call IFw,$(TOPSRC)/win32/tcc-win32.txt tcc-doc.html,"$(docdir)")
302 ifneq "$(wildcard $(LIBTCC1_U))" ""
303 $(call IFw,$(LIBTCC1_U),"$(tccdir)/lib")
304 $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/lib/include")
305 endif
307 # the msys-git shell works to configure && make except it does not have install
308 ifeq "$(and $(CONFIG_WIN32),$(shell which install >/dev/null 2>&1 || echo no))" "no"
309 install-win : INSTALL = cp
310 install-win : INSTALLBIN = cp
311 endif
313 # uninstall on windows
314 uninstall-win:
315 @rm -fv $(foreach P,$(PROGS) $(PROGS_CROSS) libtcc.dll,"$(bindir)/$P")
316 @rm -fv $(foreach F,tcc-doc.html tcc-win32.txt,"$(docdir)/$F")
317 @rm -fv $(foreach F,libtcc.h libtcc.def libtcc.a,"$(libdir)/$F")
318 rm -r "$(tccdir)"
320 # --------------------------------------------------------------------------
321 # other stuff
323 TAGFILES = *.[ch] include/*.h lib/*.[chS]
324 tags : ; ctags $(TAGFILES)
325 # cannot have both tags and TAGS on windows
326 ETAGS : ; etags $(TAGFILES)
328 # create release tarball from *current* git branch (including tcc-doc.html
329 # and converting two files to CRLF)
330 TCC-VERSION = tcc-$(VERSION)
331 tar: tcc-doc.html
332 mkdir $(TCC-VERSION)
333 ( cd $(TCC-VERSION) && git --git-dir ../.git checkout -f )
334 cp tcc-doc.html $(TCC-VERSION)
335 for f in tcc-win32.txt build-tcc.bat ; do \
336 cat win32/$$f | sed 's,\(.*\),\1\r,g' > $(TCC-VERSION)/win32/$$f ; \
337 done
338 tar cjf $(TCC-VERSION).tar.bz2 $(TCC-VERSION)
339 rm -rf $(TCC-VERSION)
340 git reset
342 config.mak:
343 $(if $(wildcard $@),,@echo "Please run ./configure." && exit 1)
345 # run all tests
346 test:
347 $(MAKE) -C tests
348 # run test(s) from tests2 subdir (see make help)
349 tests2.%:
350 $(MAKE) -C tests/tests2 $@
352 testspp.%:
353 $(MAKE) -C tests/pp $@
355 clean:
356 rm -f tcc$(EXESUF) tcc_p$(EXESUF) *-tcc$(EXESUF) tcc.pod
357 rm -f *~ *.o *.a *.so* *.out *.log lib*.def *.exe *.dll a.out tags TAGS
358 @$(MAKE) -C lib $@
359 @$(MAKE) -C tests $@
361 distclean: clean
362 rm -f config.h config.mak config.texi tcc.1 tcc-doc.info tcc-doc.html
364 .PHONY: all clean test tar tags ETAGS distclean install uninstall FORCE
366 help:
367 @echo "make"
368 @echo " build native compiler (from separate objects)"
369 @echo ""
370 @echo "make cross"
371 @echo " build cross compilers (from one source)"
372 @echo ""
373 @echo "make ONE_SOURCE=yes / no"
374 @echo " force building from one source / separate objects"
375 @echo ""
376 @echo "make cross-TARGET"
377 @echo " build one specific cross compiler for 'TARGET', as in"
378 @echo " $(TCC_X)"
379 @echo ""
380 @echo "Custom configuration:"
381 @echo " The makefile includes a file 'config-extra.mak' if it is present."
382 @echo " This file may contain some custom configuration. For example:"
383 @echo ""
384 @echo " NATIVE_DEFINES += -D..."
385 @echo ""
386 @echo " Or for example to configure the search paths for a cross-compiler"
387 @echo " that expects the linux files in <tccdir>/i386-linux:"
388 @echo ""
389 @echo " ROOT-i386 = {B}/i386-linux"
390 @echo " CRT-i386 = {B}/i386-linux/usr/lib"
391 @echo " LIB-i386 = {B}/i386-linux/lib:{B}/i386-linux/usr/lib"
392 @echo " INC-i386 = {B}/lib/include:{B}/i386-linux/usr/include"
393 @echo " DEF-i386 += -D__linux__"
394 @echo ""
395 @echo "make test"
396 @echo " run all tests"
397 @echo ""
398 @echo "make tests2.all / make tests2.37 / make tests2.37+"
399 @echo " run all/single test(s) from tests2, optionally update .expect"
400 @echo "make testspp.all / make testspp.17"
401 @echo " run all/single test(s) from tests/pp"
402 @echo ""
403 @echo "Other supported make targets:"
404 @echo " install install-strip tags ETAGS tar clean distclean help"
405 @echo ""
407 # --------------------------------------------------------------------------
408 endif # ($(INCLUDED),no)