Even on Darwin, tcc should display Linux
[tinycc.git] / Makefile
blob3be01b3634c0c0cd26457d00142f9214b38bebbf
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.dll
35 LIBTCCDEF = libtcc.def
36 endif
37 CFGWIN = -win
38 NATIVE_TARGET = $(ARCH)-$(if $(eq $(ARCH),arm),wince,win32)
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.so
47 ifndef DISABLE_RPATH
48 LINK_LIBTCC += -Wl,-rpath,"$(libdir)"
49 export LD_LIBRARY_PATH := $(CURDIR)/$(TOP)
50 endif
51 endif
52 CFGWIN =-unx
53 NATIVE_TARGET = $(ARCH)
54 endif
56 ifeq ($(TARGETOS),Darwin)
57 CFLAGS += -Wl,-flat_namespace,-undefined,warning
58 export MACOSX_DEPLOYMENT_TARGET:=10.2
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)
67 CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC -DTCC_PROFILE
68 LIBS_P= $(LIBS)
69 LDFLAGS_P = $(LDFLAGS)
71 CONFIG_$(ARCH) = yes
72 NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
73 NATIVE_DEFINES_$(CONFIG_x86_64) += -DTCC_TARGET_X86_64
74 NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE
75 NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC
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 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 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 ifdef CONFIG_CROSS
104 all : $(LIBTCC1_CROSS) $(PROGS_CROSS)
105 endif
107 # build cross compilers & libs
108 cross: all $(LIBTCC1_CROSS) $(PROGS_CROSS)
110 # build specific cross compiler & lib
111 cross-%: %-tcc$(EXESUF) libtcc1-%.a ;
113 install: install$(CFGWIN)
114 uninstall: uninstall$(CFGWIN)
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-arm-wince = -DTCC_TARGET_PE -DTCC_TARGET_ARM -DTCC_ARM_EABI -DTCC_ARM_VFP -DTCC_ARM_HARDFLOAT
126 DEF-arm64 = -DTCC_TARGET_ARM64
127 DEF-c67 = -DTCC_TARGET_C67 -w # disable warnigs
128 DEF-arm-fpa = -DTCC_TARGET_ARM
129 DEF-arm-fpa-ld = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
130 DEF-arm-vfp = -DTCC_TARGET_ARM -DTCC_ARM_VFP
131 DEF-arm-eabi = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DTCC_ARM_EABI
132 DEF-arm-eabihf = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT
133 DEF-arm = $(DEF-arm-eabihf)
134 DEF-$(NATIVE_TARGET) = $(NATIVE_DEFINES)
136 DEFINES += $(DEF-$T) $(DEF-all)
137 DEFINES += $(if $(ROOT-$T),-DCONFIG_SYSROOT="\"$(ROOT-$T)\"")
138 DEFINES += $(if $(CRT-$T),-DCONFIG_TCC_CRTPREFIX="\"$(CRT-$T)\"")
139 DEFINES += $(if $(LIB-$T),-DCONFIG_TCC_LIBPATHS="\"$(LIB-$T)\"")
140 DEFINES += $(if $(INC-$T),-DCONFIG_TCC_SYSINCLUDEPATHS="\"$(INC-$T)\"")
141 DEFINES += $(DEF-$(or $(findstring win,$T),unx))
143 ifneq ($(X),)
144 ifeq ($(CONFIG_WIN32),yes)
145 DEF-win += -DTCC_LIBTCC1="\"libtcc1-$T.a\""
146 DEF-unx += -DTCC_LIBTCC1="\"lib/libtcc1-$T.a\""
147 else
148 DEF-all += -DTCC_LIBTCC1="\"libtcc1-$T.a\""
149 DEF-win += -DCONFIG_TCCDIR="\"$(tccdir)/win32\""
150 endif
151 endif
153 # include custom cross-compiler configuration (see make help)
154 -include config-cross.mak
156 CORE_FILES = tcc.c tcctools.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
157 CORE_FILES += tcc.h config.h libtcc.h tcctok.h
158 i386_FILES = $(CORE_FILES) i386-gen.c i386-link.c i386-asm.c i386-asm.h i386-tok.h
159 i386-win32_FILES = $(i386_FILES) tccpe.c
160 x86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h
161 x86_64-win32_FILES = $(x86_64_FILES) tccpe.c
162 arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c
163 arm-wince_FILES = $(arm_FILES) tccpe.c
164 arm64_FILES = $(CORE_FILES) arm64-gen.c arm64-link.c
165 c67_FILES = $(CORE_FILES) c67-gen.c c67-link.c tcccoff.c
167 # libtcc sources
168 LIBTCC_SRC = $(filter-out tcc.c tcctools.c arm-asm.c,$(filter %.c,$($T_FILES)))
170 ifeq ($(ONE_SOURCE),yes)
171 LIBTCC_OBJ = $(X)libtcc.o
172 LIBTCC_INC = $($T_FILES)
173 TCC_FILES = tcc.c
174 $(X)libtcc.o $T-tcc$(EXESUF) : DEFINES += -DONE_SOURCE
175 else
176 LIBTCC_OBJ = $(patsubst %.c,$(X)%.o,$(LIBTCC_SRC))
177 LIBTCC_INC = $(filter %.h %-gen.c %-link.c,$($T_FILES))
178 TCC_FILES = $(X)tcc.o $(LIBTCC_OBJ)
179 endif
181 # target specific object rule
182 $(X)%.o : %.c $(LIBTCC_INC)
183 $(CC) -o $@ -c $< $(DEFINES) $(CFLAGS)
185 # additional dependencies
186 $(X)tcc.o : tcctools.c
187 $(X)arm-gen.o : arm-asm.c
189 # Host Tiny C Compiler
190 tcc$(EXESUF): $(X)tcc.o $(LIBTCC)
191 $(CC) -o $@ $^ $(DEFINES) $(CFLAGS) $(LIBS) $(LDFLAGS) $(LINK_LIBTCC)
193 # Cross Tiny C Compilers
194 %-tcc$(EXESUF): FORCE
195 @$(MAKE) --no-print-directory $@ CROSS_TARGET=$* ONE_SOURCE=$(or $(ONE_SOURCE),yes)
197 $(CROSS_TARGET)-tcc$(EXESUF): $(TCC_FILES)
198 $(CC) -o $@ $^ $(DEFINES) $(CFLAGS) $(LIBS) $(LDFLAGS)
200 # profiling version
201 tcc_p$(EXESUF): $($T_FILES)
202 $(CC) -o $@ $< -$(DEFINES) $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P)
204 # static libtcc library
205 libtcc.a: $(LIBTCC_OBJ)
206 $(AR) rcs $@ $^
208 # dynamic libtcc library
209 libtcc.so: $(LIBTCC_OBJ)
210 $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDFLAGS)
212 libtcc.so: CFLAGS+=-fPIC
214 # windows dynamic libtcc library
215 libtcc.dll : $(LIBTCC_OBJ)
216 $(CC) -shared $(LIBTCC_OBJ) -o $@ $(LDFLAGS)
218 libtcc.def : libtcc.dll tcc$(EXESUF)
219 ./tcc$(EXESUF) -impdef $< -o $@
221 libtcc.dll : DEFINES += -DLIBTCC_AS_DLL
223 # TinyCC runtime libraries
224 libtcc1.a : tcc$(EXESUF) FORCE
225 @$(MAKE) -f lib/Makefile BIN=$@ $@ TOP=. --no-print-directory
227 # Cross libtcc1.a
228 libtcc1-%.a : %-tcc$(EXESUF) FORCE
229 @$(MAKE) -f lib/Makefile BIN=$@ $@ CROSS_TARGET=$* TOP=. --no-print-directory
231 FORCE:
233 # --------------------------------------------------------------------------
234 # documentation and man page
235 tcc-doc.html: tcc-doc.texi
236 -makeinfo --no-split --html --number-sections -o $@ $<
238 tcc.1: tcc-doc.texi
239 -$(TOPSRC)/texi2pod.pl $< tcc.pod
240 -pod2man --section=1 --center="Tiny C Compiler" --release="$(VERSION)" tcc.pod > $@
242 tcc-doc.info: tcc-doc.texi
243 -makeinfo $<
245 # --------------------------------------------------------------------------
246 # install
248 INSTALL = install -m644
249 INSTALLBIN = install -m755 $(STRIP_$(STRIP_BINARIES))
250 STRIP_yes = -s
251 install-strip: install
252 install-strip: STRIP_BINARIES = yes
254 TRY-INSTALL = $(if $(wildcard $1),mkdir -p $2 && $(INSTALL) $1 $2)
255 LIBTCC1_W = $(wildcard $(filter %-win32.a %-wince.a,$(LIBTCC1_CROSS)))
256 LIBTCC1_U = $(wildcard $(filter-out $(LIBTCC1_W),$(LIBTCC1_CROSS)))
257 PROGS_X = $(wildcard $(PROGS_CROSS))
259 # install progs & libs
260 install-unx:
261 mkdir -p "$(bindir)"
262 $(INSTALLBIN) $(PROGS) $(PROGS_X) "$(bindir)"
263 mkdir -p "$(tccdir)"
264 $(INSTALL) $(LIBTCC1) $(LIBTCC1_U) "$(tccdir)"
265 mkdir -p "$(tccdir)/include"
266 $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/include"
267 mkdir -p "$(libdir)"
268 $(INSTALL) $(LIBTCC) "$(libdir)"
269 mkdir -p "$(includedir)"
270 $(INSTALL) $(TOPSRC)/libtcc.h "$(includedir)"
271 $(call TRY-INSTALL,tcc.1,"$(mandir)/man1")
272 $(call TRY-INSTALL,tcc-doc.info,"$(infodir)")
273 $(call TRY-INSTALL,tcc-doc.html,"$(docdir)")
274 mkdir -p "$(tccdir)/win32/include"
275 cp -r $(TOPSRC)/include/. "$(tccdir)/win32/include"
276 cp -r $(TOPSRC)/win32/include/. "$(tccdir)/win32/include"
277 mkdir -p "$(tccdir)/win32/lib"
278 $(INSTALL) $(TOPSRC)/win32/lib/*.def $(LIBTCC1_W) "$(tccdir)/win32/lib"
280 # uninstall
281 uninstall-unx:
282 rm -fv $(foreach P,$(PROGS) $(PROGS_CROSS),"$(bindir)/$P")
283 rm -fv "$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
284 rm -fv "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
285 rm -fv "$(docdir)/tcc-doc.html"
286 rm -rv "$(tccdir)"
288 # install progs & libs on windows
289 install-win:
290 mkdir -p "$(tccdir)"
291 $(INSTALL) $(PROGS) $(subst libtcc.a,,$(LIBTCC)) $(PROGS_X) "$(tccdir)"
292 mkdir -p "$(tccdir)/lib"
293 $(INSTALL) $(TOPSRC)/win32/lib/*.def "$(tccdir)/lib"
294 $(INSTALL) libtcc1.a $(LIBTCC1_W) $(LIBTCC1_U) "$(tccdir)/lib"
295 mkdir -p "$(tccdir)/include"
296 cp -r $(TOPSRC)/win32/include/. "$(tccdir)/include"
297 $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/include"
298 mkdir -p "$(tccdir)/lib/include";
299 $(INSTALL) $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/lib/include"
300 mkdir -p "$(tccdir)/examples"
301 cp -r $(TOPSRC)/win32/examples/. "$(tccdir)/examples"
302 $(INSTALL) $(TOPSRC)/tests/libtcc_test.c "$(tccdir)/examples"
303 mkdir -p "$(tccdir)/libtcc"
304 $(INSTALL) $(TOPSRC)/libtcc.h $(subst .dll,.def,$(LIBTCC)) "$(tccdir)/libtcc"
305 mkdir -p "$(tccdir)/doc"
306 $(INSTALL) $(TOPSRC)/win32/tcc-win32.txt $(wildcard tcc-doc.html) "$(tccdir)/doc"
308 # the msys-git shell works to configure && make except it does not have install
309 install-win : INSTALL = cp
311 # uninstall on windows
312 uninstall-win:
313 rm -rfv "$(tccdir)/"*
315 # --------------------------------------------------------------------------
316 # other stuff
318 TAGFILES = *.[ch] include/*.h lib/*.[chS]
319 tags : ; ctags $(TAGFILES)
320 # cannot have both tags and TAGS on windows
321 ETAGS : ; etags $(TAGFILES)
323 # create release tarball from *current* git branch (including tcc-doc.html
324 # and converting two files to CRLF)
325 TCC-VERSION = $(VERSION)
326 tar: tcc-doc.html
327 mkdir $(TCC-VERSION)
328 ( cd $(TCC-VERSION) && git --git-dir ../.git checkout -f )
329 cp tcc-doc.html $(TCC-VERSION)
330 for f in tcc-win32.txt build-tcc.bat ; do \
331 cat win32/$$f | sed 's,\(.*\),\1\r,g' > $(TCC-VERSION)/win32/$$f ; \
332 done
333 tar cjf $(TCC-VERSION).tar.bz2 $(TCC-VERSION)
334 rm -rf $(TCC-VERSION)
335 git reset
337 config.mak:
338 $(if $(wildcard $@),,@echo "Please run ./configure." && exit 1)
340 # in tests subdir
341 test:
342 $(MAKE) -C tests
344 clean:
345 rm -f $(PROGS) $(PROGS_CROSS) tcc_p$(EXESUF) tcc.pod \
346 *~ *.o *.a *.so* *.out *.log lib*.def *.exe *.dll a.out \
347 tags TAGS libtcc_test$(EXESUF)
348 $(MAKE) -C tests $@
349 $(MAKE) -C lib $@
351 distclean: clean
352 rm -f config.h config.mak config.texi tcc.1 tcc-doc.info tcc-doc.html
354 .PHONY: all clean test tar tags ETAGS distclean install uninstall FORCE
356 help:
357 @echo "make"
358 @echo " build native compiler (from separate objects)"
359 @echo ""
360 @echo "make cross"
361 @echo " build cross compilers (from one source)"
362 @echo ""
363 @echo "make ONE_SOURCE=yes / no"
364 @echo " force building from one source / separate objects"
365 @echo ""
366 @echo "make cross-TARGET"
367 @echo " build one specific cross compiler for 'TARGET', as in"
368 @echo " $(TCC_X)"
369 @echo ""
370 @echo "Cross compiler configuration:"
371 @echo " make will read custom configuration for cross compilers from a file"
372 @echo " 'config-cross.mak' if present. For example for a windows->i386-linux"
373 @echo " cross-compiler that expects the linux files in <prefix>/i386-linux:"
374 @echo ""
375 @echo " ROOT-i386 = {B}/i386-linux"
376 @echo " CRT-i386 = $(ROOT-i386)/usr/lib"
377 @echo " LIB-i386 = $(ROOT-i386)/lib:$(ROOT-i386)/usr/lib"
378 @echo " INC-i386 = {B}/lib/include:$(ROOT-i386)/usr/include"
379 @echo " DEF-i386 += -D__linux__"
380 @echo ""
381 @echo "Other supported make targets:"
382 @echo " install install-strip test tags ETAGS tar clean distclean help"
384 # --------------------------------------------------------------------------
385 endif # ($(INCLUDED),no)