Add my copyright for changes in arm-gen.c
[tinycc.git] / Makefile
blobd2574640bf8fbd3c20f20f0e76ad069323050e98
2 # Tiny C Compiler Makefile
5 TOP ?= .
6 include $(TOP)/config.mak
7 VPATH = $(top_srcdir)
9 CPPFLAGS_P=$(CPPFLAGS) -DCONFIG_TCC_STATIC
10 CFLAGS_P=$(CFLAGS) -pg -static
11 LIBS_P=
12 LDFLAGS_P=$(LDFLAGS)
14 ifneq ($(GCC_MAJOR),2)
15 CFLAGS+=-fno-strict-aliasing
16 ifneq ($(GCC_MAJOR),3)
17 CFLAGS+=-Wno-pointer-sign -Wno-sign-compare
18 endif
19 endif
21 ifneq ($(TARGETOS),Darwin)
22 ifeq ($(ARCH),i386)
23 CFLAGS+=-mpreferred-stack-boundary=2
24 ifeq ($(GCC_MAJOR),2)
25 CFLAGS+=-m386 -malign-functions=0
26 else
27 CFLAGS+=-march=i386 -falign-functions=0
28 endif
29 endif
30 endif
32 ifdef CONFIG_WIN64
33 CONFIG_WIN32=yes
34 endif
36 ifndef CONFIG_WIN32
37 LIBS=-lm
38 ifndef CONFIG_NOLDL
39 LIBS+=-ldl
40 endif
41 endif
43 ifeq ($(ARCH),i386)
44 NATIVE_DEFINES=-DTCC_TARGET_I386
45 NATIVE_DEFINES+=$(if $(wildcard /lib/i386-linux-gnu),-DCONFIG_MULTIARCHDIR=\"i386-linux-gnu\")
46 NATIVE_DEFINES+=$(if $(wildcard /lib/i386-kfreebsd-gnu),-DCONFIG_MULTIARCHDIR=\"i386-kfreebsd-gnu\")
47 NATIVE_DEFINES+=$(if $(wildcard /lib/i386-gnu),-DCONFIG_MULTIARCHDIR=\"i386-gnu\")
48 CFLAGS+=-m32
49 else ifeq ($(ARCH),x86-64)
50 NATIVE_DEFINES=-DTCC_TARGET_X86_64
51 CFLAGS+=-m64
52 NATIVE_DEFINES+=$(if $(wildcard /usr/lib64),-DCONFIG_LDDIR=\"lib64\")
53 NATIVE_DEFINES+=$(if $(wildcard /lib/x86_64-linux-gnu),-DCONFIG_MULTIARCHDIR=\"x86_64-linux-gnu\")
54 NATIVE_DEFINES+=$(if $(wildcard /lib/x86_64-kfreebsd-gnu),-DCONFIG_MULTIARCHDIR=\"x86_64-kfreebsd-gnu\")
55 endif
57 ifeq ($(ARCH),arm)
58 NATIVE_DEFINES=-DTCC_TARGET_ARM
59 NATIVE_DEFINES+=-DWITHOUT_LIBTCC
60 ifneq (,$(wildcard /lib/ld-linux-armhf.so.3 /lib/arm-linux-gnueabihf/ld-linux.so.3))
61 NATIVE_DEFINES+=-DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT
62 NATIVE_DEFINES+=$(if $(wildcard /lib/arm-linux-gnueabihf),-DCONFIG_MULTIARCHDIR=\"arm-linux-gnueabihf\")
63 else ifneq (,$(wildcard /lib/ld-linux.so.3))
64 NATIVE_DEFINES+=-DTCC_ARM_EABI
65 NATIVE_DEFINES+=$(if $(wildcard /lib/arm-linux-gnueabi), -DCONFIG_MULTIARCHDIR=\"arm-linux-gnueabi\")
66 endif
67 NATIVE_DEFINES+=$(if $(shell grep -l "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo),-DTCC_ARM_VFP)
68 endif
70 ifdef CONFIG_WIN32
71 NATIVE_DEFINES+=-DTCC_TARGET_PE
72 endif
74 ifneq ($(wildcard /lib/ld-uClibc.so.0),)
75 NATIVE_DEFINES+=-DTCC_UCLIBC
76 CONFIG_UCLIBC = 1
77 endif
79 # make libtcc as static or dynamic library?
80 ifdef DISABLE_STATIC
81 LIBTCC=libtcc.so.1.0
82 LINK_LIBTCC=-Wl,-rpath,"$(libdir)"
83 ifdef DISABLE_RPATH
84 LINK_LIBTCC=
85 endif
86 else
87 LIBTCC=libtcc.a
88 LINK_LIBTCC=
89 endif
91 ifeq ($(TOP),.)
93 PROGS=tcc$(EXESUF)
94 I386_CROSS = i386-tcc$(EXESUF)
95 WIN32_CROSS = i386-win32-tcc$(EXESUF)
96 WIN64_CROSS = x86_64-win32-tcc$(EXESUF)
97 WINCE_CROSS = arm-win32-tcc$(EXESUF)
98 X64_CROSS = x86_64-tcc$(EXESUF)
99 ARM_FPA_CROSS = arm-fpa-tcc$(EXESUF)
100 ARM_FPA_LD_CROSS = arm-fpa-ld-tcc$(EXESUF)
101 ARM_VFP_CROSS = arm-vfp-tcc$(EXESUF)
102 ARM_EABI_CROSS = arm-eabi-tcc$(EXESUF)
103 ARM_CROSS = $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS)
104 C67_CROSS = c67-tcc$(EXESUF)
106 CORE_FILES = tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
107 CORE_FILES += tcc.h config.h libtcc.h tcctok.h
108 I386_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h
109 WIN32_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
110 WIN64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h tccpe.c
111 WINCE_FILES = $(CORE_FILES) arm-gen.c tccpe.c
112 X86_64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h
113 ARM_FILES = $(CORE_FILES) arm-gen.c
114 C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c
116 ifdef CONFIG_WIN64
117 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
118 NATIVE_FILES=$(WIN64_FILES)
119 PROGS_CROSS=$(WIN32_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
120 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a
121 LIBTCC1=libtcc1.a
122 else ifdef CONFIG_WIN32
123 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
124 NATIVE_FILES=$(WIN32_FILES)
125 PROGS_CROSS=$(WIN64_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
126 LIBTCC1_CROSS=lib/x86_64-win32/libtcc1.a
127 LIBTCC1=libtcc1.a
128 else ifeq ($(ARCH),i386)
129 NATIVE_FILES=$(I386_FILES)
130 PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
131 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a
132 LIBTCC1=libtcc1.a
133 BCHECK_O=bcheck.o
134 else ifeq ($(ARCH),x86-64)
135 NATIVE_FILES=$(X86_64_FILES)
136 PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
137 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a lib/i386/libtcc1.a
138 LIBTCC1=libtcc1.a
139 else ifeq ($(ARCH),arm)
140 NATIVE_FILES=$(ARM_FILES)
141 PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(C67_CROSS)
142 endif
144 ifdef CONFIG_UCLIBC
145 BCHECK_O=
146 endif
147 ifeq ($(TARGETOS),Darwin)
148 BCHECK_O=
149 PROGS+=tiny_libmaker$(EXESUF)
150 endif
152 ifdef CONFIG_USE_LIBGCC
153 LIBTCC1=
154 endif
156 TCCLIBS = $(LIBTCC1) $(LIBTCC) $(BCHECK_O)
157 TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info
159 ifdef CONFIG_CROSS
160 PROGS+=$(PROGS_CROSS)
161 TCCLIBS+=$(LIBTCC1_CROSS)
162 endif
164 all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
166 # Host Tiny C Compiler
167 tcc$(EXESUF): tcc.o $(LIBTCC)
168 $(CC) -o $@ $^ $(LIBS) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(LINK_LIBTCC)
170 # Cross Tiny C Compilers
171 %-tcc$(EXESUF):
172 $(CC) -o $@ tcc.c -DONE_SOURCE $(DEFINES) $(CPPFLAGS) $(CFLAGS) $(LIBS) $(LDFLAGS)
174 $(I386_CROSS): DEFINES = -DTCC_TARGET_I386 \
175 -DCONFIG_TCCDIR="\"$(tccdir)/i386\""
176 $(X64_CROSS): DEFINES = -DTCC_TARGET_X86_64
177 $(WIN32_CROSS): DEFINES = -DTCC_TARGET_I386 -DTCC_TARGET_PE \
178 -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
179 -DCONFIG_TCC_LIBPATHS="\"{B}/lib/32;{B}/lib\""
180 $(WIN64_CROSS): DEFINES = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE \
181 -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
182 -DCONFIG_TCC_LIBPATHS="\"{B}/lib/64;{B}/lib\""
183 $(WINCE_CROSS): DEFINES = -DTCC_TARGET_PE
184 $(C67_CROSS): DEFINES = -DTCC_TARGET_C67
185 $(ARM_FPA_CROSS): DEFINES = -DTCC_TARGET_ARM
186 $(ARM_FPA_LD_CROSS)$(EXESUF): DEFINES = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
187 $(ARM_VFP_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_VFP
188 $(ARM_EABI_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_EABI
190 $(I386_CROSS): $(I386_FILES)
191 $(X64_CROSS): $(X86_64_FILES)
192 $(WIN32_CROSS): $(WIN32_FILES)
193 $(WIN64_CROSS): $(WIN64_FILES)
194 $(WINCE_CROSS): $(WINCE_FILES)
195 $(C67_CROSS): $(C67_FILES)
196 $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS): $(ARM_FILES)
198 # libtcc generation and test
199 ifndef ONE_SOURCE
200 LIBTCC_OBJ = $(filter-out tcc.o,$(patsubst %.c,%.o,$(filter %.c,$(NATIVE_FILES))))
201 LIBTCC_INC = $(filter %.h,$(CORE_FILES)) $(filter-out $(CORE_FILES),$(NATIVE_FILES))
202 else
203 LIBTCC_OBJ = libtcc.o
204 LIBTCC_INC = $(NATIVE_FILES)
205 libtcc.o : NATIVE_DEFINES += -DONE_SOURCE
206 endif
208 $(LIBTCC_OBJ) tcc.o : %.o : %.c $(LIBTCC_INC)
209 $(CC) -o $@ -c $< $(NATIVE_DEFINES) $(CPPFLAGS) $(CFLAGS)
211 libtcc.a: $(LIBTCC_OBJ)
212 $(AR) rcs $@ $^
214 libtcc.so.1.0: $(LIBTCC_OBJ)
215 $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDFLAGS)
217 libtcc.so.1.0: CFLAGS+=-fPIC
219 # profiling version
220 tcc_p$(EXESUF): $(NATIVE_FILES)
221 $(CC) -o $@ $< $(NATIVE_DEFINES) $(CPPFLAGS_P) $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P)
223 # windows utilities
224 tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
225 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
226 tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
227 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
229 # TinyCC runtime libraries
230 libtcc1.a : FORCE
231 @$(MAKE) -C lib native
232 lib/%/libtcc1.a : FORCE $(PROGS_CROSS)
233 @$(MAKE) -C lib cross TARGET=$*
234 bcheck.o : lib/bcheck.c
235 gcc -c $< -o $@ $(CPPFLAGS) $(CFLAGS)
236 FORCE:
238 # install
239 TCC_INCLUDES = stdarg.h stddef.h stdbool.h float.h varargs.h tcclib.h
240 INSTALL=install
241 ifdef STRIP_BINARIES
242 INSTALLBIN=$(INSTALL) -s
243 else
244 INSTALLBIN=$(INSTALL)
245 endif
247 ifndef CONFIG_WIN32
248 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
249 mkdir -p "$(bindir)"
250 ifeq ($(CC),tcc)
251 $(INSTALL) -m755 $(PROGS) "$(bindir)"
252 else
253 $(INSTALLBIN) -m755 $(PROGS) "$(bindir)"
254 endif
255 mkdir -p "$(mandir)/man1"
256 -$(INSTALL) tcc.1 "$(mandir)/man1"
257 mkdir -p "$(infodir)"
258 -$(INSTALL) tcc-doc.info "$(infodir)"
259 mkdir -p "$(tccdir)"
260 mkdir -p "$(tccdir)/include"
261 ifneq ($(LIBTCC1),)
262 $(INSTALL) -m644 $(LIBTCC1) "$(tccdir)"
263 endif
264 ifneq ($(BCHECK_O),)
265 $(INSTALL) -m644 $(BCHECK_O) "$(tccdir)"
266 endif
267 $(INSTALL) -m644 $(addprefix $(top_srcdir)/include/,$(TCC_INCLUDES)) "$(tccdir)/include"
268 mkdir -p "$(libdir)"
269 $(INSTALL) -m755 $(LIBTCC) "$(libdir)"
270 ifdef DISABLE_STATIC
271 ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so.1"
272 ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so"
273 endif
274 mkdir -p "$(includedir)"
275 $(INSTALL) -m644 $(top_srcdir)/libtcc.h "$(includedir)"
276 mkdir -p "$(docdir)"
277 -$(INSTALL) -m644 tcc-doc.html "$(docdir)"
278 ifdef CONFIG_CROSS
279 mkdir -p "$(tccdir)/win32/lib/32"
280 mkdir -p "$(tccdir)/win32/lib/64"
281 ifeq ($(ARCH),x86-64)
282 mkdir -p "$(tccdir)/i386"
283 $(INSTALL) -m644 lib/i386/libtcc1.a "$(tccdir)/i386"
284 cp -r "$(tccdir)/include" "$(tccdir)/i386"
285 endif
286 $(INSTALL) -m644 win32/lib/*.def "$(tccdir)/win32/lib"
287 $(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/win32/lib/32"
288 $(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/win32/lib/64"
289 cp -r win32/include/. "$(tccdir)/win32/include"
290 cp -r include/. "$(tccdir)/win32/include"
291 endif
293 uninstall:
294 rm -fv $(foreach P,$(PROGS),"$(bindir)/$P")
295 rm -fv $(foreach P,$(LIBTCC1) $(BCHECK_O),"$(tccdir)/$P")
296 rm -fv $(foreach P,$(TCC_INCLUDES),"$(tccdir)/include/$P")
297 rm -fv "$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
298 rm -fv "$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
299 rm -fv "$(libdir)/libtcc.so*"
300 rm -rf "$(tccdir)/win32"
301 -rmdir $(tccdir)/include
302 ifeq ($(ARCH),x86-64)
303 rm -rf "$(tccdir)/i386"
304 endif
305 else
306 # on windows
307 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
308 mkdir -p "$(tccdir)"
309 mkdir -p "$(tccdir)/lib"
310 mkdir -p "$(tccdir)/include"
311 mkdir -p "$(tccdir)/examples"
312 mkdir -p "$(tccdir)/doc"
313 mkdir -p "$(tccdir)/libtcc"
314 $(INSTALLBIN) -m755 $(PROGS) "$(tccdir)"
315 $(INSTALL) -m644 $(LIBTCC1) win32/lib/*.def "$(tccdir)/lib"
316 cp -r win32/include/. "$(tccdir)/include"
317 cp -r win32/examples/. "$(tccdir)/examples"
318 $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
319 $(INSTALL) -m644 tcc-doc.html win32/tcc-win32.txt "$(tccdir)/doc"
320 $(INSTALL) -m644 $(LIBTCC) libtcc.h "$(tccdir)/libtcc"
321 ifdef CONFIG_CROSS
322 mkdir -p "$(tccdir)/lib/32"
323 mkdir -p "$(tccdir)/lib/64"
324 -$(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/lib/32"
325 -$(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/lib/64"
326 endif
328 uninstall:
329 rm -rfv "$(tccdir)/*"
330 endif
332 # documentation and man page
333 tcc-doc.html: tcc-doc.texi
334 -texi2html -monolithic -number $<
336 tcc.1: tcc-doc.texi
337 -$(top_srcdir)/texi2pod.pl $< tcc.pod
338 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@
340 tcc-doc.info: tcc-doc.texi
341 -makeinfo $<
343 # in tests subdir
344 export LIBTCC1
346 %est:
347 $(MAKE) -C tests2 $@
348 $(MAKE) -C tests $@
350 clean:
351 rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.so* *.out *.exe libtcc_test$(EXESUF)
352 $(MAKE) -C tests2 $@
353 $(MAKE) -C tests $@
354 ifneq ($(LIBTCC1),)
355 $(MAKE) -C lib $@
356 endif
358 distclean: clean
359 rm -vf config.h config.mak config.texi tcc.1 tcc-doc.info tcc-doc.html
361 config.mak:
362 @echo "Please run ./configure."
363 @exit 1
365 # create release tarball from *current* git branch (including tcc-doc.html
366 # and converting two files to CRLF)
367 TCC-VERSION := tcc-$(shell cat $(top_srcdir)/VERSION)
368 tar: tcc-doc.html
369 mkdir $(TCC-VERSION)
370 ( cd $(TCC-VERSION) && git --git-dir ../.git checkout -f )
371 cp tcc-doc.html $(TCC-VERSION)
372 for f in tcc-win32.txt build-tcc.bat ; do \
373 cat win32/$$f | sed 's,\(.*\),\1\r,g' > $(TCC-VERSION)/win32/$$f ; \
374 done
375 tar cjf $(TCC-VERSION).tar.bz2 $(TCC-VERSION)
376 rm -rf $(TCC-VERSION)
377 git reset
380 .PHONY: all clean tar distclean install uninstall FORCE
382 endif # ifeq ($(TOP),.)