win64: Use tcc's own assembler
[tinycc.git] / Makefile
blob131b42a06739605989537088b376178a8cc5345c
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 WINCE_CROSS = arm-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 i386-tok.h
84 WIN32_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
85 WIN64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-asm.c x86_64-asm.h x86_64-tok.h tccpe.c
86 WINCE_FILES = $(CORE_FILES) arm-gen.c tccpe.c
87 X86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-asm.c x86_64-asm.h x86_64-tok.h
88 ARM_FILES = $(CORE_FILES) arm-gen.c
89 C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c
91 ifdef CONFIG_WIN32
92 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
93 NATIVE_FILES=$(WIN32_FILES)
94 PROGS_CROSS=$(WIN64_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
95 else
96 ifeq ($(ARCH),i386)
97 NATIVE_FILES=$(I386_FILES)
98 PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
99 else
100 ifeq ($(ARCH),x86-64)
101 NATIVE_FILES=$(X86_64_FILES)
102 PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
103 else
104 ifeq ($(ARCH),arm)
105 NATIVE_FILES=$(ARM_FILES)
106 PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(C67_CROSS)
107 endif
108 endif
109 endif
110 endif
112 ifdef CONFIG_CROSS
113 PROGS+=$(PROGS_CROSS)
114 endif
116 all: $(PROGS) $(LIBTCC1) $(BCHECK_O) libtcc.a tcc-doc.html tcc.1 libtcc_test$(EXESUF)
118 # Host Tiny C Compiler
119 tcc$(EXESUF): $(NATIVE_FILES)
120 $(CC) -o $@ $< $(NATIVE_TARGET) $(CFLAGS) $(LIBS)
122 # Cross Tiny C Compilers
123 i386-tcc$(EXESUF): $(I386_FILES)
124 $(CC) -o $@ $< -DTCC_TARGET_I386 $(CFLAGS) $(LIBS)
126 i386-win32-tcc$(EXESUF): $(WIN32_FILES)
127 $(CC) -o $@ $< -DTCC_TARGET_PE $(CFLAGS) $(LIBS)
129 x86_64-win32-tcc$(EXESUF): $(WIN32_FILES)
130 $(CC) -o $@ $< -DTCC_TARGET_PE -DTCC_TARGET_X86_64 $(CFLAGS) $(LIBS)
132 x86_64-tcc$(EXESUF): $(X86_64_FILES)
133 $(CC) -o $@ $< -DTCC_TARGET_X86_64 $(CFLAGS) $(LIBS)
135 c67-tcc$(EXESUF): $(C67_FILES)
136 $(CC) -o $@ $< -DTCC_TARGET_C67 $(CFLAGS) $(LIBS)
138 arm-win32-tcc$(EXESUF): $(WIN32_FILES)
139 $(CC) -o $@ $< -DTCC_TARGET_PE -DTCC_TARGET_ARM $(CFLAGS) $(LIBS)
141 arm-tcc-fpa$(EXESUF): $(ARM_FILES)
142 $(CC) -o $@ $< -DTCC_TARGET_ARM $(CFLAGS) $(LIBS)
144 arm-tcc-fpa-ld$(EXESUF): $(ARM_FILES)
145 $(CC) -o $@ $< -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12 $(CFLAGS) $(LIBS)
147 arm-tcc-vfp$(EXESUF): $(ARM_FILES)
148 $(CC) -o $@ $< -DTCC_TARGET_ARM -DTCC_ARM_VFP $(CFLAGS) $(LIBS)
150 arm-tcc-vfp-eabi$(EXESUF): $(ARM_FILES)
151 $(CC) -o $@ $< -DTCC_TARGET_ARM -DTCC_ARM_EABI $(CFLAGS) $(LIBS)
153 # libtcc generation and test
154 libtcc.o: $(NATIVE_FILES)
155 $(CC) -o $@ -c libtcc.c $(NATIVE_TARGET) $(CFLAGS)
157 libtcc.a: libtcc.o
158 $(AR) rcs $@ $^
160 libtcc_test$(EXESUF): tests/libtcc_test.c libtcc.a
161 $(CC) -o $@ $^ -I. $(CFLAGS) $(LIBS)
163 libtest: libtcc_test$(EXESUF) $(LIBTCC1)
164 ./libtcc_test$(EXESUF) lib_path=.
166 # profiling version
167 tcc_p$(EXESUF): $(NATIVE_FILES)
168 $(CC) -o $@ $< $(NATIVE_TARGET) $(CFLAGS_P) $(LIBS_P)
170 # windows utilities
171 tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
172 $(CC) -o $@ $< $(CFLAGS)
173 tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
174 $(CC) -o $@ $< $(CFLAGS)
176 # TinyCC runtime libraries
177 LIBTCC1_OBJS=libtcc1.o $(ALLOCA_O)
178 LIBTCC1_CC=$(CC)
179 VPATH+=lib
181 ifdef CONFIG_WIN32
182 # for windows, we must use TCC because we generate ELF objects
183 LIBTCC1_OBJS+=crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o
184 LIBTCC1_CC=./tcc.exe -Bwin32 -Iinclude $(NATIVE_TARGET)
185 VPATH+=win32/lib
186 endif
188 %.o: %.c
189 $(LIBTCC1_CC) -o $@ -c $< -O2 -Wall
190 %.o: %.S
191 $(LIBTCC1_CC) -o $@ -c $<
193 libtcc1.a: $(LIBTCC1_OBJS)
194 $(AR) rcs $@ $^
196 bcheck.o: bcheck.c
197 $(CC) -o $@ -c $< -O2 -Wall
199 # install
200 TCC_INCLUDES = stdarg.h stddef.h stdbool.h float.h varargs.h tcclib.h
201 INSTALL=install
203 ifndef CONFIG_WIN32
204 install: $(PROGS) $(LIBTCC1) $(BCHECK_O) libtcc.a tcc.1 tcc-doc.html
205 mkdir -p "$(bindir)"
206 $(INSTALL) -s -m755 $(PROGS) "$(bindir)"
207 mkdir -p "$(mandir)/man1"
208 $(INSTALL) tcc.1 "$(mandir)/man1"
209 mkdir -p "$(tccdir)"
210 mkdir -p "$(tccdir)/include"
211 ifneq ($(LIBTCC1),)
212 $(INSTALL) -m644 $(LIBTCC1) "$(tccdir)"
213 endif
214 ifneq ($(BCHECK_O),)
215 $(INSTALL) -m644 $(BCHECK_O) "$(tccdir)"
216 endif
217 $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
218 mkdir -p "$(docdir)"
219 $(INSTALL) -m644 tcc-doc.html "$(docdir)"
220 mkdir -p "$(libdir)"
221 $(INSTALL) -m644 libtcc.a "$(libdir)"
222 mkdir -p "$(includedir)"
223 $(INSTALL) -m644 libtcc.h "$(includedir)"
225 uninstall:
226 rm -fv $(foreach P,$(PROGS),"$(bindir)/$P")
227 rm -fv $(foreach P,$(LIBTCC1) $(BCHECK_O),"$(tccdir)/$P")
228 rm -fv $(foreach P,$(TCC_INCLUDES),"$(tccdir)/include/$P")
229 rm -fv "$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1"
230 rm -fv "$(libdir)/libtcc.a" "$(includedir)/libtcc.h"
232 else
233 install: $(PROGS) $(LIBTCC1) libtcc.a tcc-doc.html
234 mkdir -p "$(tccdir)"
235 mkdir -p "$(tccdir)/lib"
236 mkdir -p "$(tccdir)/include"
237 mkdir -p "$(tccdir)/examples"
238 mkdir -p "$(tccdir)/doc"
239 mkdir -p "$(tccdir)/libtcc"
240 $(INSTALL) -s -m755 $(PROGS) "$(tccdir)"
241 $(INSTALL) -m644 $(LIBTCC1) win32/lib/*.def "$(tccdir)/lib"
242 cp -r win32/include/. "$(tccdir)/include"
243 cp -r win32/examples/. "$(tccdir)/examples"
244 $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
245 $(INSTALL) -m644 tcc-doc.html win32/tcc-win32.txt "$(tccdir)/doc"
246 $(INSTALL) -m644 libtcc.a libtcc.h "$(tccdir)/libtcc"
247 endif
249 # documentation and man page
250 tcc-doc.html: tcc-doc.texi
251 -texi2html -monolithic -number $<
253 tcc.1: tcc-doc.texi
254 -./texi2pod.pl $< tcc.pod
255 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@
257 # tar release (use 'make -k tar' on a checkouted tree)
258 TCC-VERSION=tcc-$(shell cat VERSION)
259 tar:
260 rm -rf /tmp/$(TCC-VERSION)
261 cp -r . /tmp/$(TCC-VERSION)
262 ( cd /tmp ; tar zcvf ~/$(TCC-VERSION).tar.gz $(TCC-VERSION) --exclude CVS )
263 rm -rf /tmp/$(TCC-VERSION)
265 # in tests subdir
266 test clean:
267 $(MAKE) -C tests $@
269 config.mak:
270 @echo Running configure ...
271 @./configure
273 # clean
274 clean: local_clean
275 local_clean:
276 rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.out libtcc_test$(EXESUF)
278 distclean: clean
279 rm -vf config.h config.mak config.texi tcc.1
281 endif # ifeq ($(TOP),.)