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