A 32/64 bit tcc on linux: an arch specific path for libtcc1.a
[tinycc.git] / Makefile
blob7ddc81c8d9d04aef2623853d3f9539b77838d6d0
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
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_$(CONFIG_arm64) += -DTCC_TARGET_ARM64
74 NATIVE_DEFINES += $(NATIVE_DEFINES_yes)
76 ifeq ($(TOP),.)
78 PROGS=tcc$(EXESUF)
79 I386_CROSS = i386-linux-gnu-tcc$(EXESUF)
80 WIN32_CROSS = i386-w64-mingw32-tcc$(EXESUF)
81 WIN64_CROSS = x86_64-w64-mingw32-tcc$(EXESUF)
82 WINCE_CROSS = arm-wince-mingw32ce-tcc$(EXESUF)
83 X64_CROSS = x86_64-linux-gnu-tcc$(EXESUF)
84 ARM_FPA_CROSS = arm-linux-fpa-tcc$(EXESUF)
85 ARM_FPA_LD_CROSS = arm-linux-fpa-ld-tcc$(EXESUF)
86 ARM_VFP_CROSS = arm-linux-gnu-tcc$(EXESUF)
87 ARM_EABI_CROSS = arm-linux-gnueabi-tcc$(EXESUF)
88 ARM_EABIHF_CROSS = arm-linux-gnueabihf-tcc$(EXESUF)
89 ARM_CROSS = $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS)
90 ARM64_CROSS = arm64-tcc$(EXESUF)
91 C67_CROSS = c67-tcc$(EXESUF)
93 # Legacy symlinks for cross compilers
94 $(I386_CROSS)_LINK = i386-tcc$(EXESUF)
95 $(WIN32_CROSS)_LINK = i386-win32-tcc$(EXESUF)
96 $(WIN64_CROSS)_LINK = x86_64-win32-tcc$(EXESUF)
97 $(WINCE_CROSS)_LINK = arm-win32-tcc$(EXESUF)
98 $(X64_CROSS)_LINK = x86_64-tcc$(EXESUF)
99 $(ARM_FPA_CROSS)_LINK = arm-fpa-tcc$(EXESUF)
100 $(ARM_FPA_LD_CROSS)_LINK = arm-fpa-ld-tcc$(EXESUF)
101 $(ARM_VFP_CROSS)_LINK = arm-vfp-tcc$(EXESUF)
102 $(ARM_EABI_CROSS)_LINK = arm-eabi-tcc$(EXESUF)
104 CORE_FILES = tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
105 CORE_FILES += tcc.h config.h libtcc.h tcctok.h
106 I386_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h
107 WIN32_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
108 WIN64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h tccpe.c
109 WINCE_FILES = $(CORE_FILES) arm-gen.c tccpe.c
110 X86_64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h
111 ARM_FILES = $(CORE_FILES) arm-gen.c
112 ARM64_FILES = $(CORE_FILES) arm64-gen.c
113 C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c
115 ifdef CONFIG_WIN64
116 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
117 NATIVE_FILES=$(WIN64_FILES)
118 PROGS_CROSS=$(WIN32_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(ARM64_CROSS) $(C67_CROSS) $(WINCE_CROSS)
119 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a
120 LIBTCC1=libtcc1.a
121 else ifdef CONFIG_WIN32
122 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
123 NATIVE_FILES=$(WIN32_FILES)
124 PROGS_CROSS=$(WIN64_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(ARM64_CROSS) $(C67_CROSS) $(WINCE_CROSS)
125 LIBTCC1_CROSS=lib/x86_64-win32/libtcc1.a
126 LIBTCC1=libtcc1.a
127 else ifeq ($(ARCH),i386)
128 NATIVE_FILES=$(I386_FILES)
129 PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(ARM64_CROSS) $(C67_CROSS) $(WINCE_CROSS)
130 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a
131 LIBTCC1=libtcc1.a
132 else ifeq ($(ARCH),x86-64)
133 NATIVE_FILES=$(X86_64_FILES)
134 PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(ARM64_CROSS) $(C67_CROSS) $(WINCE_CROSS)
135 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a lib/i386/libtcc1.a
136 LIBTCC1=libtcc1.a
137 else ifeq ($(ARCH),arm)
138 NATIVE_FILES=$(ARM_FILES)
139 PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM64_CROSS) $(C67_CROSS) $(WINCE_CROSS)
140 LIBTCC1=libtcc1.a
141 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a lib/i386/libtcc1.a
142 else ifeq ($(ARCH),arm64)
143 NATIVE_FILES=$(ARM64_FILES)
144 PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS) $(WINCE_CROSS)
145 LIBTCC1=libtcc1.a
146 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a lib/i386/libtcc1.a
147 endif
148 PROGS_CROSS_LINK=$(foreach PROG_CROSS,$(PROGS_CROSS),$($(PROG_CROSS)_LINK))
150 ifeq ($(TARGETOS),Darwin)
151 PROGS+=tiny_libmaker$(EXESUF)
152 endif
154 TCCLIBS = $(LIBTCC1) $(LIBTCC) $(LIBTCC_EXTRA)
155 TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info
157 ifdef CONFIG_CROSS
158 PROGS+=$(PROGS_CROSS)
159 TCCLIBS+=$(LIBTCC1_CROSS)
160 endif
162 all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
164 # Host Tiny C Compiler
165 tcc$(EXESUF): tcc.o $(LIBTCC)
166 $(CC) -o $@ $^ $(LIBS) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(LINK_LIBTCC)
168 # Cross Tiny C Compilers
169 %-tcc$(EXESUF): tcc.c
170 $(CC) -o $@ $< -DONE_SOURCE $(DEFINES) $(CPPFLAGS) $(CFLAGS) $(LIBS) $(LDFLAGS)
171 $(if $($@_LINK),ln -sf $@ $($@_LINK))
173 # profiling version
174 tcc_p$(EXESUF): $(NATIVE_FILES)
175 $(CC) -o $@ $< -DONE_SOURCE $(NATIVE_DEFINES) $(CPPFLAGS_P) $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P)
177 $(I386_CROSS): DEFINES = -DTCC_TARGET_I386 \
178 -DCONFIG_TCCDIR="\"$(tccdir)/i386\"" -DCONFIG_MULTIARCHDIR="\"i386-linux-gnu\""
179 $(X64_CROSS): DEFINES = -DTCC_TARGET_X86_64 -DCONFIG_MULTIARCHDIR="\"x86_64-linux-gnu\""
180 $(WIN32_CROSS): DEFINES = -DTCC_TARGET_I386 -DTCC_TARGET_PE \
181 -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
182 -DCONFIG_TCC_LIBPATHS="\"{B}/lib/32;{B}/lib\""
183 $(WIN64_CROSS): DEFINES = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE \
184 -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
185 -DCONFIG_TCC_LIBPATHS="\"{B}/lib/64;{B}/lib\""
186 $(WINCE_CROSS): DEFINES = -DTCC_TARGET_PE
187 $(C67_CROSS): DEFINES = -DTCC_TARGET_C67
188 $(ARM_FPA_CROSS): DEFINES = -DTCC_TARGET_ARM
189 $(ARM_FPA_LD_CROSS)$(EXESUF): DEFINES = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
190 $(ARM_VFP_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DCONFIG_MULTIARCHDIR="\"arm-linux-gnu\""
191 $(ARM_EABI_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_EABI -DTCC_ARM_VFP -DCONFIG_MULTIARCHDIR="\"arm-linux-gnueabi\""
192 $(ARM64_CROSS): DEFINES = -DTCC_TARGET_ARM64
194 $(I386_CROSS): $(I386_FILES)
195 $(X64_CROSS): $(X86_64_FILES)
196 $(WIN32_CROSS): $(WIN32_FILES)
197 $(WIN64_CROSS): $(WIN64_FILES)
198 $(WINCE_CROSS): $(WINCE_FILES)
199 $(C67_CROSS): $(C67_FILES)
200 $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS): $(ARM_FILES)
201 $(ARM64_CROSS): $(ARM64_FILES)
203 # libtcc generation and test
204 ifndef ONE_SOURCE
205 LIBTCC_OBJ = $(filter-out tcc.o,$(patsubst %.c,%.o,$(filter %.c,$(NATIVE_FILES))))
206 LIBTCC_INC = $(filter %.h,$(CORE_FILES)) $(filter-out $(CORE_FILES),$(NATIVE_FILES))
207 else
208 LIBTCC_OBJ = libtcc.o
209 LIBTCC_INC = $(NATIVE_FILES)
210 libtcc.o : NATIVE_DEFINES += -DONE_SOURCE
211 endif
213 $(LIBTCC_OBJ) tcc.o : %.o : %.c $(LIBTCC_INC)
214 $(CC) -o $@ -c $< $(NATIVE_DEFINES) $(CPPFLAGS) $(CFLAGS)
216 ifndef LIBTCC_DLL
217 libtcc.a: $(LIBTCC_OBJ)
218 $(AR) rcs $@ $^
219 endif
221 libtcc.so.1.0: $(LIBTCC_OBJ)
222 $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDFLAGS)
224 libtcc.so.1.0: CFLAGS+=-fPIC
226 ifdef LIBTCC_DLL
227 libtcc.dll libtcc.def libtcc.a: $(LIBTCC_OBJ)
228 $(CC) -shared $^ -o $@ $(LDFLAGS) -Wl,--output-def,libtcc.def,--out-implib,libtcc.a
229 endif
231 # windows utilities
232 tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
233 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
234 tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
235 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
237 # TinyCC runtime libraries
238 libtcc1.a : FORCE
239 $(MAKE) -C lib native
240 lib/%/libtcc1.a : FORCE $(PROGS_CROSS)
241 $(MAKE) -C lib cross TARGET=$*
243 FORCE:
245 # install
246 TCC_INCLUDES = stdarg.h stddef.h stdbool.h float.h varargs.h
247 INSTALL=install
248 ifdef STRIP_BINARIES
249 INSTALLBIN=$(INSTALL) -s
250 else
251 INSTALLBIN=$(INSTALL)
252 endif
254 install-strip: install
255 strip $(foreach PROG,$(PROGS),"$(bindir)"/$(PROG))
257 ifndef CONFIG_WIN32
258 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
259 mkdir -p "$(bindir)"
260 ifeq ($(CC),tcc)
261 $(INSTALL) -m755 $(PROGS) $(PROGS_CROSS_LINK) "$(bindir)"
262 else
263 $(INSTALLBIN) -m755 $(PROGS) "$(bindir)"
264 endif
265 mkdir -p "$(mandir)/man1"
266 -$(INSTALL) -m644 tcc.1 "$(mandir)/man1"
267 mkdir -p "$(infodir)"
268 -$(INSTALL) -m644 tcc-doc.info "$(infodir)"
269 mkdir -p "$(tccdir)"
270 mkdir -p "$(tccdir)/include"
271 ifneq ($(LIBTCC1),)
272 $(INSTALL) -m644 $(LIBTCC1) "$(tccdir)"
273 endif
274 $(INSTALL) -m644 $(addprefix $(top_srcdir)/include/,$(TCC_INCLUDES)) $(top_srcdir)/tcclib.h "$(tccdir)/include"
275 mkdir -p "$(libdir)"
276 $(INSTALL) -m644 $(LIBTCC) "$(libdir)"
277 ifdef DISABLE_STATIC
278 ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so.1"
279 ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so"
280 endif
281 mkdir -p "$(includedir)"
282 $(INSTALL) -m644 $(top_srcdir)/libtcc.h "$(includedir)"
283 mkdir -p "$(docdir)"
284 -$(INSTALL) -m644 tcc-doc.html "$(docdir)"
285 ifdef CONFIG_CROSS
286 mkdir -p "$(tccdir)/win32/lib/32"
287 mkdir -p "$(tccdir)/win32/lib/64"
288 ifneq ($(ARCH),i386)
289 mkdir -p "$(tccdir)/i386"
290 $(INSTALL) -m644 lib/i386/libtcc1.a "$(tccdir)/i386"
291 cp -r "$(tccdir)/include" "$(tccdir)/i386"
292 endif
293 $(INSTALL) -m644 $(top_srcdir)/win32/lib/*.def "$(tccdir)/win32/lib"
294 $(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/win32/lib/32"
295 $(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/win32/lib/64"
296 cp -r $(top_srcdir)/win32/include/. "$(tccdir)/win32/include"
297 cp -r "$(tccdir)/include" "$(tccdir)/win32"
298 endif
300 uninstall:
301 rm -fv $(foreach P,$(PROGS),"$(bindir)/$P")
302 rm -fv $(foreach P,$(LIBTCC1),"$(tccdir)/$P")
303 rm -fv $(foreach P,$(TCC_INCLUDES),"$(tccdir)/include/$P")
304 rm -fv "$(tccdir)/include/tcclib.h"
305 rm -fv "$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
306 rm -fv "$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
307 rm -fv "$(libdir)/libtcc.so*"
308 rm -rf "$(tccdir)/win32"
309 -rmdir $(tccdir)/include
310 ifneq ($(ARCH),i386)
311 rm -rf "$(tccdir)/i386"
312 endif
313 else
314 # on windows
315 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
316 mkdir -p "$(tccdir)"
317 mkdir -p "$(tccdir)/lib"
318 mkdir -p "$(tccdir)/include"
319 mkdir -p "$(tccdir)/examples"
320 mkdir -p "$(tccdir)/doc"
321 mkdir -p "$(tccdir)/libtcc"
322 $(INSTALLBIN) -m755 $(PROGS) "$(tccdir)"
323 $(INSTALL) -m644 $(LIBTCC1) $(top_srcdir)/win32/lib/*.def "$(tccdir)/lib"
324 cp -r $(top_srcdir)/win32/include/. "$(tccdir)/include"
325 cp -r $(top_srcdir)/win32/examples/. "$(tccdir)/examples"
326 $(INSTALL) -m644 $(addprefix $(top_srcdir)/include/,$(TCC_INCLUDES)) $(top_srcdir)/tcclib.h "$(tccdir)/include"
327 $(INSTALL) -m644 tcc-doc.html $(top_srcdir)/win32/tcc-win32.txt "$(tccdir)/doc"
328 $(INSTALL) -m644 $(top_srcdir)/libtcc.h $(LIBTCC_EXTRA) "$(tccdir)/libtcc"
329 $(INSTALL) -m644 $(LIBTCC) $(tccdir)
330 ifdef CONFIG_CROSS
331 mkdir -p "$(tccdir)/lib/32"
332 mkdir -p "$(tccdir)/lib/64"
333 -$(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/lib/32"
334 -$(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/lib/64"
335 endif
337 uninstall:
338 rm -rfv "$(tccdir)/*"
339 endif
341 # documentation and man page
342 tcc-doc.html: tcc-doc.texi
343 -makeinfo --no-split --html --number-sections -o $@ $<
345 tcc.1: tcc-doc.texi
346 -$(top_srcdir)/texi2pod.pl $< tcc.pod
347 -pod2man --section=1 --center="Tiny C Compiler" --release=`cat $(top_srcdir)/VERSION` tcc.pod > $@
349 tcc-doc.info: tcc-doc.texi
350 -makeinfo $<
352 # in tests subdir
353 export LIBTCC1
355 %est:
356 $(MAKE) -C tests $@ 'PROGS_CROSS=$(PROGS_CROSS)'
358 clean:
359 rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.so* *.out *.log \
360 *.exe a.out tags TAGS libtcc_test$(EXESUF)
361 $(MAKE) -C tests $@
362 ifneq ($(LIBTCC1),)
363 $(MAKE) -C lib $@
364 endif
366 distclean: clean
367 rm -vf config.h config.mak config.texi tcc.1 tcc-doc.info tcc-doc.html
369 config.mak:
370 @echo "Please run ./configure."
371 @exit 1
373 tags:
374 ctags $(top_srcdir)/*.[ch] $(top_srcdir)/include/*.h $(top_srcdir)/lib/*.[chS]
376 TAGS:
377 ctags -e $(top_srcdir)/*.[ch] $(top_srcdir)/include/*.h $(top_srcdir)/lib/*.[chS]
379 # create release tarball from *current* git branch (including tcc-doc.html
380 # and converting two files to CRLF)
381 TCC-VERSION := tcc-$(shell cat $(top_srcdir)/VERSION)
382 tar: tcc-doc.html
383 mkdir $(TCC-VERSION)
384 ( cd $(TCC-VERSION) && git --git-dir ../.git checkout -f )
385 cp tcc-doc.html $(TCC-VERSION)
386 for f in tcc-win32.txt build-tcc.bat ; do \
387 cat win32/$$f | sed 's,\(.*\),\1\r,g' > $(TCC-VERSION)/win32/$$f ; \
388 done
389 tar cjf $(TCC-VERSION).tar.bz2 $(TCC-VERSION)
390 rm -rf $(TCC-VERSION)
391 git reset
393 .PHONY: all clean tar tags TAGS distclean install uninstall FORCE
395 endif # ifeq ($(TOP),.)