Remove semicolon in x86-64 va_arg definition.
[tinycc.git] / Makefile
blob453748c739c18d4e97e79f44e975a9d708abce62
2 # Tiny C Compiler Makefile
5 TOP ?= .
6 include $(TOP)/config.mak
8 CFLAGS_P=$(CFLAGS) -pg -static -DCONFIG_TCC_STATIC
9 LIBS_P=
11 ifneq ($(GCC_MAJOR),2)
12 CFLAGS+=-fno-strict-aliasing
13 ifneq ($(GCC_MAJOR),3)
14 CFLAGS+=-Wno-pointer-sign -Wno-sign-compare -D_FORTIFY_SOURCE=0
15 endif
16 endif
18 ifeq ($(ARCH),i386)
19 CFLAGS+=-mpreferred-stack-boundary=2
20 ifeq ($(GCC_MAJOR),2)
21 CFLAGS+=-m386 -malign-functions=0
22 else
23 CFLAGS+=-march=i386 -falign-functions=0
24 endif
25 endif
27 ifdef CONFIG_WIN64
28 CONFIG_WIN32=yes
29 endif
31 ifndef CONFIG_WIN32
32 LIBS=-lm
33 ifndef CONFIG_NOLDL
34 LIBS+=-ldl
35 endif
36 endif
38 ifeq ($(ARCH),i386)
39 NATIVE_DEFINES=-DTCC_TARGET_I386
40 else
41 ifeq ($(ARCH),x86-64)
42 NATIVE_DEFINES=-DTCC_TARGET_X86_64
43 NATIVE_DEFINES+=$(if $(wildcard /lib64/ld-linux-x86-64.so.2),-DTCC_TARGET_X86_64_CENTOS)
44 endif
45 endif
47 ifeq ($(ARCH),arm)
48 NATIVE_DEFINES=-DTCC_TARGET_ARM
49 NATIVE_DEFINES+=-DWITHOUT_LIBTCC
50 NATIVE_DEFINES+=$(if $(wildcard /lib/ld-linux.so.3),-DTCC_ARM_EABI)
51 NATIVE_DEFINES+=$(if $(shell grep -l "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo),-DTCC_ARM_VFP)
52 endif
54 ifdef CONFIG_WIN32
55 NATIVE_DEFINES+=-DTCC_TARGET_PE
56 endif
58 ifneq ($(wildcard /lib/ld-uClibc.so.0),)
59 NATIVE_DEFINES+=-DTCC_UCLIBC
60 CONFIG_UCLIBC = 1
61 endif
63 # make libtcc as static or dynamic library?
64 ifdef DISABLE_STATIC
65 LIBTCC=libtcc.so.1.0
66 LINK_LIBTCC=-Wl,-rpath,"$(libdir)"
67 ifdef DISABLE_RPATH
68 LINK_LIBTCC=
69 endif
70 else
71 LIBTCC=libtcc.a
72 LINK_LIBTCC=
73 endif
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
107 ifdef CONFIG_WIN32
108 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
109 NATIVE_FILES=$(WIN32_FILES)
110 PROGS_CROSS=$(WIN64_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
111 LIBTCC1_CROSS=lib/x86_64-win32/libtcc1.a
112 LIBTCC1=libtcc1.a
113 else
114 ifeq ($(ARCH),i386)
115 NATIVE_FILES=$(I386_FILES)
116 PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
117 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a
118 LIBTCC1=libtcc1.a
119 BCHECK_O=bcheck.o
120 else
121 ifeq ($(ARCH),x86-64)
122 NATIVE_FILES=$(X86_64_FILES)
123 PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
124 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a lib/i386/libtcc1.a
125 LIBTCC1=libtcc1.a
126 else
127 ifeq ($(ARCH),arm)
128 NATIVE_FILES=$(ARM_FILES)
129 PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(C67_CROSS)
130 endif
131 endif
132 endif
133 endif
134 endif
136 ifdef CONFIG_UCLIBC
137 BCHECK_O=
138 endif
140 ifdef CONFIG_USE_LIBGCC
141 LIBTCC1=
142 endif
144 TCCLIBS = $(LIBTCC1) $(LIBTCC) $(BCHECK_O)
145 TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info
147 ifdef CONFIG_CROSS
148 PROGS+=$(PROGS_CROSS)
149 TCCLIBS+=$(LIBTCC1_CROSS)
150 endif
152 all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
154 # Host Tiny C Compiler
155 tcc$(EXESUF): tcc.o $(LIBTCC)
156 $(CC) -o $@ $^ $(LIBS) $(LDFLAGS) $(LINK_LIBTCC)
158 # Cross Tiny C Compilers
159 %-tcc$(EXESUF):
160 $(CC) -o $@ tcc.c -DONE_SOURCE $(DEFINES) $(CFLAGS) $(LIBS) $(LDFLAGS)
162 $(I386_CROSS): DEFINES = -DTCC_TARGET_I386 \
163 -DCONFIG_TCCDIR="\"$(tccdir)/i386\""
164 $(X64_CROSS): DEFINES = -DTCC_TARGET_X86_64
165 $(WIN32_CROSS): DEFINES = -DTCC_TARGET_I386 -DTCC_TARGET_PE \
166 -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
167 -DCONFIG_TCC_LIBPATH="\"\b/lib/32;\b/lib\""
168 $(WIN64_CROSS): DEFINES = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE \
169 -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
170 -DCONFIG_TCC_LIBPATH="\"\b/lib/64;\b/lib\""
171 $(WINCE_CROSS): DEFINES = -DTCC_TARGET_PE
172 $(C67_CROSS): DEFINES = -DTCC_TARGET_C67
173 $(ARM_FPA_CROSS): DEFINES = -DTCC_TARGET_ARM
174 $(ARM_FPA_LD_CROSS)$(EXESUF): DEFINES = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
175 $(ARM_VFP_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_VFP
176 $(ARM_EABI_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_EABI
178 $(I386_CROSS): $(I386_FILES)
179 $(X64_CROSS): $(X86_64_FILES)
180 $(WIN32_CROSS): $(WIN32_FILES)
181 $(WIN64_CROSS): $(WIN64_FILES)
182 $(WINCE_CROSS): $(WINCE_FILES)
183 $(C67_CROSS): $(C67_FILES)
184 $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS): $(ARM_FILES)
186 # libtcc generation and test
187 ifndef ONE_SOURCE
188 LIBTCC_OBJ = $(filter-out tcc.o,$(patsubst %.c,%.o,$(filter %.c,$(NATIVE_FILES))))
189 LIBTCC_INC = $(filter %.h,$(CORE_FILES)) $(filter-out $(CORE_FILES),$(NATIVE_FILES))
190 else
191 LIBTCC_OBJ = libtcc.o
192 LIBTCC_INC = $(NATIVE_FILES)
193 $(LIBTCC_OBJ) tcc.o : NATIVE_DEFINES += -DONE_SOURCE
194 endif
196 $(LIBTCC_OBJ) tcc.o : %.o : %.c $(LIBTCC_INC)
197 $(CC) -o $@ -c $< $(NATIVE_DEFINES) $(CFLAGS)
199 libtcc.a: $(LIBTCC_OBJ)
200 $(AR) rcs $@ $^
202 libtcc.so.1.0: $(LIBTCC_OBJ)
203 $(CC) -shared -Wl,-soname,$@ -o $@ $^
205 libtcc.so.1.0: CFLAGS+=-fPIC
207 # profiling version
208 tcc_p$(EXESUF): $(NATIVE_FILES)
209 $(CC) -o $@ $< $(NATIVE_DEFINES) $(CFLAGS_P) $(LIBS_P)
211 # windows utilities
212 tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
213 $(CC) -o $@ $< $(CFLAGS)
214 tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
215 $(CC) -o $@ $< $(CFLAGS)
217 # TinyCC runtime libraries
218 libtcc1.a : FORCE
219 @$(MAKE) -C lib native
220 lib/%/libtcc1.a : FORCE $(PROGS_CROSS)
221 @$(MAKE) -C lib cross TARGET=$*
222 bcheck.o : lib/bcheck.c
223 gcc -c $< -o $@ $(CFLAGS)
224 FORCE:
226 # install
227 TCC_INCLUDES = stdarg.h stddef.h stdbool.h float.h varargs.h tcclib.h
228 INSTALL=install
229 ifdef STRIP_BINARIES
230 INSTALLBIN=$(INSTALL) -s
231 else
232 INSTALLBIN=$(INSTALL)
233 endif
235 ifndef CONFIG_WIN32
236 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
237 mkdir -p "$(bindir)"
238 ifeq ($(CC),tcc)
239 $(INSTALL) -m755 $(PROGS) "$(bindir)"
240 else
241 $(INSTALLBIN) -m755 $(PROGS) "$(bindir)"
242 endif
243 mkdir -p "$(mandir)/man1"
244 -$(INSTALL) tcc.1 "$(mandir)/man1"
245 mkdir -p "$(infodir)"
246 -$(INSTALL) tcc-doc.info "$(infodir)"
247 mkdir -p "$(tccdir)"
248 mkdir -p "$(tccdir)/include"
249 ifneq ($(LIBTCC1),)
250 $(INSTALL) -m644 $(LIBTCC1) "$(tccdir)"
251 endif
252 ifneq ($(BCHECK_O),)
253 $(INSTALL) -m644 $(BCHECK_O) "$(tccdir)"
254 endif
255 $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
256 mkdir -p "$(libdir)"
257 $(INSTALL) -m755 $(LIBTCC) "$(libdir)"
258 ifdef DISABLE_STATIC
259 ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so.1"
260 ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so"
261 endif
262 mkdir -p "$(includedir)"
263 $(INSTALL) -m644 libtcc.h "$(includedir)"
264 mkdir -p "$(docdir)"
265 -$(INSTALL) -m644 tcc-doc.html "$(docdir)"
266 ifdef CONFIG_CROSS
267 mkdir -p "$(tccdir)/win32/lib/32"
268 mkdir -p "$(tccdir)/win32/lib/64"
269 ifeq ($(ARCH),x86-64)
270 mkdir -p "$(tccdir)/i386"
271 $(INSTALL) -m644 lib/i386/libtcc1.a "$(tccdir)/i386"
272 cp -r "$(tccdir)/include" "$(tccdir)/i386"
273 endif
274 $(INSTALL) -m644 win32/lib/*.def "$(tccdir)/win32/lib"
275 $(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/win32/lib/32"
276 $(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/win32/lib/64"
277 cp -r win32/include/. "$(tccdir)/win32/include"
278 cp -r include/. "$(tccdir)/win32/include"
279 endif
281 uninstall:
282 rm -fv $(foreach P,$(PROGS),"$(bindir)/$P")
283 rm -fv $(foreach P,$(LIBTCC1) $(BCHECK_O),"$(tccdir)/$P")
284 rm -fv $(foreach P,$(TCC_INCLUDES),"$(tccdir)/include/$P")
285 rm -fv "$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
286 rm -fv "$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
287 rm -fv "$(libdir)/libtcc.so*"
288 rm -rf "$(tccdir)/win32"
289 -rmdir $(tccdir)/include
290 ifeq ($(ARCH),x86-64)
291 rm -rf "$(tccdir)/i386"
292 endif
293 else
294 # on windows
295 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
296 mkdir -p "$(tccdir)"
297 mkdir -p "$(tccdir)/lib"
298 mkdir -p "$(tccdir)/include"
299 mkdir -p "$(tccdir)/examples"
300 mkdir -p "$(tccdir)/doc"
301 mkdir -p "$(tccdir)/libtcc"
302 $(INSTALLBIN) -m755 $(PROGS) "$(tccdir)"
303 $(INSTALL) -m644 $(LIBTCC1) win32/lib/*.def "$(tccdir)/lib"
304 cp -r win32/include/. "$(tccdir)/include"
305 cp -r win32/examples/. "$(tccdir)/examples"
306 $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
307 $(INSTALL) -m644 tcc-doc.html win32/tcc-win32.txt "$(tccdir)/doc"
308 $(INSTALL) -m644 $(LIBTCC) libtcc.h "$(tccdir)/libtcc"
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 -texi2html -monolithic -number $<
324 tcc.1: tcc-doc.texi
325 -./texi2pod.pl $< tcc.pod
326 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@
328 tcc-doc.info: tcc-doc.texi
329 -makeinfo tcc-doc.texi
331 .PHONY: all clean tar distclean install uninstall FORCE
333 # tar release (use 'make -k tar' on a checkouted tree)
334 TCC-VERSION=tcc-$(shell cat VERSION)
335 tar:
336 rm -rf /tmp/$(TCC-VERSION)
337 cp -r . /tmp/$(TCC-VERSION)
338 ( cd /tmp ; tar zcvf ~/$(TCC-VERSION).tar.gz $(TCC-VERSION) --exclude CVS )
339 rm -rf /tmp/$(TCC-VERSION)
341 # in tests subdir
342 export LIBTCC1
344 %est:
345 $(MAKE) -C tests $@
347 clean:
348 rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.so* *.out *.exe libtcc_test$(EXESUF)
349 $(MAKE) -C tests $@
350 ifneq ($(LIBTCC1),)
351 $(MAKE) -C lib $@
352 endif
354 distclean: clean
355 rm -vf config.h config.mak config.texi tcc.1 tcc-doc.info tcc-doc.html
357 config.mak:
358 @echo "Please run ./configure."
359 @exit 1
361 endif # ifeq ($(TOP),.)