gen_addrpc32: absolute ptr needs *ABS* relocation
[tinycc.git] / Makefile
blob3a5c000428e2c4d53b202b179b0b109c07eeeb6f
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 configuration (see make help)
155 -include config-extra.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 tcc.o : DEFINES += -DONE_SOURCE=0
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 $(TCC_FILES) : DEFINES += -DONE_SOURCE=0
182 endif
184 # target specific object rule
185 $(X)%.o : %.c $(LIBTCC_INC)
186 $(CC) -o $@ -c $< $(DEFINES) $(CFLAGS)
188 # additional dependencies
189 $(X)tcc.o : tcctools.c
191 # Host Tiny C Compiler
192 tcc$(EXESUF): tcc.o $(LIBTCC)
193 $(CC) -o $@ $^ $(LIBS) $(LDFLAGS) $(LINK_LIBTCC)
195 # Cross Tiny C Compilers
196 %-tcc$(EXESUF): FORCE
197 @$(MAKE) --no-print-directory $@ CROSS_TARGET=$* ONE_SOURCE=$(or $(ONE_SOURCE),yes)
199 $(CROSS_TARGET)-tcc$(EXESUF): $(TCC_FILES)
200 $(CC) -o $@ $^ $(LIBS) $(LDFLAGS)
202 # profiling version
203 tcc_p$(EXESUF): $($T_FILES)
204 $(CC) -o $@ $< $(DEFINES) $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P)
206 # static libtcc library
207 libtcc.a: $(LIBTCC_OBJ)
208 $(AR) rcs $@ $^
210 # dynamic libtcc library
211 libtcc.so: $(LIBTCC_OBJ)
212 $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDFLAGS)
214 libtcc.so: CFLAGS+=-fPIC
215 libtcc.so: LDFLAGS+=-fPIC
217 # windows dynamic libtcc library
218 libtcc.dll : $(LIBTCC_OBJ)
219 $(CC) -shared -o $@ $^ $(LDFLAGS)
221 libtcc.def : libtcc.dll tcc$(EXESUF)
222 ./tcc$(EXESUF) -impdef $< -o $@
224 libtcc.dll : DEFINES += -DLIBTCC_AS_DLL
226 # TinyCC runtime libraries
227 libtcc1.a : tcc$(EXESUF) FORCE
228 @$(MAKE) -C lib DEFINES="$(DEF-$T)"
230 # Cross libtcc1.a
231 libtcc1-%.a : %-tcc$(EXESUF) FORCE
232 @$(MAKE) -C lib DEFINES="$(DEF-$*)" CROSS_TARGET=$*
234 .PRECIOUS: libtcc1-%.a
235 FORCE:
237 # --------------------------------------------------------------------------
238 # documentation and man page
239 tcc-doc.html: tcc-doc.texi
240 -makeinfo --no-split --html --number-sections -o $@ $<
242 tcc.1: tcc-doc.texi
243 -$(TOPSRC)/texi2pod.pl $< tcc.pod
244 -pod2man --section=1 --center="Tiny C Compiler" --release="$(VERSION)" tcc.pod > $@
246 tcc-doc.info: tcc-doc.texi
247 -makeinfo $<
249 # --------------------------------------------------------------------------
250 # install
252 INSTALL = install -m644
253 INSTALLBIN = install -m755 $(STRIP_$(CONFIG_strip))
254 STRIP_yes = -s
255 install-strip: install
256 install-strip: CONFIG_strip = yes
258 TRY-INSTALL = $(if $(wildcard $1),mkdir -p $2 && $(INSTALL) $1 $2)
259 LIBTCC1_W = $(wildcard $(filter %-win32.a %-wince.a,$(LIBTCC1_CROSS)))
260 LIBTCC1_U = $(wildcard $(filter-out $(LIBTCC1_W),$(LIBTCC1_CROSS)))
261 PROGS_X = $(wildcard $(PROGS_CROSS))
263 # install progs & libs
264 install-unx:
265 mkdir -p "$(bindir)"
266 $(INSTALLBIN) $(PROGS) $(PROGS_X) "$(bindir)"
267 mkdir -p "$(tccdir)"
268 $(INSTALL) $(LIBTCC1) $(LIBTCC1_U) "$(tccdir)"
269 mkdir -p "$(tccdir)/include"
270 $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/include"
271 mkdir -p "$(libdir)"
272 $(INSTALL) $(LIBTCC) "$(libdir)"
273 mkdir -p "$(includedir)"
274 $(INSTALL) $(TOPSRC)/libtcc.h "$(includedir)"
275 $(call TRY-INSTALL,tcc.1,"$(mandir)/man1")
276 $(call TRY-INSTALL,tcc-doc.info,"$(infodir)")
277 $(call TRY-INSTALL,tcc-doc.html,"$(docdir)")
278 ifneq "$(LIBTCC1_W)" ""
279 mkdir -p "$(tccdir)/win32/lib"
280 $(INSTALL) $(TOPSRC)/win32/lib/*.def $(LIBTCC1_W) "$(tccdir)/win32/lib"
281 mkdir -p "$(tccdir)/win32/include"
282 cp -r $(TOPSRC)/win32/include/. "$(tccdir)/win32/include"
283 $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/win32/include"
284 endif
286 # uninstall
287 uninstall-unx:
288 @rm -fv $(foreach P,$(PROGS) $(PROGS_CROSS),"$(bindir)/$P")
289 @rm -fv "$(libdir)/libtcc.a" "$(libdir)/libtcc.so" "$(includedir)/libtcc.h"
290 @rm -fv "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
291 @rm -fv "$(docdir)/tcc-doc.html"
292 rm -r "$(tccdir)"
294 # install progs & libs on windows
295 install-win:
296 mkdir -p "$(tccdir)"
297 $(INSTALL) $(PROGS) $(subst libtcc.a,,$(LIBTCC)) $(PROGS_X) "$(tccdir)"
298 mkdir -p "$(tccdir)/lib"
299 $(INSTALL) $(TOPSRC)/win32/lib/*.def "$(tccdir)/lib"
300 $(INSTALL) libtcc1.a $(LIBTCC1_W) "$(tccdir)/lib"
301 mkdir -p "$(tccdir)/include"
302 cp -r $(TOPSRC)/win32/include/. "$(tccdir)/include"
303 $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/include"
304 mkdir -p "$(tccdir)/examples"
305 cp -r $(TOPSRC)/win32/examples/. "$(tccdir)/examples"
306 $(INSTALL) $(TOPSRC)/tests/libtcc_test.c "$(tccdir)/examples"
307 mkdir -p "$(tccdir)/libtcc"
308 $(INSTALL) $(TOPSRC)/libtcc.h $(subst .dll,.def,$(LIBTCC)) "$(tccdir)/libtcc"
309 mkdir -p "$(tccdir)/doc"
310 $(INSTALL) $(TOPSRC)/win32/tcc-win32.txt $(wildcard tcc-doc.html) "$(tccdir)/doc"
311 ifneq "$(LIBTCC1_U)" ""
312 $(INSTALL) $(LIBTCC1_U) "$(tccdir)/lib"
313 mkdir -p "$(tccdir)/lib/include";
314 $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/lib/include"
315 endif
317 # the msys-git shell works to configure && make except it does not have install
318 install-win : INSTALL = cp
320 # uninstall on windows
321 uninstall-win:
322 rm -r "$(tccdir)"
324 # --------------------------------------------------------------------------
325 # other stuff
327 TAGFILES = *.[ch] include/*.h lib/*.[chS]
328 tags : ; ctags $(TAGFILES)
329 # cannot have both tags and TAGS on windows
330 ETAGS : ; etags $(TAGFILES)
332 # create release tarball from *current* git branch (including tcc-doc.html
333 # and converting two files to CRLF)
334 TCC-VERSION = tcc-$(VERSION)
335 tar: tcc-doc.html
336 mkdir $(TCC-VERSION)
337 ( cd $(TCC-VERSION) && git --git-dir ../.git checkout -f )
338 cp tcc-doc.html $(TCC-VERSION)
339 for f in tcc-win32.txt build-tcc.bat ; do \
340 cat win32/$$f | sed 's,\(.*\),\1\r,g' > $(TCC-VERSION)/win32/$$f ; \
341 done
342 tar cjf $(TCC-VERSION).tar.bz2 $(TCC-VERSION)
343 rm -rf $(TCC-VERSION)
344 git reset
346 config.mak:
347 $(if $(wildcard $@),,@echo "Please run ./configure." && exit 1)
349 # run all tests
350 test:
351 $(MAKE) -C tests
352 # run test(s) from tests2 subdir (see make help)
353 tests2.%:
354 $(MAKE) -C tests/tests2 $@
356 clean:
357 rm -f $(PROGS) $(PROGS_CROSS) tcc_p$(EXESUF) tcc.pod
358 rm -f *~ *.o *.a *.so* *.out *.log lib*.def *.exe *.dll a.out tags TAGS
359 @$(MAKE) -C tests $@
360 @$(MAKE) -C lib $@
362 distclean: clean
363 rm -f config.h config.mak config.texi tcc.1 tcc-doc.info tcc-doc.html
365 .PHONY: all clean test tar tags ETAGS distclean install uninstall FORCE
367 help:
368 @echo "make"
369 @echo " build native compiler (from separate objects)"
370 @echo ""
371 @echo "make cross"
372 @echo " build cross compilers (from one source)"
373 @echo ""
374 @echo "make ONE_SOURCE=yes / no"
375 @echo " force building from one source / separate objects"
376 @echo ""
377 @echo "make cross-TARGET"
378 @echo " build one specific cross compiler for 'TARGET', as in"
379 @echo " $(TCC_X)"
380 @echo ""
381 @echo "Custom configuration:"
382 @echo " The makefile includes a file 'config-extra.mak' if it is present."
383 @echo " This file may contain some custom configuration. For example:"
384 @echo ""
385 @echo " NATIVE_DEFINES += -D..."
386 @echo ""
387 @echo " Or for example to configure the search paths for a cross-compiler"
388 @echo " that expects the linux files in <tccdir>/i386-linux:"
389 @echo ""
390 @echo " ROOT-i386 = {B}/i386-linux"
391 @echo " CRT-i386 = {B}/i386-linux/usr/lib"
392 @echo " LIB-i386 = {B}/i386-linux/lib:{B}/i386-linux/usr/lib"
393 @echo " INC-i386 = {B}/lib/include:{B}/i386-linux/usr/include"
394 @echo " DEF-i386 += -D__linux__"
395 @echo ""
396 @echo "make test"
397 @echo " run all tests"
398 @echo ""
399 @echo "make tests2.all / make tests2.37 / make tests2.37+"
400 @echo " run all/single test(s) from tests2, optionally update .expect"
401 @echo ""
402 @echo "Other supported make targets:"
403 @echo " install install-strip tags ETAGS tar clean distclean help"
404 @echo ""
406 # --------------------------------------------------------------------------
407 endif # ($(INCLUDED),no)