Remove a bit-field TODO
[tinycc.git] / Makefile
blob28193a5d93f7779d860ff98abeb655813ac3abcd
1 # --------------------------------------------------------------------------
3 # Tiny C Compiler Makefile
6 ifndef TOP
7 TOP = .
8 INCLUDED = no
9 endif
11 include $(TOP)/config.mak
13 ifeq (-$(findstring gcc,$(CC))-,-gcc-)
14 ifeq (-$(GCC_MAJOR)-$(findstring $(GCC_MINOR),56789)-,-4--)
15 CFLAGS += -D_FORTIFY_SOURCE=0
16 endif
17 else
18 ifeq (-$(findstring clang,$(CC))-,-clang-)
19 # make clang accept gnuisms in libtcc1.c
20 CFLAGS+=-fheinous-gnu-extensions
21 endif
22 endif
24 LIBTCC = libtcc.a
25 LIBTCC1 = libtcc1.a
26 LINK_LIBTCC =
27 LIBS =
28 CFLAGS += -I$(TOP)
29 CFLAGS += $(CPPFLAGS)
30 VPATH = $(TOPSRC)
32 ifdef CONFIG_WIN32
33 ifneq ($(DISABLE_STATIC),no)
34 LIBTCC = libtcc$(DLLSUF)
35 LIBTCCDEF = libtcc.def
36 endif
37 CFGWIN = -win
38 NATIVE_TARGET = $(ARCH)-win$(if $(findstring arm,$(ARCH)),ce,32)
39 else
40 LIBS=-lm
41 ifndef CONFIG_NOLDL
42 LIBS+=-ldl
43 endif
44 # make libtcc as static or dynamic library?
45 ifeq ($(DISABLE_STATIC),yes)
46 LIBTCC=libtcc$(DLLSUF)
47 export LD_LIBRARY_PATH := $(CURDIR)/$(TOP)
48 ifndef DISABLE_RPATH
49 LINK_LIBTCC += -Wl,-rpath,"$(libdir)"
50 endif
51 endif
52 CFGWIN =-unx
53 NATIVE_TARGET = $(ARCH)
54 ifdef CONFIG_OSX
55 NATIVE_TARGET = $(ARCH)-osx
56 LDFLAGS += -flat_namespace -undefined warning
57 export MACOSX_DEPLOYMENT_TARGET := 10.2
58 endif
59 endif
61 # run local version of tcc with local libraries and includes
62 TCCFLAGS-unx = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP)
63 TCCFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP)
64 TCCFLAGS = $(TCCFLAGS$(CFGWIN))
65 TCC = $(TOP)/tcc$(EXESUF) $(TCCFLAGS)
66 ifdef CONFIG_OSX
67 TCCFLAGS += -D_ANSI_SOURCE
68 endif
70 CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC -DTCC_PROFILE
71 LIBS_P = $(LIBS)
72 LDFLAGS_P = $(LDFLAGS)
74 CONFIG_$(ARCH) = yes
75 NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
76 NATIVE_DEFINES_$(CONFIG_x86_64) += -DTCC_TARGET_X86_64
77 NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE
78 NATIVE_DEFINES_$(CONFIG_OSX) += -DTCC_TARGET_MACHO
79 NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC
80 NATIVE_DEFINES_$(CONFIG_musl) += -DTCC_MUSL
81 NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM
82 NATIVE_DEFINES_$(CONFIG_arm_eabihf) += -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT
83 NATIVE_DEFINES_$(CONFIG_arm_eabi) += -DTCC_ARM_EABI
84 NATIVE_DEFINES_$(CONFIG_arm_vfp) += -DTCC_ARM_VFP
85 NATIVE_DEFINES_$(CONFIG_arm64) += -DTCC_TARGET_ARM64
86 NATIVE_DEFINES += $(NATIVE_DEFINES_yes)
88 ifeq ($(INCLUDED),no)
89 # --------------------------------------------------------------------------
90 # running top Makefile
92 PROGS = tcc$(EXESUF)
93 TCCLIBS = $(LIBTCC1) $(LIBTCC) $(LIBTCCDEF)
94 TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info
96 all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
98 # cross compiler targets to build
99 TCC_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince c67
100 # TCC_X += arm-fpa arm-fpa-ld arm-vfp arm-eabi
102 # cross libtcc1.a targets to build
103 LIBTCC1_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince
105 PROGS_CROSS = $(foreach X,$(TCC_X),$X-tcc$(EXESUF))
106 LIBTCC1_CROSS = $(foreach X,$(LIBTCC1_X),libtcc1-$X.a)
108 # build cross compilers & libs
109 cross: $(LIBTCC1_CROSS) $(PROGS_CROSS)
111 # build specific cross compiler & lib
112 cross-%: %-tcc$(EXESUF) libtcc1-%.a ;
114 install: install$(CFGWIN)
115 uninstall: uninstall$(CFGWIN)
117 ifdef CONFIG_CROSS
118 all : cross
119 endif
121 # --------------------------------------------
123 T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown)
124 X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-)
126 DEF-i386 = -DTCC_TARGET_I386
127 DEF-x86_64 = -DTCC_TARGET_X86_64
128 DEF-i386-win32 = -DTCC_TARGET_PE -DTCC_TARGET_I386
129 DEF-x86_64-win32= -DTCC_TARGET_PE -DTCC_TARGET_X86_64
130 DEF-x86_64-osx = -DTCC_TARGET_MACHO -DTCC_TARGET_X86_64
131 DEF-arm-wince = -DTCC_TARGET_PE -DTCC_TARGET_ARM -DTCC_ARM_EABI -DTCC_ARM_VFP -DTCC_ARM_HARDFLOAT
132 DEF-arm64 = -DTCC_TARGET_ARM64
133 DEF-c67 = -DTCC_TARGET_C67 -w # disable warnigs
134 DEF-arm-fpa = -DTCC_TARGET_ARM
135 DEF-arm-fpa-ld = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
136 DEF-arm-vfp = -DTCC_TARGET_ARM -DTCC_ARM_VFP
137 DEF-arm-eabi = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DTCC_ARM_EABI
138 DEF-arm-eabihf = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT
139 DEF-arm = $(DEF-arm-eabihf)
140 DEF-$(NATIVE_TARGET) = $(NATIVE_DEFINES)
142 DEFINES += $(DEF-$T) $(DEF-all)
143 DEFINES += $(if $(ROOT-$T),-DCONFIG_SYSROOT="\"$(ROOT-$T)\"")
144 DEFINES += $(if $(CRT-$T),-DCONFIG_TCC_CRTPREFIX="\"$(CRT-$T)\"")
145 DEFINES += $(if $(LIB-$T),-DCONFIG_TCC_LIBPATHS="\"$(LIB-$T)\"")
146 DEFINES += $(if $(INC-$T),-DCONFIG_TCC_SYSINCLUDEPATHS="\"$(INC-$T)\"")
147 DEFINES += $(DEF-$(or $(findstring win,$T),unx))
149 ifneq ($(X),)
150 ifeq ($(CONFIG_WIN32),yes)
151 DEF-win += -DTCC_LIBTCC1="\"libtcc1-$T.a\""
152 DEF-unx += -DTCC_LIBTCC1="\"lib/libtcc1-$T.a\""
153 else
154 DEF-all += -DTCC_LIBTCC1="\"libtcc1-$T.a\""
155 DEF-win += -DCONFIG_TCCDIR="\"$(tccdir)/win32\""
156 endif
157 endif
159 # include custom cross-compiler configuration (see make help)
160 -include config-cross.mak
162 CORE_FILES = tcc.c tcctools.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
163 CORE_FILES += tcc.h config.h libtcc.h tcctok.h
164 i386_FILES = $(CORE_FILES) i386-gen.c i386-link.c i386-asm.c i386-asm.h i386-tok.h
165 i386-win32_FILES = $(i386_FILES) tccpe.c
166 x86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h
167 x86_64-win32_FILES = $(x86_64_FILES) tccpe.c
168 x86_64-osx_FILES = $(x86_64_FILES)
169 arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c
170 arm-wince_FILES = $(arm_FILES) tccpe.c
171 arm64_FILES = $(CORE_FILES) arm64-gen.c arm64-link.c
172 c67_FILES = $(CORE_FILES) c67-gen.c c67-link.c tcccoff.c
174 # libtcc sources
175 LIBTCC_SRC = $(filter-out tcc.c tcctools.c arm-asm.c,$(filter %.c,$($T_FILES)))
177 ifeq ($(ONE_SOURCE),yes)
178 LIBTCC_OBJ = $(X)libtcc.o
179 LIBTCC_INC = $($T_FILES)
180 TCC_FILES = tcc.c
181 $(X)libtcc.o $T-tcc$(EXESUF) : DEFINES += -DONE_SOURCE
182 else
183 LIBTCC_OBJ = $(patsubst %.c,$(X)%.o,$(LIBTCC_SRC))
184 LIBTCC_INC = $(filter %.h %-gen.c %-link.c,$($T_FILES))
185 TCC_FILES = $(X)tcc.o $(LIBTCC_OBJ)
186 endif
188 # target specific object rule
189 $(X)%.o : %.c $(LIBTCC_INC)
190 $(CC) -o $@ -c $< $(DEFINES) $(CFLAGS)
192 # additional dependencies
193 $(X)tcc.o : tcctools.c
194 $(X)arm-gen.o : arm-asm.c
196 # Host Tiny C Compiler
197 tcc$(EXESUF): tcc.o $(LIBTCC)
198 $(CC) -o $@ $^ $(DEFINES) $(CFLAGS) $(LIBS) $(LDFLAGS) $(LINK_LIBTCC)
200 # Cross Tiny C Compilers
201 %-tcc$(EXESUF): FORCE
202 @$(MAKE) --no-print-directory $@ CROSS_TARGET=$* ONE_SOURCE=$(or $(ONE_SOURCE),yes)
204 $(CROSS_TARGET)-tcc$(EXESUF): $(TCC_FILES)
205 $(CC) -o $@ $^ $(DEFINES) $(CFLAGS) $(LIBS) $(LDFLAGS)
207 # profiling version
208 tcc_p$(EXESUF): $($T_FILES)
209 $(CC) -o $@ $< $(DEFINES) -DONE_SOURCE $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P)
211 # static libtcc library
212 libtcc.a: $(LIBTCC_OBJ)
213 $(AR) rcs $@ $^
215 # dynamic libtcc library
216 libtcc.so: $(LIBTCC_OBJ)
217 $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(CFLAGS) $(LDFLAGS)
219 libtcc.so: CFLAGS+=-fPIC
221 # windows dynamic libtcc library
222 libtcc.dll : $(LIBTCC_OBJ)
223 $(CC) -shared -o $@ $^ $(CFLAGS) $(LDFLAGS)
225 libtcc.def : libtcc.dll tcc$(EXESUF)
226 ./tcc$(EXESUF) -impdef $< -o $@
228 libtcc.dll : DEFINES += -DLIBTCC_AS_DLL
230 # TinyCC runtime libraries
231 libtcc1.a : tcc$(EXESUF) FORCE
232 @$(MAKE) -C lib
234 # Cross libtcc1.a
235 libtcc1-%.a : %-tcc$(EXESUF) FORCE
236 @$(MAKE) -C lib CROSS_TARGET=$*
238 FORCE:
240 # --------------------------------------------------------------------------
241 # documentation and man page
242 tcc-doc.html: tcc-doc.texi
243 -makeinfo --no-split --html --number-sections -o $@ $<
245 tcc.1: tcc-doc.texi
246 -$(TOPSRC)/texi2pod.pl $< tcc.pod
247 -pod2man --section=1 --center="Tiny C Compiler" --release="$(VERSION)" tcc.pod > $@
249 tcc-doc.info: tcc-doc.texi
250 -makeinfo $<
252 # --------------------------------------------------------------------------
253 # install
255 INSTALL = install -m644
256 INSTALLBIN = install -m755 $(STRIP_$(STRIP_BINARIES))
257 STRIP_yes = -s
258 install-strip: install
259 install-strip: STRIP_BINARIES = yes
261 TRY-INSTALL = $(if $(wildcard $1),mkdir -p $2 && $(INSTALL) $1 $2)
262 LIBTCC1_W = $(wildcard $(filter %-win32.a %-wince.a,$(LIBTCC1_CROSS)))
263 LIBTCC1_U = $(wildcard $(filter-out $(LIBTCC1_W),$(LIBTCC1_CROSS)))
264 PROGS_X = $(wildcard $(PROGS_CROSS))
266 # install progs & libs
267 install-unx:
268 mkdir -p "$(bindir)"
269 $(INSTALLBIN) $(PROGS) $(PROGS_X) "$(bindir)"
270 mkdir -p "$(tccdir)"
271 $(INSTALL) $(LIBTCC1) $(LIBTCC1_U) "$(tccdir)"
272 mkdir -p "$(tccdir)/include"
273 $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/include"
274 mkdir -p "$(libdir)"
275 $(INSTALL) $(LIBTCC) "$(libdir)"
276 mkdir -p "$(includedir)"
277 $(INSTALL) $(TOPSRC)/libtcc.h "$(includedir)"
278 $(call TRY-INSTALL,tcc.1,"$(mandir)/man1")
279 $(call TRY-INSTALL,tcc-doc.info,"$(infodir)")
280 $(call TRY-INSTALL,tcc-doc.html,"$(docdir)")
281 ifneq "$(LIBTCC1_W)" ""
282 mkdir -p "$(tccdir)/win32/lib"
283 $(INSTALL) $(TOPSRC)/win32/lib/*.def $(LIBTCC1_W) "$(tccdir)/win32/lib"
284 mkdir -p "$(tccdir)/win32/include"
285 cp -r $(TOPSRC)/win32/include/. "$(tccdir)/win32/include"
286 $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/win32/include"
287 endif
289 # uninstall
290 uninstall-unx:
291 @rm -fv $(foreach P,$(PROGS) $(PROGS_CROSS),"$(bindir)/$P")
292 @rm -fv "$(libdir)/libtcc.a" "$(libdir)/libtcc.so" "$(includedir)/libtcc.h"
293 @rm -fv "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
294 @rm -fv "$(docdir)/tcc-doc.html"
295 rm -r "$(tccdir)"
297 # install progs & libs on windows
298 install-win:
299 mkdir -p "$(tccdir)"
300 $(INSTALL) $(PROGS) $(subst libtcc.a,,$(LIBTCC)) $(PROGS_X) "$(tccdir)"
301 mkdir -p "$(tccdir)/lib"
302 $(INSTALL) $(TOPSRC)/win32/lib/*.def "$(tccdir)/lib"
303 $(INSTALL) libtcc1.a $(LIBTCC1_W) "$(tccdir)/lib"
304 mkdir -p "$(tccdir)/include"
305 cp -r $(TOPSRC)/win32/include/. "$(tccdir)/include"
306 $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/include"
307 mkdir -p "$(tccdir)/examples"
308 cp -r $(TOPSRC)/win32/examples/. "$(tccdir)/examples"
309 $(INSTALL) $(TOPSRC)/tests/libtcc_test.c "$(tccdir)/examples"
310 mkdir -p "$(tccdir)/libtcc"
311 $(INSTALL) $(TOPSRC)/libtcc.h $(subst .dll,.def,$(LIBTCC)) "$(tccdir)/libtcc"
312 mkdir -p "$(tccdir)/doc"
313 $(INSTALL) $(TOPSRC)/win32/tcc-win32.txt $(wildcard tcc-doc.html) "$(tccdir)/doc"
314 ifneq "$(LIBTCC1_U)" ""
315 $(INSTALL) $(LIBTCC1_U) "$(tccdir)/lib"
316 mkdir -p "$(tccdir)/lib/include";
317 $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/lib/include"
318 endif
320 # the msys-git shell works to configure && make except it does not have install
321 install-win : INSTALL = cp
323 # uninstall on windows
324 uninstall-win:
325 rm -r "$(tccdir)/"*
327 # --------------------------------------------------------------------------
328 # other stuff
330 TAGFILES = *.[ch] include/*.h lib/*.[chS]
331 tags : ; ctags $(TAGFILES)
332 # cannot have both tags and TAGS on windows
333 ETAGS : ; etags $(TAGFILES)
335 # create release tarball from *current* git branch (including tcc-doc.html
336 # and converting two files to CRLF)
337 TCC-VERSION = tcc-$(VERSION)
338 tar: tcc-doc.html
339 mkdir $(TCC-VERSION)
340 ( cd $(TCC-VERSION) && git --git-dir ../.git checkout -f )
341 cp tcc-doc.html $(TCC-VERSION)
342 for f in tcc-win32.txt build-tcc.bat ; do \
343 cat win32/$$f | sed 's,\(.*\),\1\r,g' > $(TCC-VERSION)/win32/$$f ; \
344 done
345 tar cjf $(TCC-VERSION).tar.bz2 $(TCC-VERSION)
346 rm -rf $(TCC-VERSION)
347 git reset
349 config.mak:
350 $(if $(wildcard $@),,@echo "Please run ./configure." && exit 1)
352 # in tests subdir
353 test:
354 $(MAKE) -C tests
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 "Cross compiler configuration:"
382 @echo " make will read custom configuration for cross compilers from a file"
383 @echo " 'config-cross.mak' if present. For example for a windows->i386-linux"
384 @echo " cross-compiler that expects the linux files in <tccdir>/i386-linux:"
385 @echo ""
386 @echo " ROOT-i386 = {B}/i386-linux"
387 @echo " CRT-i386 = {B}/i386-linux/usr/lib"
388 @echo " LIB-i386 = {B}/i386-linux/lib:{B}/i386-linux/usr/lib"
389 @echo " INC-i386 = {B}/lib/include:{B}/i386-linux/usr/include"
390 @echo " DEF-i386 += -D__linux__"
391 @echo ""
392 @echo "Other supported make targets:"
393 @echo " install install-strip test tags ETAGS tar clean distclean help"
395 # --------------------------------------------------------------------------
396 endif # ($(INCLUDED),no)