configure: support DESTDIR for RPM packagers etc.
[tinycc/miki.git] / Makefile
blob730b817697b244e59c056e6b0ac94f8906064172
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 endif
16 ifeq ($(ARCH),i386)
17 CFLAGS+=-mpreferred-stack-boundary=2
18 ifeq ($(GCC_MAJOR),2)
19 CFLAGS+=-m386 -malign-functions=0
20 else
21 CFLAGS+=-march=i386 -falign-functions=0
22 ifneq ($(GCC_MAJOR),3)
23 CFLAGS+=-Wno-pointer-sign -Wno-sign-compare -D_FORTIFY_SOURCE=0
24 endif
25 endif
26 endif
28 ifeq ($(ARCH),x86-64)
29 CFLAGS+=-Wno-pointer-sign
30 endif
32 ifndef CONFIG_WIN32
33 LIBS=-lm
34 ifndef CONFIG_NOLDL
35 LIBS+=-ldl
36 endif
37 endif
39 ifdef CONFIG_WIN32
40 NATIVE_TARGET=-DTCC_TARGET_PE
41 LIBTCC1=libtcc1.a
42 else
43 ifeq ($(ARCH),i386)
44 NATIVE_TARGET=-DTCC_TARGET_I386
45 LIBTCC1=libtcc1.a
46 BCHECK_O=bcheck.o
47 else
48 ifeq ($(ARCH),arm)
49 NATIVE_TARGET=-DTCC_TARGET_ARM
50 NATIVE_TARGET+=$(if $(wildcard /lib/ld-linux.so.3),-DTCC_ARM_EABI)
51 NATIVE_TARGET+=$(if $(shell grep -l "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo),-DTCC_ARM_VFP)
52 else
53 ifeq ($(ARCH),x86-64)
54 NATIVE_TARGET=-DTCC_TARGET_X86_64
55 LIBTCC1=libtcc1.a
56 endif
57 endif
58 endif
59 endif
61 ifneq ($(wildcard /lib/ld-uClibc.so.0),)
62 NATIVE_TARGET+=-DTCC_UCLIBC
63 BCHECK_O=
64 endif
66 ifdef CONFIG_USE_LIBGCC
67 LIBTCC1=
68 endif
70 ifeq ($(TOP),.)
72 PROGS=tcc$(EXESUF)
74 I386_CROSS = i386-tcc$(EXESUF)
75 WIN32_CROSS = i386-win32-tcc$(EXESUF)
76 X64_CROSS = x86_64-tcc$(EXESUF)
77 ARM_CROSS = arm-tcc-fpa$(EXESUF) arm-tcc-fpa-ld$(EXESUF) \
78 arm-tcc-vfp$(EXESUF) arm-tcc-vfp-eabi$(EXESUF)
79 C67_CROSS = c67-tcc$(EXESUF)
81 CORE_FILES = tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c \
82 tcc.h config.h libtcc.h tcctok.h
83 I386_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h
84 WIN32_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h 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=$(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) $(ARM_CROSS) $(C67_CROSS)
97 else
98 ifeq ($(ARCH),x86-64)
99 NATIVE_FILES=$(X86_64_FILES)
100 PROGS_CROSS=$(I386_CROSS) $(WIN32_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) $(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-tcc$(EXESUF): $(X86_64_FILES)
128 $(CC) -o $@ $< -DTCC_TARGET_X86_64 $(CFLAGS) $(LIBS)
130 c67-tcc$(EXESUF): $(C67_FILES)
131 $(CC) -o $@ $< -DTCC_TARGET_C67 $(CFLAGS) $(LIBS)
133 arm-tcc-fpa$(EXESUF): $(ARM_FILES)
134 $(CC) -o $@ $< -DTCC_TARGET_ARM $(CFLAGS) $(LIBS)
136 arm-tcc-fpa-ld$(EXESUF): $(ARM_FILES)
137 $(CC) -o $@ $< -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12 $(CFLAGS) $(LIBS)
139 arm-tcc-vfp$(EXESUF): $(ARM_FILES)
140 $(CC) -o $@ $< -DTCC_TARGET_ARM -DTCC_ARM_VFP $(CFLAGS) $(LIBS)
142 arm-tcc-vfp-eabi$(EXESUF): $(ARM_FILES)
143 $(CC) -o $@ $< -DTCC_TARGET_ARM -DTCC_ARM_EABI $(CFLAGS) $(LIBS)
145 # libtcc generation and test
146 libtcc.o: $(NATIVE_FILES)
147 $(CC) -o $@ -c libtcc.c $(NATIVE_TARGET) $(CFLAGS)
149 libtcc.a: libtcc.o
150 $(AR) rcs $@ $^
152 libtcc_test$(EXESUF): tests/libtcc_test.c libtcc.a
153 $(CC) -o $@ $^ -I. $(CFLAGS) $(LIBS)
155 libtest: libtcc_test$(EXESUF) $(LIBTCC1)
156 ./libtcc_test$(EXESUF) lib_path=.
158 # profiling version
159 tcc_p$(EXESUF): $(NATIVE_FILES)
160 $(CC) -o $@ $< $(NATIVE_TARGET) $(CFLAGS_P) $(LIBS_P)
162 # windows utilities
163 tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
164 $(CC) -o $@ $< $(CFLAGS)
165 tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
166 $(CC) -o $@ $< $(CFLAGS)
168 # TinyCC runtime libraries
169 LIBTCC1_OBJS=libtcc1.o
170 LIBTCC1_CC=$(CC)
171 VPATH+=lib
172 ifdef CONFIG_WIN32
173 # for windows, we must use TCC because we generate ELF objects
174 LIBTCC1_OBJS+=crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o
175 LIBTCC1_CC=./tcc.exe -Bwin32 -DTCC_TARGET_PE
176 VPATH+=win32/lib
177 endif
178 ifeq ($(ARCH),i386)
179 LIBTCC1_OBJS+=alloca86.o alloca86-bt.o
180 else
181 ifeq ($(ARCH),x86-64)
182 LIBTCC1_OBJS+=alloca86_64.o
183 endif
184 endif
186 %.o: %.c
187 $(LIBTCC1_CC) -o $@ -c $< -O2 -Wall
189 %.o: %.S
190 $(LIBTCC1_CC) -o $@ -c $<
192 libtcc1.a: $(LIBTCC1_OBJS)
193 $(AR) rcs $@ $^
195 bcheck.o: bcheck.c
196 $(CC) -o $@ -c $< -O2 -Wall
198 # install
199 TCC_INCLUDES = stdarg.h stddef.h stdbool.h float.h varargs.h tcclib.h
200 INSTALL=install
202 ifndef CONFIG_WIN32
203 install: $(PROGS) $(LIBTCC1) $(BCHECK_O) libtcc.a tcc.1 tcc-doc.html
204 mkdir -p "$(bindir)"
205 $(INSTALL) -s -m755 $(PROGS) "$(bindir)"
206 mkdir -p "$(mandir)/man1"
207 $(INSTALL) tcc.1 "$(mandir)/man1"
208 mkdir -p "$(tccdir)"
209 mkdir -p "$(tccdir)/include"
210 ifneq ($(LIBTCC1),)
211 $(INSTALL) -m644 $(LIBTCC1) "$(tccdir)"
212 endif
213 ifneq ($(BCHECK_O),)
214 $(INSTALL) -m644 $(BCHECK_O) "$(tccdir)"
215 endif
216 $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
217 mkdir -p "$(docdir)"
218 $(INSTALL) -m644 tcc-doc.html "$(docdir)"
219 mkdir -p "$(libdir)"
220 $(INSTALL) -m644 libtcc.a "$(libdir)"
221 mkdir -p "$(includedir)"
222 $(INSTALL) -m644 libtcc.h "$(includedir)"
224 uninstall:
225 rm -fv $(foreach P,$(PROGS),"$(bindir)/$P")
226 rm -fv $(foreach P,$(LIBTCC1) $(BCHECK_O),"$(tccdir)/$P")
227 rm -fv $(foreach P,$(TCC_INCLUDES),"$(tccdir)/include/$P")
228 rm -fv "$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1"
229 rm -fv "$(libdir)/libtcc.a" "$(includedir)/libtcc.h"
231 else
232 install: $(PROGS) $(LIBTCC1) libtcc.a tcc-doc.html
233 mkdir -p "$(tccdir)"
234 mkdir -p "$(tccdir)/lib"
235 mkdir -p "$(tccdir)/include"
236 mkdir -p "$(tccdir)/examples"
237 mkdir -p "$(tccdir)/doc"
238 mkdir -p "$(tccdir)/libtcc"
239 $(INSTALL) -s -m755 $(PROGS) "$(tccdir)"
240 $(INSTALL) -m644 $(LIBTCC1) win32/lib/*.def "$(tccdir)/lib"
241 cp -r win32/include/. "$(tccdir)/include"
242 cp -r win32/examples/. "$(tccdir)/examples"
243 # $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
244 $(INSTALL) -m644 tcc-doc.html win32/tcc-win32.txt "$(tccdir)/doc"
245 $(INSTALL) -m644 libtcc.a libtcc.h "$(tccdir)/libtcc"
246 endif
248 # documentation and man page
249 tcc-doc.html: tcc-doc.texi
250 -texi2html -monolithic -number $<
252 tcc.1: tcc-doc.texi
253 -./texi2pod.pl $< tcc.pod
254 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@
256 # tar release (use 'make -k tar' on a checkouted tree)
257 TCC-VERSION=tcc-$(shell cat VERSION)
258 tar:
259 rm -rf /tmp/$(TCC-VERSION)
260 cp -r . /tmp/$(TCC-VERSION)
261 ( cd /tmp ; tar zcvf ~/$(TCC-VERSION).tar.gz $(TCC-VERSION) --exclude CVS )
262 rm -rf /tmp/$(TCC-VERSION)
264 # in tests subdir
265 test clean :
266 $(MAKE) -C tests $@
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 tcc-doc.html
276 endif # ifeq ($(TOP),.)