Windows test Makefile target also test pp tests.
[tinycc.git] / Makefile
blob565ce2cb6d4eb81a6e4ca41b2357ce8f9ec63f99
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),libtcc1-$X.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: install$(CFGWIN)
110 uninstall: uninstall$(CFGWIN)
112 ifdef CONFIG_cross
113 all : cross
114 endif
116 # --------------------------------------------
118 T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown)
119 X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-)
121 DEF-i386 = -DTCC_TARGET_I386
122 DEF-x86_64 = -DTCC_TARGET_X86_64
123 DEF-i386-win32 = -DTCC_TARGET_PE -DTCC_TARGET_I386
124 DEF-x86_64-win32= -DTCC_TARGET_PE -DTCC_TARGET_X86_64
125 DEF-x86_64-osx = -DTCC_TARGET_MACHO -DTCC_TARGET_X86_64
126 DEF-arm-wince = -DTCC_TARGET_PE -DTCC_TARGET_ARM -DTCC_ARM_EABI -DTCC_ARM_VFP -DTCC_ARM_HARDFLOAT
127 DEF-arm64 = -DTCC_TARGET_ARM64
128 DEF-c67 = -DTCC_TARGET_C67 -w # disable warnigs
129 DEF-arm-fpa = -DTCC_TARGET_ARM
130 DEF-arm-fpa-ld = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
131 DEF-arm-vfp = -DTCC_TARGET_ARM -DTCC_ARM_VFP
132 DEF-arm-eabi = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DTCC_ARM_EABI
133 DEF-arm-eabihf = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT
134 DEF-arm = $(DEF-arm-eabihf)
135 DEF-$(NATIVE_TARGET) = $(NATIVE_DEFINES)
137 DEFINES += $(DEF-$T) $(DEF-all)
138 DEFINES += $(if $(ROOT-$T),-DCONFIG_SYSROOT="\"$(ROOT-$T)\"")
139 DEFINES += $(if $(CRT-$T),-DCONFIG_TCC_CRTPREFIX="\"$(CRT-$T)\"")
140 DEFINES += $(if $(LIB-$T),-DCONFIG_TCC_LIBPATHS="\"$(LIB-$T)\"")
141 DEFINES += $(if $(INC-$T),-DCONFIG_TCC_SYSINCLUDEPATHS="\"$(INC-$T)\"")
142 DEFINES += $(DEF-$(or $(findstring win,$T),unx))
144 ifneq ($(X),)
145 ifeq ($(CONFIG_WIN32),yes)
146 DEF-win += -DTCC_LIBTCC1="\"libtcc1-$T.a\""
147 DEF-unx += -DTCC_LIBTCC1="\"lib/libtcc1-$T.a\""
148 else
149 DEF-all += -DTCC_LIBTCC1="\"libtcc1-$T.a\""
150 DEF-win += -DCONFIG_TCCDIR="\"$(tccdir)/win32\""
151 endif
152 endif
154 # include custom cross-compiler configuration (see make help)
155 -include config-cross.mak
157 CORE_FILES = tcc.c tcctools.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
158 CORE_FILES += tcc.h config.h libtcc.h tcctok.h
159 i386_FILES = $(CORE_FILES) i386-gen.c i386-link.c i386-asm.c i386-asm.h i386-tok.h
160 i386-win32_FILES = $(i386_FILES) tccpe.c
161 x86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h
162 x86_64-win32_FILES = $(x86_64_FILES) tccpe.c
163 x86_64-osx_FILES = $(x86_64_FILES)
164 arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c
165 arm-wince_FILES = $(arm_FILES) tccpe.c
166 arm64_FILES = $(CORE_FILES) arm64-gen.c arm64-link.c
167 c67_FILES = $(CORE_FILES) c67-gen.c c67-link.c tcccoff.c
169 # libtcc sources
170 LIBTCC_SRC = $(filter-out tcc.c tcctools.c,$(filter %.c,$($T_FILES)))
172 ifeq ($(ONE_SOURCE),yes)
173 LIBTCC_OBJ = $(X)libtcc.o
174 LIBTCC_INC = $($T_FILES)
175 TCC_FILES = $(X)tcc.o
176 $(X)libtcc.o $T-tcc$(EXESUF) : DEFINES += -DONE_SOURCE
177 else
178 LIBTCC_OBJ = $(patsubst %.c,$(X)%.o,$(LIBTCC_SRC))
179 LIBTCC_INC = $(filter %.h %-gen.c %-link.c,$($T_FILES))
180 TCC_FILES = $(X)tcc.o $(LIBTCC_OBJ)
181 endif
183 # target specific object rule
184 $(X)%.o : %.c $(LIBTCC_INC)
185 $(CC) -o $@ -c $< $(DEFINES) $(CFLAGS)
187 # additional dependencies
188 $(X)tcc.o : tcctools.c
190 # Host Tiny C Compiler
191 tcc$(EXESUF): tcc.o $(LIBTCC)
192 $(CC) -o $@ $^ $(LIBS) $(LDFLAGS) $(LINK_LIBTCC)
194 # Cross Tiny C Compilers
195 %-tcc$(EXESUF): FORCE
196 @$(MAKE) --no-print-directory $@ CROSS_TARGET=$* ONE_SOURCE=$(or $(ONE_SOURCE),yes)
198 $(CROSS_TARGET)-tcc$(EXESUF): $(TCC_FILES)
199 $(CC) -o $@ $^ $(LIBS) $(LDFLAGS)
201 # profiling version
202 tcc_p$(EXESUF): $($T_FILES)
203 $(CC) -o $@ $< $(DEFINES) -DONE_SOURCE $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P)
205 # static libtcc library
206 libtcc.a: $(LIBTCC_OBJ)
207 $(AR) rcs $@ $^
209 # dynamic libtcc library
210 libtcc.so: $(LIBTCC_OBJ)
211 $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDFLAGS)
213 libtcc.so: CFLAGS+=-fPIC
214 libtcc.so: LDFLAGS+=-fPIC
216 # windows dynamic libtcc library
217 libtcc.dll : $(LIBTCC_OBJ)
218 $(CC) -shared -o $@ $^ $(LDFLAGS)
220 libtcc.def : libtcc.dll tcc$(EXESUF)
221 ./tcc$(EXESUF) -impdef $< -o $@
223 libtcc.dll : DEFINES += -DLIBTCC_AS_DLL
225 # TinyCC runtime libraries
226 libtcc1.a : tcc$(EXESUF) FORCE
227 @$(MAKE) -C lib DEFINES="$(DEF-$T)"
229 # Cross libtcc1.a
230 libtcc1-%.a : %-tcc$(EXESUF) FORCE
231 @$(MAKE) -C lib DEFINES="$(DEF-$*)" CROSS_TARGET=$*
233 .PRECIOUS: libtcc1-%.a
234 FORCE:
236 # --------------------------------------------------------------------------
237 # documentation and man page
238 tcc-doc.html: tcc-doc.texi
239 -makeinfo --no-split --html --number-sections -o $@ $<
241 tcc.1: tcc-doc.texi
242 -$(TOPSRC)/texi2pod.pl $< tcc.pod
243 -pod2man --section=1 --center="Tiny C Compiler" --release="$(VERSION)" tcc.pod > $@
245 tcc-doc.info: tcc-doc.texi
246 -makeinfo $<
248 # --------------------------------------------------------------------------
249 # install
251 INSTALL = install -m644
252 INSTALLBIN = install -m755 $(STRIP_$(CONFIG_strip))
253 STRIP_yes = -s
254 install-strip: install
255 install-strip: CONFIG_strip = yes
257 TRY-INSTALL = $(if $(wildcard $1),mkdir -p $2 && $(INSTALL) $1 $2)
258 LIBTCC1_W = $(wildcard $(filter %-win32.a %-wince.a,$(LIBTCC1_CROSS)))
259 LIBTCC1_U = $(wildcard $(filter-out $(LIBTCC1_W),$(LIBTCC1_CROSS)))
260 PROGS_X = $(wildcard $(PROGS_CROSS))
262 # install progs & libs
263 install-unx:
264 mkdir -p "$(bindir)"
265 $(INSTALLBIN) $(PROGS) $(PROGS_X) "$(bindir)"
266 mkdir -p "$(tccdir)"
267 $(INSTALL) $(LIBTCC1) $(LIBTCC1_U) "$(tccdir)"
268 mkdir -p "$(tccdir)/include"
269 $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/include"
270 mkdir -p "$(libdir)"
271 $(INSTALL) $(LIBTCC) "$(libdir)"
272 mkdir -p "$(includedir)"
273 $(INSTALL) $(TOPSRC)/libtcc.h "$(includedir)"
274 $(call TRY-INSTALL,tcc.1,"$(mandir)/man1")
275 $(call TRY-INSTALL,tcc-doc.info,"$(infodir)")
276 $(call TRY-INSTALL,tcc-doc.html,"$(docdir)")
277 ifneq "$(LIBTCC1_W)" ""
278 mkdir -p "$(tccdir)/win32/lib"
279 $(INSTALL) $(TOPSRC)/win32/lib/*.def $(LIBTCC1_W) "$(tccdir)/win32/lib"
280 mkdir -p "$(tccdir)/win32/include"
281 cp -r $(TOPSRC)/win32/include/. "$(tccdir)/win32/include"
282 $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/win32/include"
283 endif
285 # uninstall
286 uninstall-unx:
287 @rm -fv $(foreach P,$(PROGS) $(PROGS_CROSS),"$(bindir)/$P")
288 @rm -fv "$(libdir)/libtcc.a" "$(libdir)/libtcc.so" "$(includedir)/libtcc.h"
289 @rm -fv "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
290 @rm -fv "$(docdir)/tcc-doc.html"
291 rm -r "$(tccdir)"
293 # install progs & libs on windows
294 install-win:
295 mkdir -p "$(tccdir)"
296 $(INSTALL) $(PROGS) $(subst libtcc.a,,$(LIBTCC)) $(PROGS_X) "$(tccdir)"
297 mkdir -p "$(tccdir)/lib"
298 $(INSTALL) $(TOPSRC)/win32/lib/*.def "$(tccdir)/lib"
299 $(INSTALL) libtcc1.a $(LIBTCC1_W) "$(tccdir)/lib"
300 mkdir -p "$(tccdir)/include"
301 cp -r $(TOPSRC)/win32/include/. "$(tccdir)/include"
302 $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/include"
303 mkdir -p "$(tccdir)/examples"
304 cp -r $(TOPSRC)/win32/examples/. "$(tccdir)/examples"
305 $(INSTALL) $(TOPSRC)/tests/libtcc_test.c "$(tccdir)/examples"
306 mkdir -p "$(tccdir)/libtcc"
307 $(INSTALL) $(TOPSRC)/libtcc.h $(subst .dll,.def,$(LIBTCC)) "$(tccdir)/libtcc"
308 mkdir -p "$(tccdir)/doc"
309 $(INSTALL) $(TOPSRC)/win32/tcc-win32.txt $(wildcard tcc-doc.html) "$(tccdir)/doc"
310 ifneq "$(LIBTCC1_U)" ""
311 $(INSTALL) $(LIBTCC1_U) "$(tccdir)/lib"
312 mkdir -p "$(tccdir)/lib/include";
313 $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/lib/include"
314 endif
316 # the msys-git shell works to configure && make except it does not have install
317 install-win : INSTALL = cp
319 # uninstall on windows
320 uninstall-win:
321 rm -r "$(tccdir)/"*
323 # --------------------------------------------------------------------------
324 # other stuff
326 TAGFILES = *.[ch] include/*.h lib/*.[chS]
327 tags : ; ctags $(TAGFILES)
328 # cannot have both tags and TAGS on windows
329 ETAGS : ; etags $(TAGFILES)
331 # create release tarball from *current* git branch (including tcc-doc.html
332 # and converting two files to CRLF)
333 TCC-VERSION = tcc-$(VERSION)
334 tar: tcc-doc.html
335 mkdir $(TCC-VERSION)
336 ( cd $(TCC-VERSION) && git --git-dir ../.git checkout -f )
337 cp tcc-doc.html $(TCC-VERSION)
338 for f in tcc-win32.txt build-tcc.bat ; do \
339 cat win32/$$f | sed 's,\(.*\),\1\r,g' > $(TCC-VERSION)/win32/$$f ; \
340 done
341 tar cjf $(TCC-VERSION).tar.bz2 $(TCC-VERSION)
342 rm -rf $(TCC-VERSION)
343 git reset
345 config.mak:
346 $(if $(wildcard $@),,@echo "Please run ./configure." && exit 1)
348 # in tests subdir
349 test:
350 $(MAKE) -C tests
352 clean:
353 rm -f $(PROGS) $(PROGS_CROSS) tcc_p$(EXESUF) tcc.pod
354 rm -f *~ *.o *.a *.so* *.out *.log lib*.def *.exe *.dll a.out tags TAGS
355 @$(MAKE) -C tests $@
356 @$(MAKE) -C lib $@
358 distclean: clean
359 rm -f config.h config.mak config.texi tcc.1 tcc-doc.info tcc-doc.html
361 .PHONY: all clean test tar tags ETAGS distclean install uninstall FORCE
363 help:
364 @echo "make"
365 @echo " build native compiler (from separate objects)"
366 @echo ""
367 @echo "make cross"
368 @echo " build cross compilers (from one source)"
369 @echo ""
370 @echo "make ONE_SOURCE=yes / no"
371 @echo " force building from one source / separate objects"
372 @echo ""
373 @echo "make cross-TARGET"
374 @echo " build one specific cross compiler for 'TARGET', as in"
375 @echo " $(TCC_X)"
376 @echo ""
377 @echo "Cross compiler configuration:"
378 @echo " make will read custom configuration for cross compilers from a file"
379 @echo " 'config-cross.mak' if present. For example for a windows->i386-linux"
380 @echo " cross-compiler that expects the linux files in <tccdir>/i386-linux:"
381 @echo ""
382 @echo " ROOT-i386 = {B}/i386-linux"
383 @echo " CRT-i386 = {B}/i386-linux/usr/lib"
384 @echo " LIB-i386 = {B}/i386-linux/lib:{B}/i386-linux/usr/lib"
385 @echo " INC-i386 = {B}/lib/include:{B}/i386-linux/usr/include"
386 @echo " DEF-i386 += -D__linux__"
387 @echo ""
388 @echo "Other supported make targets:"
389 @echo " install install-strip test tags ETAGS tar clean distclean help"
391 # --------------------------------------------------------------------------
392 endif # ($(INCLUDED),no)