fix some warning
[tinycc/kirr.git] / Makefile
blob01c3e272257231580e43aa0d7c1323b0f625f8b9
2 # Tiny C Compiler Makefile
5 TOP ?= .
6 include $(TOP)/config.mak
8 CFLAGS+=-g -Wall
9 CFLAGS_P=$(CFLAGS) -pg -static -DCONFIG_TCC_STATIC
10 LIBS_P=
12 ifneq ($(GCC_MAJOR),2)
13 CFLAGS+=-fno-strict-aliasing
14 ifneq ($(GCC_MAJOR),3)
15 CFLAGS+=-Wno-pointer-sign -Wno-sign-compare -D_FORTIFY_SOURCE=0
16 endif
17 endif
19 ifeq ($(ARCH),i386)
20 CFLAGS+=-mpreferred-stack-boundary=2
21 ifeq ($(GCC_MAJOR),2)
22 CFLAGS+=-m386 -malign-functions=0
23 else
24 CFLAGS+=-march=i386 -falign-functions=0
25 endif
26 endif
28 ifndef CONFIG_WIN32
29 LIBS=-lm
30 ifndef CONFIG_NOLDL
31 LIBS+=-ldl
32 endif
33 endif
35 ifeq ($(ARCH),i386)
36 NATIVE_TARGET=-DTCC_TARGET_I386
37 LIBTCC1=libtcc1.a
38 BCHECK_O=bcheck.o
39 ALLOCA_O=alloca86.o alloca86-bt.o
40 else
41 ifeq ($(ARCH),x86-64)
42 NATIVE_TARGET=-DTCC_TARGET_X86_64
43 LIBTCC1=libtcc1.a
44 BCHECK_O=
45 ALLOCA_O=alloca86_64.o
46 endif
47 endif
49 ifeq ($(ARCH),arm)
50 NATIVE_TARGET=-DTCC_TARGET_ARM
51 NATIVE_TARGET+=$(if $(wildcard /lib/ld-linux.so.3),-DTCC_ARM_EABI)
52 NATIVE_TARGET+=$(if $(shell grep -l "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo),-DTCC_ARM_VFP)
53 endif
55 ifdef CONFIG_WIN32
56 NATIVE_TARGET+=-DTCC_TARGET_PE
57 BCHECK_O=
58 endif
60 ifneq ($(wildcard /lib/ld-uClibc.so.0),)
61 NATIVE_TARGET+=-DTCC_UCLIBC
62 BCHECK_O=
63 endif
65 ifdef CONFIG_USE_LIBGCC
66 LIBTCC1=
67 endif
69 ifeq ($(TOP),.)
71 PROGS=tcc$(EXESUF)
72 I386_CROSS = i386-tcc$(EXESUF)
73 WIN32_CROSS = i386-win32-tcc$(EXESUF)
74 WIN64_CROSS = x86_64-win32-tcc$(EXESUF)
75 X64_CROSS = x86_64-tcc$(EXESUF)
76 ARM_CROSS = arm-tcc-fpa$(EXESUF) arm-tcc-fpa-ld$(EXESUF) \
77 arm-tcc-vfp$(EXESUF) arm-tcc-vfp-eabi$(EXESUF)
78 C67_CROSS = c67-tcc$(EXESUF)
80 CORE_FILES = tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c \
81 tcc.h config.h libtcc.h tcctok.h
82 I386_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h
83 WIN32_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h tccpe.c
84 WIN64_FILES = $(CORE_FILES) x86_64-gen.c tccpe.c
85 X86_64_FILES = $(CORE_FILES) x86_64-gen.c
86 ARM_FILES = $(CORE_FILES) arm-gen.c
87 C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c
89 ifdef CONFIG_WIN32
90 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
91 NATIVE_FILES=$(WIN32_FILES)
92 PROGS_CROSS=$(WIN64_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
93 else
94 ifeq ($(ARCH),i386)
95 NATIVE_FILES=$(I386_FILES)
96 PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
97 else
98 ifeq ($(ARCH),x86-64)
99 NATIVE_FILES=$(X86_64_FILES)
100 PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
101 else
102 ifeq ($(ARCH),arm)
103 NATIVE_FILES=$(ARM_FILES)
104 PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(C67_CROSS)
105 endif
106 endif
107 endif
108 endif
110 ifdef CONFIG_CROSS
111 PROGS+=$(PROGS_CROSS)
112 endif
114 all: $(PROGS) $(LIBTCC1) $(BCHECK_O) libtcc.a tcc-doc.html tcc.1 libtcc_test$(EXESUF)
116 # Host Tiny C Compiler
117 tcc$(EXESUF): $(NATIVE_FILES)
118 $(CC) -o $@ $< $(NATIVE_TARGET) $(CFLAGS) $(LIBS)
120 # Cross Tiny C Compilers
121 i386-tcc$(EXESUF): $(I386_FILES)
122 $(CC) -o $@ $< -DTCC_TARGET_I386 $(CFLAGS) $(LIBS)
124 i386-win32-tcc$(EXESUF): $(WIN32_FILES)
125 $(CC) -o $@ $< -DTCC_TARGET_PE $(CFLAGS) $(LIBS)
127 x86_64-win32-tcc$(EXESUF): $(WIN32_FILES)
128 $(CC) -o $@ $< -DTCC_TARGET_PE -DTCC_TARGET_X86_64 $(CFLAGS) $(LIBS)
130 x86_64-tcc$(EXESUF): $(X86_64_FILES)
131 $(CC) -o $@ $< -DTCC_TARGET_X86_64 $(CFLAGS) $(LIBS)
133 c67-tcc$(EXESUF): $(C67_FILES)
134 $(CC) -o $@ $< -DTCC_TARGET_C67 $(CFLAGS) $(LIBS)
136 arm-tcc-fpa$(EXESUF): $(ARM_FILES)
137 $(CC) -o $@ $< -DTCC_TARGET_ARM $(CFLAGS) $(LIBS)
139 arm-tcc-fpa-ld$(EXESUF): $(ARM_FILES)
140 $(CC) -o $@ $< -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12 $(CFLAGS) $(LIBS)
142 arm-tcc-vfp$(EXESUF): $(ARM_FILES)
143 $(CC) -o $@ $< -DTCC_TARGET_ARM -DTCC_ARM_VFP $(CFLAGS) $(LIBS)
145 arm-tcc-vfp-eabi$(EXESUF): $(ARM_FILES)
146 $(CC) -o $@ $< -DTCC_TARGET_ARM -DTCC_ARM_EABI $(CFLAGS) $(LIBS)
148 # libtcc generation and test
149 libtcc.o: $(NATIVE_FILES)
150 $(CC) -o $@ -c libtcc.c $(NATIVE_TARGET) $(CFLAGS)
152 libtcc.a: libtcc.o
153 $(AR) rcs $@ $^
155 libtcc_test$(EXESUF): tests/libtcc_test.c libtcc.a
156 $(CC) -o $@ $^ -I. $(CFLAGS) $(LIBS)
158 libtest: libtcc_test$(EXESUF) $(LIBTCC1)
159 ./libtcc_test$(EXESUF) lib_path=.
161 # profiling version
162 tcc_p$(EXESUF): $(NATIVE_FILES)
163 $(CC) -o $@ $< $(NATIVE_TARGET) $(CFLAGS_P) $(LIBS_P)
165 # windows utilities
166 tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
167 $(CC) -o $@ $< $(CFLAGS)
168 tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
169 $(CC) -o $@ $< $(CFLAGS)
171 # TinyCC runtime libraries
172 LIBTCC1_OBJS=libtcc1.o $(ALLOCA_O)
173 LIBTCC1_CC=$(CC)
174 VPATH+=lib
176 ifdef CONFIG_WIN32
177 # for windows, we must use TCC because we generate ELF objects
178 LIBTCC1_OBJS+=crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o
179 LIBTCC1_CC=./tcc.exe -Bwin32 -Iinclude $(NATIVE_TARGET)
180 VPATH+=win32/lib
181 endif
183 %.o: %.c
184 $(LIBTCC1_CC) -o $@ -c $< -O2 -Wall
185 %.o: %.S
186 $(LIBTCC1_CC) -o $@ -c $<
188 libtcc1.a: $(LIBTCC1_OBJS)
189 $(AR) rcs $@ $^
191 bcheck.o: bcheck.c
192 $(CC) -o $@ -c $< -O2 -Wall
194 # install
195 TCC_INCLUDES = stdarg.h stddef.h stdbool.h float.h varargs.h tcclib.h
196 INSTALL=install
198 ifndef CONFIG_WIN32
199 install: $(PROGS) $(LIBTCC1) $(BCHECK_O) libtcc.a tcc.1 tcc-doc.html
200 mkdir -p "$(bindir)"
201 $(INSTALL) -s -m755 $(PROGS) "$(bindir)"
202 mkdir -p "$(mandir)/man1"
203 $(INSTALL) tcc.1 "$(mandir)/man1"
204 mkdir -p "$(tccdir)"
205 mkdir -p "$(tccdir)/include"
206 ifneq ($(LIBTCC1),)
207 $(INSTALL) -m644 $(LIBTCC1) "$(tccdir)"
208 endif
209 ifneq ($(BCHECK_O),)
210 $(INSTALL) -m644 $(BCHECK_O) "$(tccdir)"
211 endif
212 $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
213 mkdir -p "$(docdir)"
214 $(INSTALL) -m644 tcc-doc.html "$(docdir)"
215 mkdir -p "$(libdir)"
216 $(INSTALL) -m644 libtcc.a "$(libdir)"
217 mkdir -p "$(includedir)"
218 $(INSTALL) -m644 libtcc.h "$(includedir)"
220 uninstall:
221 rm -fv $(foreach P,$(PROGS),"$(bindir)/$P")
222 rm -fv $(foreach P,$(LIBTCC1) $(BCHECK_O),"$(tccdir)/$P")
223 rm -fv $(foreach P,$(TCC_INCLUDES),"$(tccdir)/include/$P")
224 rm -fv "$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1"
225 rm -fv "$(libdir)/libtcc.a" "$(includedir)/libtcc.h"
227 else
228 install: $(PROGS) $(LIBTCC1) libtcc.a tcc-doc.html
229 mkdir -p "$(tccdir)"
230 mkdir -p "$(tccdir)/lib"
231 mkdir -p "$(tccdir)/include"
232 mkdir -p "$(tccdir)/examples"
233 mkdir -p "$(tccdir)/doc"
234 mkdir -p "$(tccdir)/libtcc"
235 $(INSTALL) -s -m755 $(PROGS) "$(tccdir)"
236 $(INSTALL) -m644 $(LIBTCC1) win32/lib/*.def "$(tccdir)/lib"
237 cp -r win32/include/. "$(tccdir)/include"
238 cp -r win32/examples/. "$(tccdir)/examples"
239 $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
240 $(INSTALL) -m644 tcc-doc.html win32/tcc-win32.txt "$(tccdir)/doc"
241 $(INSTALL) -m644 libtcc.a libtcc.h "$(tccdir)/libtcc"
242 endif
244 # documentation and man page
245 tcc-doc.html: tcc-doc.texi
246 -texi2html -monolithic -number $<
248 tcc.1: tcc-doc.texi
249 -./texi2pod.pl $< tcc.pod
250 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@
252 # tar release (use 'make -k tar' on a checkouted tree)
253 TCC-VERSION=tcc-$(shell cat VERSION)
254 tar:
255 rm -rf /tmp/$(TCC-VERSION)
256 cp -r . /tmp/$(TCC-VERSION)
257 ( cd /tmp ; tar zcvf ~/$(TCC-VERSION).tar.gz $(TCC-VERSION) --exclude CVS )
258 rm -rf /tmp/$(TCC-VERSION)
260 # in tests subdir
261 test clean:
262 $(MAKE) -C tests $@
264 config.mak:
265 @echo Running configure ...
266 @./configure
268 # clean
269 clean: local_clean
270 local_clean:
271 rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.out libtcc_test$(EXESUF)
273 distclean: clean
274 rm -vf config.h config.mak config.texi tcc.1
276 endif # ifeq ($(TOP),.)