tccasm: support .weak labels
[tinycc.git] / Makefile
blob2d13d1ecebda3630a3ac98d99d4245462b34d761
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 ifdef CONFIG_WIN64
29 CONFIG_WIN32=yes
30 endif
32 ifndef CONFIG_WIN32
33 LIBS=-lm
34 ifndef CONFIG_NOLDL
35 LIBS+=-ldl
36 endif
37 endif
39 ifeq ($(ARCH),i386)
40 NATIVE_DEFINES=-DTCC_TARGET_I386
41 else
42 ifeq ($(ARCH),x86-64)
43 NATIVE_DEFINES=-DTCC_TARGET_X86_64
44 NATIVE_DEFINES+=$(if $(wildcard /lib64/ld-linux-x86-64.so.2),-DTCC_TARGET_X86_64_CENTOS)
45 endif
46 endif
48 ifeq ($(ARCH),arm)
49 NATIVE_DEFINES=-DTCC_TARGET_ARM
50 NATIVE_DEFINES+=-DWITHOUT_LIBTCC
51 NATIVE_DEFINES+=$(if $(wildcard /lib/ld-linux.so.3),-DTCC_ARM_EABI)
52 NATIVE_DEFINES+=$(if $(shell grep -l "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo),-DTCC_ARM_VFP)
53 endif
55 ifdef CONFIG_WIN32
56 NATIVE_DEFINES+=-DTCC_TARGET_PE
57 endif
59 ifneq ($(wildcard /lib/ld-uClibc.so.0),)
60 NATIVE_DEFINES+=-DTCC_UCLIBC
61 CONFIG_UCLIBC = 1
62 endif
64 # make libtcc as static or dynamic library?
65 ifdef DISABLE_STATIC
66 LIBTCC=libtcc.so.1.0
67 LINK_LIBTCC=-Wl,-rpath,"$(libdir)"
68 ifdef DISABLE_RPATH
69 LINK_LIBTCC=
70 endif
71 else
72 LIBTCC=libtcc.a
73 LINK_LIBTCC=
74 endif
76 ifeq ($(TOP),.)
78 PROGS=tcc$(EXESUF)
79 I386_CROSS = i386-tcc$(EXESUF)
80 WIN32_CROSS = i386-win32-tcc$(EXESUF)
81 WIN64_CROSS = x86_64-win32-tcc$(EXESUF)
82 WINCE_CROSS = arm-win32-tcc$(EXESUF)
83 X64_CROSS = x86_64-tcc$(EXESUF)
84 ARM_FPA_CROSS = arm-fpa-tcc$(EXESUF)
85 ARM_FPA_LD_CROSS = arm-fpa-ld-tcc$(EXESUF)
86 ARM_VFP_CROSS = arm-vfp-tcc$(EXESUF)
87 ARM_EABI_CROSS = arm-eabi-tcc$(EXESUF)
88 ARM_CROSS = $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS)
89 C67_CROSS = c67-tcc$(EXESUF)
91 CORE_FILES = tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
92 CORE_FILES += tcc.h config.h libtcc.h tcctok.h
93 I386_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h
94 WIN32_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
95 WIN64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h tccpe.c
96 WINCE_FILES = $(CORE_FILES) arm-gen.c tccpe.c
97 X86_64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h
98 ARM_FILES = $(CORE_FILES) arm-gen.c
99 C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c
101 ifdef CONFIG_WIN64
102 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
103 NATIVE_FILES=$(WIN64_FILES)
104 PROGS_CROSS=$(WIN32_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
105 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a
106 LIBTCC1=libtcc1.a
107 else
108 ifdef CONFIG_WIN32
109 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
110 NATIVE_FILES=$(WIN32_FILES)
111 PROGS_CROSS=$(WIN64_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
112 LIBTCC1_CROSS=lib/x86_64-win32/libtcc1.a
113 LIBTCC1=libtcc1.a
114 else
115 ifeq ($(ARCH),i386)
116 NATIVE_FILES=$(I386_FILES)
117 PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
118 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a
119 LIBTCC1=libtcc1.a
120 BCHECK_O=bcheck.o
121 else
122 ifeq ($(ARCH),x86-64)
123 NATIVE_FILES=$(X86_64_FILES)
124 PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
125 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a lib/i386/libtcc1.a
126 LIBTCC1=libtcc1.a
127 else
128 ifeq ($(ARCH),arm)
129 NATIVE_FILES=$(ARM_FILES)
130 PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(C67_CROSS)
131 endif
132 endif
133 endif
134 endif
135 endif
137 ifdef CONFIG_UCLIBC
138 BCHECK_O=
139 endif
141 ifdef CONFIG_USE_LIBGCC
142 LIBTCC1=
143 endif
145 TCCLIBS = $(LIBTCC1) $(LIBTCC) $(BCHECK_O)
146 TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info
148 ifdef CONFIG_CROSS
149 PROGS+=$(PROGS_CROSS)
150 TCCLIBS+=$(LIBTCC1_CROSS)
151 endif
153 all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
155 # Host Tiny C Compiler
156 tcc$(EXESUF): tcc.o $(LIBTCC)
157 $(CC) -o $@ $^ $(LIBS) $(LDFLAGS) $(LINK_LIBTCC)
159 # Cross Tiny C Compilers
160 %-tcc$(EXESUF):
161 $(CC) -o $@ tcc.c $(DEFINES) $(CFLAGS) $(LIBS) $(LDFLAGS)
163 $(I386_CROSS): DEFINES = -DTCC_TARGET_I386 -DCONFIG_TCCDIR="\"$(tccdir)/i386\""
164 $(X64_CROSS): DEFINES = -DTCC_TARGET_X86_64
165 $(WIN32_CROSS): DEFINES = -DTCC_TARGET_I386 -DTCC_TARGET_PE -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" -DCONFIG_TCC_CROSSLIB="\"lib/32\""
166 $(WIN64_CROSS): DEFINES = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" -DCONFIG_TCC_CROSSLIB="\"lib/64\""
167 $(WINCE_CROSS): DEFINES = -DTCC_TARGET_PE
168 $(C67_CROSS): DEFINES = -DTCC_TARGET_C67
169 $(ARM_FPA_CROSS): DEFINES = -DTCC_TARGET_ARM
170 $(ARM_FPA_LD_CROSS)$(EXESUF): DEFINES = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
171 $(ARM_VFP_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_VFP
172 $(ARM_EABI_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_EABI
174 $(I386_CROSS): $(I386_FILES)
175 $(X64_CROSS): $(X86_64_FILES)
176 $(WIN32_CROSS): $(WIN32_FILES)
177 $(WIN64_CROSS): $(WIN64_FILES)
178 $(WINCE_CROSS): $(WINCE_FILES)
179 $(C67_CROSS): $(C67_FILES)
180 $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS): $(ARM_FILES)
182 # libtcc generation and test
183 ifdef NOTALLINONE
184 LIBTCC_OBJ = $(filter-out tcc.o,$(patsubst %.c,%.o,$(filter %.c,$(NATIVE_FILES))))
185 LIBTCC_INC = $(filter %.h,$(CORE_FILES)) $(filter-out $(CORE_FILES),$(NATIVE_FILES))
186 $(LIBTCC_OBJ) tcc.o : NATIVE_DEFINES += -DNOTALLINONE
187 else
188 LIBTCC_OBJ = libtcc.o
189 LIBTCC_INC = $(NATIVE_FILES)
190 tcc.o : NATIVE_DEFINES += -DNOTALLINONE
191 endif
193 $(LIBTCC_OBJ) tcc.o : %.o : %.c $(LIBTCC_INC)
194 $(CC) -o $@ -c $< $(NATIVE_DEFINES) $(CFLAGS)
196 libtcc.a: $(LIBTCC_OBJ)
197 $(AR) rcs $@ $^
199 libtcc.so.1.0: $(LIBTCC_OBJ)
200 $(CC) -shared -Wl,-soname,$@ -o $@ $^
202 libtcc.so.1.0: CFLAGS+=-fPIC
204 # profiling version
205 tcc_p$(EXESUF): $(NATIVE_FILES)
206 $(CC) -o $@ $< $(NATIVE_DEFINES) $(CFLAGS_P) $(LIBS_P)
208 # windows utilities
209 tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
210 $(CC) -o $@ $< $(CFLAGS)
211 tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
212 $(CC) -o $@ $< $(CFLAGS)
214 # TinyCC runtime libraries
215 libtcc1.a : FORCE
216 @$(MAKE) -C lib native
217 lib/%/libtcc1.a : FORCE $(PROGS_CROSS)
218 @$(MAKE) -C lib cross TARGET=$*
219 bcheck.o : lib/bcheck.c
220 gcc -c $< -o $@ -O2 -Wall
221 FORCE:
223 # install
224 TCC_INCLUDES = stdarg.h stddef.h stdbool.h float.h varargs.h tcclib.h
225 INSTALL=install
227 ifndef CONFIG_WIN32
228 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
229 mkdir -p "$(bindir)"
230 ifeq ($(CC),tcc)
231 $(INSTALL) -m755 $(PROGS) "$(bindir)"
232 else
233 $(INSTALL) -s -m755 $(PROGS) "$(bindir)"
234 endif
235 mkdir -p "$(mandir)/man1"
236 -$(INSTALL) tcc.1 "$(mandir)/man1"
237 mkdir -p "$(infodir)"
238 -$(INSTALL) tcc-doc.info "$(infodir)"
239 mkdir -p "$(tccdir)"
240 mkdir -p "$(tccdir)/include"
241 ifneq ($(LIBTCC1),)
242 $(INSTALL) -m644 $(LIBTCC1) "$(tccdir)"
243 endif
244 ifneq ($(BCHECK_O),)
245 $(INSTALL) -m644 $(BCHECK_O) "$(tccdir)"
246 endif
247 $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
248 mkdir -p "$(libdir)"
249 $(INSTALL) -m755 $(LIBTCC) "$(libdir)"
250 ifdef DISABLE_STATIC
251 ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so.1"
252 ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so"
253 endif
254 mkdir -p "$(includedir)"
255 $(INSTALL) -m644 libtcc.h "$(includedir)"
256 mkdir -p "$(docdir)"
257 -$(INSTALL) -m644 tcc-doc.html "$(docdir)"
258 ifdef CONFIG_CROSS
259 mkdir -p "$(tccdir)/win32/lib/32"
260 mkdir -p "$(tccdir)/win32/lib/64"
261 ifeq ($(ARCH),x86-64)
262 mkdir -p "$(tccdir)/i386"
263 $(INSTALL) -m644 lib/i386/libtcc1.a "$(tccdir)/i386"
264 cp -r "$(tccdir)/include" "$(tccdir)/i386"
265 endif
266 $(INSTALL) -m644 win32/lib/*.def "$(tccdir)/win32/lib"
267 $(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/win32/lib/32"
268 $(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/win32/lib/64"
269 cp -r win32/include/. "$(tccdir)/win32/include"
270 cp -r include/. "$(tccdir)/win32/include"
271 endif
273 uninstall:
274 rm -fv $(foreach P,$(PROGS),"$(bindir)/$P")
275 rm -fv $(foreach P,$(LIBTCC1) $(BCHECK_O),"$(tccdir)/$P")
276 rm -fv $(foreach P,$(TCC_INCLUDES),"$(tccdir)/include/$P")
277 rm -fv "$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
278 rm -fv "$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
279 rm -fv "$(libdir)/libtcc.so*"
280 rm -rf "$(tccdir)/win32"
281 -rmdir $(tccdir)/include
282 ifeq ($(ARCH),x86-64)
283 rm -rf "$(tccdir)/i386"
284 endif
285 else
286 # on windows
287 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
288 mkdir -p "$(tccdir)"
289 mkdir -p "$(tccdir)/lib"
290 mkdir -p "$(tccdir)/include"
291 mkdir -p "$(tccdir)/examples"
292 mkdir -p "$(tccdir)/doc"
293 mkdir -p "$(tccdir)/libtcc"
294 $(INSTALL) -s -m755 $(PROGS) "$(tccdir)"
295 $(INSTALL) -m644 $(LIBTCC1) win32/lib/*.def "$(tccdir)/lib"
296 cp -r win32/include/. "$(tccdir)/include"
297 cp -r win32/examples/. "$(tccdir)/examples"
298 $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) "$(tccdir)/include"
299 $(INSTALL) -m644 tcc-doc.html win32/tcc-win32.txt "$(tccdir)/doc"
300 $(INSTALL) -m644 $(LIBTCC) libtcc.h "$(tccdir)/libtcc"
301 ifdef CONFIG_CROSS
302 mkdir -p "$(tccdir)/lib/32"
303 mkdir -p "$(tccdir)/lib/64"
304 -$(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/lib/32"
305 -$(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/lib/64"
306 endif
308 uninstall:
309 rm -rfv "$(tccdir)/*"
310 endif
312 # documentation and man page
313 tcc-doc.html: tcc-doc.texi
314 -texi2html -monolithic -number $<
316 tcc.1: tcc-doc.texi
317 -./texi2pod.pl $< tcc.pod
318 -pod2man --section=1 --center=" " --release=" " tcc.pod > $@
320 tcc-doc.info: tcc-doc.texi
321 -makeinfo tcc-doc.texi
323 .PHONY: all clean tar distclean install uninstall FORCE
325 # tar release (use 'make -k tar' on a checkouted tree)
326 TCC-VERSION=tcc-$(shell cat VERSION)
327 tar:
328 rm -rf /tmp/$(TCC-VERSION)
329 cp -r . /tmp/$(TCC-VERSION)
330 ( cd /tmp ; tar zcvf ~/$(TCC-VERSION).tar.gz $(TCC-VERSION) --exclude CVS )
331 rm -rf /tmp/$(TCC-VERSION)
333 # in tests subdir
334 %est:
335 $(MAKE) -C tests $@
337 clean:
338 rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.so* *.out *.exe libtcc_test$(EXESUF)
339 $(MAKE) -C tests $@
340 $(MAKE) -C lib $@
342 distclean: clean
343 rm -vf config.h config.mak config.texi tcc.1 tcc-doc.info tcc-doc.html
345 config.mak:
346 @echo "Please run ./configure."
347 @exit 1
349 endif # ifeq ($(TOP),.)