Fix struct ret in variadic fct with ARM hardfloat
[tinycc.git] / Makefile
blob24a7c0945e1f3cf28fd5422c8a8abbb115eabfca
2 # Tiny C Compiler Makefile
5 TOP ?= .
6 include $(TOP)/config.mak
7 VPATH = $(top_srcdir)
9 CPPFLAGS = -I$(TOP) # for config.h
11 ifeq (-$(findstring gcc,$(CC))-,-gcc-)
12 ifeq (-$(findstring $(GCC_MAJOR),01)-,--)
13 CFLAGS+=-fno-strict-aliasing
14 ifeq (-$(findstring $(GCC_MAJOR),23)-,--)
15 CFLAGS+=-Wno-pointer-sign -Wno-sign-compare
16 ifeq (-$(GCC_MAJOR)-$(findstring $(GCC_MINOR),56789)-,-4--)
17 CFLAGS+=-D_FORTIFY_SOURCE=0
18 else
19 CFLAGS+=-Wno-unused-result
20 endif
21 endif
22 endif
23 else # not GCC
24 ifeq (-$(findstring clang,$(CC))-,-clang-)
25 # make clang accept gnuisms in libtcc1.c
26 CFLAGS+=-fheinous-gnu-extensions
27 endif
28 endif
30 CPPFLAGS_P=$(CPPFLAGS) -DCONFIG_TCC_STATIC
31 CFLAGS_P=$(CFLAGS) -pg -static
32 LIBS_P=
33 LDFLAGS_P=$(LDFLAGS)
35 ifdef CONFIG_WIN64
36 CONFIG_WIN32=yes
37 endif
39 ifndef CONFIG_WIN32
40 LIBS=-lm
41 ifndef CONFIG_NOLDL
42 LIBS+=-ldl
43 endif
44 endif
46 # make libtcc as static or dynamic library?
47 ifdef DISABLE_STATIC
48 ifndef CONFIG_WIN32
49 LIBTCC=libtcc.so.1.0
50 else
51 LIBTCC=libtcc.dll
52 LIBTCC_DLL=yes
53 LIBTCC_EXTRA=libtcc.def libtcc.a
54 endif
55 LINK_LIBTCC=-Wl,-rpath,"$(libdir)"
56 ifdef DISABLE_RPATH
57 LINK_LIBTCC=
58 endif
59 else
60 LIBTCC=libtcc.a
61 LINK_LIBTCC=
62 endif
64 CONFIG_$(ARCH) = yes
65 NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
66 NATIVE_DEFINES_$(CONFIG_x86-64) += -DTCC_TARGET_X86_64
67 NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE
68 NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC
69 NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM
70 NATIVE_DEFINES_$(CONFIG_arm_eabihf) += -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT
71 NATIVE_DEFINES_$(CONFIG_arm_eabi) += -DTCC_ARM_EABI
72 NATIVE_DEFINES_$(CONFIG_arm_vfp) += -DTCC_ARM_VFP
73 NATIVE_DEFINES += $(NATIVE_DEFINES_yes)
75 ifeq ($(TOP),.)
77 PROGS=tcc$(EXESUF)
78 I386_CROSS = i386-tcc$(EXESUF)
79 WIN32_CROSS = i386-win32-tcc$(EXESUF)
80 WIN64_CROSS = x86_64-win32-tcc$(EXESUF)
81 WINCE_CROSS = arm-win32-tcc$(EXESUF)
82 X64_CROSS = x86_64-tcc$(EXESUF)
83 ARM_FPA_CROSS = arm-fpa-tcc$(EXESUF)
84 ARM_FPA_LD_CROSS = arm-fpa-ld-tcc$(EXESUF)
85 ARM_VFP_CROSS = arm-vfp-tcc$(EXESUF)
86 ARM_EABI_CROSS = arm-eabi-tcc$(EXESUF)
87 ARM_CROSS = $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS)
88 C67_CROSS = c67-tcc$(EXESUF)
90 CORE_FILES = tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
91 CORE_FILES += tcc.h config.h libtcc.h tcctok.h
92 I386_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h
93 WIN32_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
94 WIN64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h tccpe.c
95 WINCE_FILES = $(CORE_FILES) arm-gen.c tccpe.c
96 X86_64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h
97 ARM_FILES = $(CORE_FILES) arm-gen.c
98 C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c
100 ifdef CONFIG_WIN64
101 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
102 NATIVE_FILES=$(WIN64_FILES)
103 PROGS_CROSS=$(WIN32_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
104 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a
105 LIBTCC1=libtcc1.a
106 else ifdef CONFIG_WIN32
107 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
108 NATIVE_FILES=$(WIN32_FILES)
109 PROGS_CROSS=$(WIN64_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
110 LIBTCC1_CROSS=lib/x86_64-win32/libtcc1.a
111 LIBTCC1=libtcc1.a
112 else ifeq ($(ARCH),i386)
113 NATIVE_FILES=$(I386_FILES)
114 PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
115 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a
116 LIBTCC1=libtcc1.a
117 else ifeq ($(ARCH),x86-64)
118 NATIVE_FILES=$(X86_64_FILES)
119 PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
120 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a lib/i386/libtcc1.a
121 LIBTCC1=libtcc1.a
122 else ifeq ($(ARCH),arm)
123 NATIVE_FILES=$(ARM_FILES)
124 PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(C67_CROSS)
125 LIBTCC1=libtcc1.a
126 endif
128 ifeq ($(TARGETOS),Darwin)
129 PROGS+=tiny_libmaker$(EXESUF)
130 endif
132 ifdef CONFIG_USE_LIBGCC
133 LIBTCC1=
134 endif
136 TCCLIBS = $(LIBTCC1) $(LIBTCC) $(LIBTCC_EXTRA)
137 TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info
139 ifdef CONFIG_CROSS
140 PROGS+=$(PROGS_CROSS)
141 TCCLIBS+=$(LIBTCC1_CROSS)
142 endif
144 all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
146 # Host Tiny C Compiler
147 tcc$(EXESUF): tcc.o $(LIBTCC)
148 $(CC) -o $@ $^ $(LIBS) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(LINK_LIBTCC)
150 # Cross Tiny C Compilers
151 %-tcc$(EXESUF): tcc.c
152 $(CC) -o $@ $< -DONE_SOURCE $(DEFINES) $(CPPFLAGS) $(CFLAGS) $(LIBS) $(LDFLAGS)
154 # profiling version
155 tcc_p$(EXESUF): $(NATIVE_FILES)
156 $(CC) -o $@ $< -DONE_SOURCE $(NATIVE_DEFINES) $(CPPFLAGS_P) $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P)
158 $(I386_CROSS): DEFINES = -DTCC_TARGET_I386 \
159 -DCONFIG_TCCDIR="\"$(tccdir)/i386\""
160 $(X64_CROSS): DEFINES = -DTCC_TARGET_X86_64
161 $(WIN32_CROSS): DEFINES = -DTCC_TARGET_I386 -DTCC_TARGET_PE \
162 -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
163 -DCONFIG_TCC_LIBPATHS="\"{B}/lib/32;{B}/lib\""
164 $(WIN64_CROSS): DEFINES = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE \
165 -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
166 -DCONFIG_TCC_LIBPATHS="\"{B}/lib/64;{B}/lib\""
167 $(WINCE_CROSS): DEFINES = -DTCC_TARGET_PE
168 $(C67_CROSS): DEFINES = -DTCC_TARGET_C67
169 $(ARM_FPA_CROSS): DEFINES = -DTCC_TARGET_ARM
170 $(ARM_FPA_LD_CROSS)$(EXESUF): DEFINES = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
171 $(ARM_VFP_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_VFP
172 $(ARM_EABI_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_EABI
174 $(I386_CROSS): $(I386_FILES)
175 $(X64_CROSS): $(X86_64_FILES)
176 $(WIN32_CROSS): $(WIN32_FILES)
177 $(WIN64_CROSS): $(WIN64_FILES)
178 $(WINCE_CROSS): $(WINCE_FILES)
179 $(C67_CROSS): $(C67_FILES)
180 $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS): $(ARM_FILES)
182 # libtcc generation and test
183 ifndef ONE_SOURCE
184 LIBTCC_OBJ = $(filter-out tcc.o,$(patsubst %.c,%.o,$(filter %.c,$(NATIVE_FILES))))
185 LIBTCC_INC = $(filter %.h,$(CORE_FILES)) $(filter-out $(CORE_FILES),$(NATIVE_FILES))
186 else
187 LIBTCC_OBJ = libtcc.o
188 LIBTCC_INC = $(NATIVE_FILES)
189 libtcc.o : NATIVE_DEFINES += -DONE_SOURCE
190 endif
192 $(LIBTCC_OBJ) tcc.o : %.o : %.c $(LIBTCC_INC)
193 $(CC) -o $@ -c $< $(NATIVE_DEFINES) $(CPPFLAGS) $(CFLAGS)
195 ifndef LIBTCC_DLL
196 libtcc.a: $(LIBTCC_OBJ)
197 $(AR) rcs $@ $^
198 endif
200 libtcc.so.1.0: $(LIBTCC_OBJ)
201 $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDFLAGS)
203 libtcc.so.1.0: CFLAGS+=-fPIC
205 ifdef LIBTCC_DLL
206 libtcc.dll libtcc.def libtcc.a: $(LIBTCC_OBJ)
207 $(CC) -shared $^ -o $@ $(LDFLAGS) -Wl,--output-def,libtcc.def,--out-implib,libtcc.a
208 endif
210 # windows utilities
211 tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
212 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
213 tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
214 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
216 # TinyCC runtime libraries
217 libtcc1.a : FORCE
218 $(MAKE) -C lib native
219 lib/%/libtcc1.a : FORCE $(PROGS_CROSS)
220 $(MAKE) -C lib cross TARGET=$*
222 FORCE:
224 # install
225 TCC_INCLUDES = stdarg.h stddef.h stdbool.h float.h varargs.h
226 INSTALL=install
227 ifdef STRIP_BINARIES
228 INSTALLBIN=$(INSTALL) -s
229 else
230 INSTALLBIN=$(INSTALL)
231 endif
233 install-strip: install
234 strip $(foreach PROG,$(PROGS),"$(bindir)"/$(PROG))
236 ifndef CONFIG_WIN32
237 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
238 mkdir -p "$(bindir)"
239 ifeq ($(CC),tcc)
240 $(INSTALL) -m755 $(PROGS) "$(bindir)"
241 else
242 $(INSTALLBIN) -m755 $(PROGS) "$(bindir)"
243 endif
244 mkdir -p "$(mandir)/man1"
245 -$(INSTALL) tcc.1 "$(mandir)/man1"
246 mkdir -p "$(infodir)"
247 -$(INSTALL) tcc-doc.info "$(infodir)"
248 mkdir -p "$(tccdir)"
249 mkdir -p "$(tccdir)/include"
250 ifneq ($(LIBTCC1),)
251 $(INSTALL) -m644 $(LIBTCC1) "$(tccdir)"
252 endif
253 $(INSTALL) -m644 $(addprefix $(top_srcdir)/include/,$(TCC_INCLUDES)) $(top_srcdir)/tcclib.h "$(tccdir)/include"
254 mkdir -p "$(libdir)"
255 $(INSTALL) -m755 $(LIBTCC) "$(libdir)"
256 ifdef DISABLE_STATIC
257 ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so.1"
258 ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so"
259 endif
260 mkdir -p "$(includedir)"
261 $(INSTALL) -m644 $(top_srcdir)/libtcc.h "$(includedir)"
262 mkdir -p "$(docdir)"
263 -$(INSTALL) -m644 tcc-doc.html "$(docdir)"
264 ifdef CONFIG_CROSS
265 mkdir -p "$(tccdir)/win32/lib/32"
266 mkdir -p "$(tccdir)/win32/lib/64"
267 ifeq ($(ARCH),x86-64)
268 mkdir -p "$(tccdir)/i386"
269 $(INSTALL) -m644 lib/i386/libtcc1.a "$(tccdir)/i386"
270 cp -r "$(tccdir)/include" "$(tccdir)/i386"
271 endif
272 $(INSTALL) -m644 $(top_srcdir)/win32/lib/*.def "$(tccdir)/win32/lib"
273 $(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/win32/lib/32"
274 $(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/win32/lib/64"
275 cp -r $(top_srcdir)/win32/include/. "$(tccdir)/win32/include"
276 cp -r $(top_srcdir)/include/. "$(tccdir)/win32/include"
277 endif
279 uninstall:
280 rm -fv $(foreach P,$(PROGS),"$(bindir)/$P")
281 rm -fv $(foreach P,$(LIBTCC1),"$(tccdir)/$P")
282 rm -fv $(foreach P,$(TCC_INCLUDES),"$(tccdir)/include/$P")
283 rm -fv "$(tccdir)/include/tcclib.h"
284 rm -fv "$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
285 rm -fv "$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
286 rm -fv "$(libdir)/libtcc.so*"
287 rm -rf "$(tccdir)/win32"
288 -rmdir $(tccdir)/include
289 ifeq ($(ARCH),x86-64)
290 rm -rf "$(tccdir)/i386"
291 endif
292 else
293 # on windows
294 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
295 mkdir -p "$(tccdir)"
296 mkdir -p "$(tccdir)/lib"
297 mkdir -p "$(tccdir)/include"
298 mkdir -p "$(tccdir)/examples"
299 mkdir -p "$(tccdir)/doc"
300 mkdir -p "$(tccdir)/libtcc"
301 $(INSTALLBIN) -m755 $(PROGS) "$(tccdir)"
302 $(INSTALL) -m644 $(LIBTCC1) $(top_srcdir)/win32/lib/*.def "$(tccdir)/lib"
303 cp -r $(top_srcdir)/win32/include/. "$(tccdir)/include"
304 cp -r $(top_srcdir)/win32/examples/. "$(tccdir)/examples"
305 $(INSTALL) -m644 $(addprefix $(top_srcdir)/include/,$(TCC_INCLUDES)) $(top_srcdir)/tcclib.h "$(tccdir)/include"
306 $(INSTALL) -m644 tcc-doc.html $(top_srcdir)/win32/tcc-win32.txt "$(tccdir)/doc"
307 $(INSTALL) -m644 $(top_srcdir)/libtcc.h $(LIBTCC_EXTRA) "$(tccdir)/libtcc"
308 $(INSTALL) -m644 $(LIBTCC) $(tccdir)
309 ifdef CONFIG_CROSS
310 mkdir -p "$(tccdir)/lib/32"
311 mkdir -p "$(tccdir)/lib/64"
312 -$(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/lib/32"
313 -$(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/lib/64"
314 endif
316 uninstall:
317 rm -rfv "$(tccdir)/*"
318 endif
320 # documentation and man page
321 tcc-doc.html: tcc-doc.texi
322 -makeinfo --no-split --html --number-sections -o $@ $<
324 tcc.1: tcc-doc.texi
325 -$(top_srcdir)/texi2pod.pl $< tcc.pod
326 -pod2man --section=1 --center="Tiny C Compiler" --release=`cat $(top_srcdir)/VERSION` tcc.pod > $@
328 tcc-doc.info: tcc-doc.texi
329 -makeinfo $<
331 # in tests subdir
332 export LIBTCC1
334 %est:
335 $(MAKE) -C tests $@
337 clean:
338 rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.so* *.out *.exe libtcc_test$(EXESUF)
339 $(MAKE) -C tests $@
340 ifneq ($(LIBTCC1),)
341 $(MAKE) -C lib $@
342 endif
344 distclean: clean
345 rm -vf config.h config.mak config.texi tcc.1 tcc-doc.info tcc-doc.html
347 config.mak:
348 @echo "Please run ./configure."
349 @exit 1
351 # create release tarball from *current* git branch (including tcc-doc.html
352 # and converting two files to CRLF)
353 TCC-VERSION := tcc-$(shell cat $(top_srcdir)/VERSION)
354 tar: tcc-doc.html
355 mkdir $(TCC-VERSION)
356 ( cd $(TCC-VERSION) && git --git-dir ../.git checkout -f )
357 cp tcc-doc.html $(TCC-VERSION)
358 for f in tcc-win32.txt build-tcc.bat ; do \
359 cat win32/$$f | sed 's,\(.*\),\1\r,g' > $(TCC-VERSION)/win32/$$f ; \
360 done
361 tar cjf $(TCC-VERSION).tar.bz2 $(TCC-VERSION)
362 rm -rf $(TCC-VERSION)
363 git reset
365 Makefile: $(top_srcdir)/Makefile
366 cp $< $@
368 .PHONY: all clean tar distclean install uninstall FORCE
370 endif # ifeq ($(TOP),.)