Fixed problems with XMM1 use on Linux/x86-64.
[tinycc.git] / Makefile
blobf487fbf04da3d051c1f422bc4da778bac53e3613
2 # Tiny C Compiler Makefile
5 TOP ?= .
6 include $(TOP)/config.mak
7 VPATH = $(top_srcdir)
9 CPPFLAGS = -I$(TOP) # for config.h
11 ifeq (-$(findstring gcc,$(CC))-,-gcc-)
12 ifeq (-$(findstring $(GCC_MAJOR),01)-,--)
13 CFLAGS+=-fno-strict-aliasing
14 ifeq (-$(findstring $(GCC_MAJOR),23)-,--)
15 CFLAGS+=-Wno-pointer-sign -Wno-sign-compare
16 ifeq (-$(GCC_MAJOR)-$(findstring $(GCC_MINOR),56789)-,-4--)
17 CFLAGS+=-D_FORTIFY_SOURCE=0
18 else
19 CFLAGS+=-Wno-unused-result
20 endif
21 endif
22 endif
23 else # not GCC
24 ifeq (-$(findstring clang,$(CC))-,-clang-)
25 # make clang accept gnuisms in libtcc1.c
26 CFLAGS+=-fheinous-gnu-extensions
27 endif
28 endif
30 CPPFLAGS_P=$(CPPFLAGS) -DCONFIG_TCC_STATIC
31 CFLAGS_P=$(CFLAGS) -pg -static
32 LIBS_P=
33 LDFLAGS_P=$(LDFLAGS)
35 ifdef CONFIG_WIN64
36 CONFIG_WIN32=yes
37 endif
39 ifndef CONFIG_WIN32
40 LIBS=-lm
41 ifndef CONFIG_NOLDL
42 LIBS+=-ldl
43 endif
44 endif
46 # make libtcc as static or dynamic library?
47 ifdef DISABLE_STATIC
48 ifndef CONFIG_WIN32
49 LIBTCC=libtcc.so.1.0
50 else
51 LIBTCC=libtcc.dll
52 LIBTCC_DLL=yes
53 LIBTCC_EXTRA=libtcc.def libtcc.a
54 endif
55 LINK_LIBTCC=-Wl,-rpath,"$(libdir)"
56 ifdef DISABLE_RPATH
57 LINK_LIBTCC=
58 endif
59 else
60 LIBTCC=libtcc.a
61 LINK_LIBTCC=
62 endif
64 CONFIG_$(ARCH) = yes
65 NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
66 NATIVE_DEFINES_$(CONFIG_x86-64) += -DTCC_TARGET_X86_64
67 NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE
68 NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC
69 NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM -DWITHOUT_LIBTCC
70 NATIVE_DEFINES_$(CONFIG_arm_eabihf) += -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT
71 NATIVE_DEFINES_$(CONFIG_arm_eabi) += -DTCC_ARM_EABI
72 NATIVE_DEFINES_$(CONFIG_arm_vfp) += -DTCC_ARM_VFP
73 NATIVE_DEFINES += $(NATIVE_DEFINES_yes)
75 ifeq ($(TOP),.)
77 PROGS=tcc$(EXESUF)
78 I386_CROSS = i386-tcc$(EXESUF)
79 WIN32_CROSS = i386-win32-tcc$(EXESUF)
80 WIN64_CROSS = x86_64-win32-tcc$(EXESUF)
81 WINCE_CROSS = arm-win32-tcc$(EXESUF)
82 X64_CROSS = x86_64-tcc$(EXESUF)
83 ARM_FPA_CROSS = arm-fpa-tcc$(EXESUF)
84 ARM_FPA_LD_CROSS = arm-fpa-ld-tcc$(EXESUF)
85 ARM_VFP_CROSS = arm-vfp-tcc$(EXESUF)
86 ARM_EABI_CROSS = arm-eabi-tcc$(EXESUF)
87 ARM_CROSS = $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS)
88 C67_CROSS = c67-tcc$(EXESUF)
90 CORE_FILES = tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
91 CORE_FILES += tcc.h config.h libtcc.h tcctok.h
92 I386_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h
93 WIN32_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
94 WIN64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h tccpe.c
95 WINCE_FILES = $(CORE_FILES) arm-gen.c tccpe.c
96 X86_64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h
97 ARM_FILES = $(CORE_FILES) arm-gen.c
98 C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c
100 ifdef CONFIG_WIN64
101 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
102 NATIVE_FILES=$(WIN64_FILES)
103 PROGS_CROSS=$(WIN32_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
104 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a
105 LIBTCC1=libtcc1.a
106 else ifdef CONFIG_WIN32
107 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
108 NATIVE_FILES=$(WIN32_FILES)
109 PROGS_CROSS=$(WIN64_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
110 LIBTCC1_CROSS=lib/x86_64-win32/libtcc1.a
111 LIBTCC1=libtcc1.a
112 else ifeq ($(ARCH),i386)
113 NATIVE_FILES=$(I386_FILES)
114 PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
115 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a
116 LIBTCC1=libtcc1.a
117 else ifeq ($(ARCH),x86-64)
118 NATIVE_FILES=$(X86_64_FILES)
119 PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
120 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a lib/i386/libtcc1.a
121 LIBTCC1=libtcc1.a
122 else ifeq ($(ARCH),arm)
123 NATIVE_FILES=$(ARM_FILES)
124 PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(C67_CROSS)
125 endif
127 ifeq ($(TARGETOS),Darwin)
128 PROGS+=tiny_libmaker$(EXESUF)
129 endif
131 ifdef CONFIG_USE_LIBGCC
132 LIBTCC1=
133 endif
135 TCCLIBS = $(LIBTCC1) $(LIBTCC) $(LIBTCC_EXTRA)
136 TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info
138 ifdef CONFIG_CROSS
139 PROGS+=$(PROGS_CROSS)
140 TCCLIBS+=$(LIBTCC1_CROSS)
141 endif
143 all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
145 # Host Tiny C Compiler
146 tcc$(EXESUF): tcc.o $(LIBTCC)
147 $(CC) -o $@ $^ $(LIBS) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(LINK_LIBTCC)
149 # Cross Tiny C Compilers
150 %-tcc$(EXESUF): tcc.c
151 $(CC) -o $@ $< -DONE_SOURCE $(DEFINES) $(CPPFLAGS) $(CFLAGS) $(LIBS) $(LDFLAGS)
153 # profiling version
154 tcc_p$(EXESUF): $(NATIVE_FILES)
155 $(CC) -o $@ $< -DONE_SOURCE $(NATIVE_DEFINES) $(CPPFLAGS_P) $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P)
157 $(I386_CROSS): DEFINES = -DTCC_TARGET_I386 \
158 -DCONFIG_TCCDIR="\"$(tccdir)/i386\""
159 $(X64_CROSS): DEFINES = -DTCC_TARGET_X86_64
160 $(WIN32_CROSS): DEFINES = -DTCC_TARGET_I386 -DTCC_TARGET_PE \
161 -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
162 -DCONFIG_TCC_LIBPATHS="\"{B}/lib/32;{B}/lib\""
163 $(WIN64_CROSS): DEFINES = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE \
164 -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
165 -DCONFIG_TCC_LIBPATHS="\"{B}/lib/64;{B}/lib\""
166 $(WINCE_CROSS): DEFINES = -DTCC_TARGET_PE
167 $(C67_CROSS): DEFINES = -DTCC_TARGET_C67
168 $(ARM_FPA_CROSS): DEFINES = -DTCC_TARGET_ARM
169 $(ARM_FPA_LD_CROSS)$(EXESUF): DEFINES = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
170 $(ARM_VFP_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_VFP
171 $(ARM_EABI_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_EABI
173 $(I386_CROSS): $(I386_FILES)
174 $(X64_CROSS): $(X86_64_FILES)
175 $(WIN32_CROSS): $(WIN32_FILES)
176 $(WIN64_CROSS): $(WIN64_FILES)
177 $(WINCE_CROSS): $(WINCE_FILES)
178 $(C67_CROSS): $(C67_FILES)
179 $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS): $(ARM_FILES)
181 # libtcc generation and test
182 ifndef ONE_SOURCE
183 LIBTCC_OBJ = $(filter-out tcc.o,$(patsubst %.c,%.o,$(filter %.c,$(NATIVE_FILES))))
184 LIBTCC_INC = $(filter %.h,$(CORE_FILES)) $(filter-out $(CORE_FILES),$(NATIVE_FILES))
185 else
186 LIBTCC_OBJ = libtcc.o
187 LIBTCC_INC = $(NATIVE_FILES)
188 libtcc.o : NATIVE_DEFINES += -DONE_SOURCE
189 endif
191 $(LIBTCC_OBJ) tcc.o : %.o : %.c $(LIBTCC_INC)
192 $(CC) -o $@ -c $< $(NATIVE_DEFINES) $(CPPFLAGS) $(CFLAGS)
194 ifndef LIBTCC_DLL
195 libtcc.a: $(LIBTCC_OBJ)
196 $(AR) rcs $@ $^
197 endif
199 libtcc.so.1.0: $(LIBTCC_OBJ)
200 $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDFLAGS)
202 libtcc.so.1.0: CFLAGS+=-fPIC
204 ifdef LIBTCC_DLL
205 libtcc.dll libtcc.def libtcc.a: $(LIBTCC_OBJ)
206 $(CC) -shared $^ -o $@ $(LDFLAGS) -Wl,--output-def,libtcc.def,--out-implib,libtcc.a
207 endif
209 # windows utilities
210 tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
211 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
212 tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
213 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
215 # TinyCC runtime libraries
216 libtcc1.a : FORCE
217 $(MAKE) -C lib native
218 lib/%/libtcc1.a : FORCE $(PROGS_CROSS)
219 $(MAKE) -C lib cross TARGET=$*
221 FORCE:
223 # install
224 TCC_INCLUDES = stdarg.h stddef.h stdbool.h float.h varargs.h tcclib.h
225 INSTALL=install
226 ifdef STRIP_BINARIES
227 INSTALLBIN=$(INSTALL) -s
228 else
229 INSTALLBIN=$(INSTALL)
230 endif
232 ifndef CONFIG_WIN32
233 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
234 mkdir -p "$(bindir)"
235 ifeq ($(CC),tcc)
236 $(INSTALL) -m755 $(PROGS) "$(bindir)"
237 else
238 $(INSTALLBIN) -m755 $(PROGS) "$(bindir)"
239 endif
240 mkdir -p "$(mandir)/man1"
241 -$(INSTALL) tcc.1 "$(mandir)/man1"
242 mkdir -p "$(infodir)"
243 -$(INSTALL) tcc-doc.info "$(infodir)"
244 mkdir -p "$(tccdir)"
245 mkdir -p "$(tccdir)/include"
246 ifneq ($(LIBTCC1),)
247 $(INSTALL) -m644 $(LIBTCC1) "$(tccdir)"
248 endif
249 $(INSTALL) -m644 $(addprefix $(top_srcdir)/include/,$(TCC_INCLUDES)) "$(tccdir)/include"
250 mkdir -p "$(libdir)"
251 $(INSTALL) -m755 $(LIBTCC) "$(libdir)"
252 ifdef DISABLE_STATIC
253 ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so.1"
254 ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so"
255 endif
256 mkdir -p "$(includedir)"
257 $(INSTALL) -m644 $(top_srcdir)/libtcc.h "$(includedir)"
258 mkdir -p "$(docdir)"
259 -$(INSTALL) -m644 tcc-doc.html "$(docdir)"
260 ifdef CONFIG_CROSS
261 mkdir -p "$(tccdir)/win32/lib/32"
262 mkdir -p "$(tccdir)/win32/lib/64"
263 ifeq ($(ARCH),x86-64)
264 mkdir -p "$(tccdir)/i386"
265 $(INSTALL) -m644 lib/i386/libtcc1.a "$(tccdir)/i386"
266 cp -r "$(tccdir)/include" "$(tccdir)/i386"
267 endif
268 $(INSTALL) -m644 win32/lib/*.def "$(tccdir)/win32/lib"
269 $(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/win32/lib/32"
270 $(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/win32/lib/64"
271 cp -r win32/include/. "$(tccdir)/win32/include"
272 cp -r include/. "$(tccdir)/win32/include"
273 endif
275 uninstall:
276 rm -fv $(foreach P,$(PROGS),"$(bindir)/$P")
277 rm -fv $(foreach P,$(LIBTCC1),"$(tccdir)/$P")
278 rm -fv $(foreach P,$(TCC_INCLUDES),"$(tccdir)/include/$P")
279 rm -fv "$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
280 rm -fv "$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
281 rm -fv "$(libdir)/libtcc.so*"
282 rm -rf "$(tccdir)/win32"
283 -rmdir $(tccdir)/include
284 ifeq ($(ARCH),x86-64)
285 rm -rf "$(tccdir)/i386"
286 endif
287 else
288 # on windows
289 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
290 mkdir -p "$(tccdir)"
291 mkdir -p "$(tccdir)/lib"
292 mkdir -p "$(tccdir)/include"
293 mkdir -p "$(tccdir)/examples"
294 mkdir -p "$(tccdir)/doc"
295 mkdir -p "$(tccdir)/libtcc"
296 $(INSTALLBIN) -m755 $(PROGS) "$(tccdir)"
297 $(INSTALL) -m644 $(LIBTCC1) $(top_srcdir)/win32/lib/*.def "$(tccdir)/lib"
298 cp -r $(top_srcdir)/win32/include/. "$(tccdir)/include"
299 cp -r $(top_srcdir)/win32/examples/. "$(tccdir)/examples"
300 $(INSTALL) -m644 $(addprefix $(top_srcdir)/include/,$(TCC_INCLUDES)) "$(tccdir)/include"
301 $(INSTALL) -m644 tcc-doc.html $(top_srcdir)/win32/tcc-win32.txt "$(tccdir)/doc"
302 $(INSTALL) -m644 $(top_srcdir)/libtcc.h $(LIBTCC_EXTRA) "$(tccdir)/libtcc"
303 $(INSTALL) -m644 $(LIBTCC) $(tccdir)
304 ifdef CONFIG_CROSS
305 mkdir -p "$(tccdir)/lib/32"
306 mkdir -p "$(tccdir)/lib/64"
307 -$(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/lib/32"
308 -$(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/lib/64"
309 endif
311 uninstall:
312 rm -rfv "$(tccdir)/*"
313 endif
315 # documentation and man page
316 tcc-doc.html: tcc-doc.texi
317 makeinfo --no-split --html -o $@ $<
319 tcc.1: tcc-doc.texi
320 -$(top_srcdir)/texi2pod.pl $< tcc.pod
321 -pod2man --section=1 --center="Tiny C Compiler" --release=`cat $(top_srcdir)/VERSION` tcc.pod > $@
323 tcc-doc.info: tcc-doc.texi
324 -makeinfo $<
326 # in tests subdir
327 export LIBTCC1
329 %est:
330 $(MAKE) -C tests $@
332 clean:
333 rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.so* *.out *.exe libtcc_test$(EXESUF)
334 $(MAKE) -C tests $@
335 ifneq ($(LIBTCC1),)
336 $(MAKE) -C lib $@
337 endif
339 distclean: clean
340 rm -vf config.h config.mak config.texi tcc.1 tcc-doc.info tcc-doc.html
342 config.mak:
343 @echo "Please run ./configure."
344 @exit 1
346 # create release tarball from *current* git branch (including tcc-doc.html
347 # and converting two files to CRLF)
348 TCC-VERSION := tcc-$(shell cat $(top_srcdir)/VERSION)
349 tar: tcc-doc.html
350 mkdir $(TCC-VERSION)
351 ( cd $(TCC-VERSION) && git --git-dir ../.git checkout -f )
352 cp tcc-doc.html $(TCC-VERSION)
353 for f in tcc-win32.txt build-tcc.bat ; do \
354 cat win32/$$f | sed 's,\(.*\),\1\r,g' > $(TCC-VERSION)/win32/$$f ; \
355 done
356 tar cjf $(TCC-VERSION).tar.bz2 $(TCC-VERSION)
357 rm -rf $(TCC-VERSION)
358 git reset
360 Makefile: $(top_srcdir)/Makefile
361 cp $< $@
363 .PHONY: all clean tar distclean install uninstall FORCE
365 endif # ifeq ($(TOP),.)