build: revert Makefiles to 0.9.26 state (mostly)
[tinycc.git] / Makefile
blob75d73aa0c9a2abd68353cccb5fb8953b01d663f9
2 # Tiny C Compiler Makefile
5 TOP ?= .
6 include $(TOP)/config.mak
7 VPATH = $(TOP)
9 ifeq (-$(findstring gcc,$(CC))-,-gcc-)
10 ifeq (-$(GCC_MAJOR)-$(findstring $(GCC_MINOR),56789)-,-4--)
11 CFLAGS += -D_FORTIFY_SOURCE=0
12 endif
13 else
14 ifeq (-$(findstring clang,$(CC))-,-clang-)
15 # make clang accept gnuisms in libtcc1.c
16 CFLAGS+=-fheinous-gnu-extensions
17 endif
18 endif
20 CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC
21 LIBS_P=
22 LDFLAGS_P = $(LDFLAGS)
24 LIBTCC = libtcc.a
25 LIBTCC1 = libtcc1.a
26 LINK_LIBTCC =
27 LIBS =
29 ifdef CONFIG_WIN32
30 ifeq ($(ARCH),x86-64)
31 CONFIG_WIN64=yes
32 endif
33 STRIP_BINARIES = yes
34 LIBTCC = libtcc.dll
35 else
36 LIBS=-lm
37 ifndef CONFIG_NOLDL
38 LIBS+=-ldl
39 endif
40 # make libtcc as static or dynamic library?
41 ifdef DISABLE_STATIC
42 LIBTCC=libtcc.so
43 ifndef DISABLE_RPATH
44 LINK_LIBTCC += -Wl,-rpath,"$(libdir)"
45 export LD_LIBRARY_PATH := $(CURDIR)/$(TOP)
46 endif
47 endif
48 endif
50 ifeq ($(TARGETOS),Darwin)
51 CFLAGS += -Wl,-flat_namespace,-undefined,warning
52 export MACOSX_DEPLOYMENT_TARGET:=10.2
53 endif
55 CONFIG_$(ARCH) = yes
56 NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
57 NATIVE_DEFINES_$(CONFIG_x86-64) += -DTCC_TARGET_X86_64
58 NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE
59 NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC
60 NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM
61 NATIVE_DEFINES_$(CONFIG_arm_eabihf) += -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT
62 NATIVE_DEFINES_$(CONFIG_arm_eabi) += -DTCC_ARM_EABI
63 NATIVE_DEFINES_$(CONFIG_arm_vfp) += -DTCC_ARM_VFP
64 NATIVE_DEFINES_$(CONFIG_arm64) += -DTCC_TARGET_ARM64
65 NATIVE_DEFINES += $(NATIVE_DEFINES_yes)
67 ifeq ($(TOP),.)
69 PROGS=tcc$(EXESUF)
70 I386_CROSS = i386-tcc$(EXESUF)
71 WIN32_CROSS = i386-win32-tcc$(EXESUF)
72 WIN64_CROSS = x86_64-win32-tcc$(EXESUF)
73 WINCE_CROSS = arm-wince-tcc$(EXESUF)
74 X64_CROSS = x86_64-tcc$(EXESUF)
75 ARM_FPA_CROSS = arm-fpa-tcc$(EXESUF)
76 ARM_FPA_LD_CROSS = arm-fpa-ld-tcc$(EXESUF)
77 ARM_VFP_CROSS = arm-vfp-tcc$(EXESUF)
78 ARM_EABI_CROSS = arm-eabi-tcc$(EXESUF)
79 ARM_EABIHF_CROSS = arm-eabihf-tcc$(EXESUF)
80 ARM_CROSS = $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS)
81 ARM64_CROSS = arm64-tcc$(EXESUF)
82 C67_CROSS = c67-tcc$(EXESUF)
84 CORE_FILES = tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
85 CORE_FILES += tcc.h config.h libtcc.h tcctok.h
86 I386_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h
87 WIN32_FILES = $(CORE_FILES) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
88 WIN64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h tccpe.c
89 WINCE_FILES = $(CORE_FILES) arm-gen.c tccpe.c
90 X86_64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h
91 ARM_FILES = $(CORE_FILES) arm-gen.c
92 ARM64_FILES = $(CORE_FILES) arm64-gen.c
93 C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c
95 ifdef CONFIG_WIN64
96 PROGS+=tiny_impdef$(EXESUF)
97 NATIVE_FILES=$(WIN64_FILES)
98 PROGS_CROSS=$(WIN32_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(ARM64_CROSS) $(C67_CROSS) $(WINCE_CROSS)
99 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a
101 else ifdef CONFIG_WIN32
102 PROGS+=tiny_impdef$(EXESUF)
103 NATIVE_FILES=$(WIN32_FILES)
104 PROGS_CROSS=$(WIN64_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(ARM64_CROSS) $(C67_CROSS) $(WINCE_CROSS)
105 LIBTCC1_CROSS=lib/x86_64-win32/libtcc1.a
107 else ifeq ($(ARCH),i386)
108 NATIVE_FILES=$(I386_FILES)
109 PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(ARM64_CROSS) $(C67_CROSS) $(WINCE_CROSS)
110 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a
112 else ifeq ($(ARCH),x86-64)
113 NATIVE_FILES=$(X86_64_FILES)
114 PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(ARM64_CROSS) $(C67_CROSS) $(WINCE_CROSS)
115 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a
117 else ifeq ($(ARCH),arm)
118 NATIVE_FILES=$(ARM_FILES)
119 PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM64_CROSS) $(C67_CROSS) $(WINCE_CROSS)
121 else ifeq ($(ARCH),arm64)
122 NATIVE_FILES=$(ARM64_FILES)
123 PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS) $(WINCE_CROSS)
124 endif
126 ifeq ($(TARGETOS),Darwin)
127 PROGS += tiny_libmaker$(EXESUF)
128 endif
130 TCCLIBS = $(LIBTCC1) $(LIBTCC)
131 TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info
133 ifdef CONFIG_CROSS
134 PROGS += $(PROGS_CROSS)
135 TCCLIBS += $(LIBTCC1_CROSS)
136 endif
138 all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
140 # Host Tiny C Compiler
141 tcc$(EXESUF): tcc.c $(LIBTCC)
142 $(CC) -o $@ $^ $(LIBS) $(CFLAGS) $(LDFLAGS) $(LINK_LIBTCC)
144 # Cross Tiny C Compilers
145 %-tcc$(EXESUF): tcc.c
146 $(CC) -o $@ $< -DONE_SOURCE $(DEFINES) $(CFLAGS) $(LIBS) $(LDFLAGS)
148 # profiling version
149 tcc_p$(EXESUF): $(NATIVE_FILES)
150 $(CC) -o $@ $< -DONE_SOURCE $(NATIVE_DEFINES) $(CPPFLAGS_P) $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P)
152 $(I386_CROSS): DEFINES = -DTCC_TARGET_I386 \
153 -DCONFIG_TCCDIR="\"$(tccdir)/i386\""
154 $(X64_CROSS) : DEFINES = -DTCC_TARGET_X86_64
155 -DCONFIG_TCCDIR="\"$(tccdir)/x86_64\""
156 $(WIN32_CROSS) : DEFINES = -DTCC_TARGET_I386 -DTCC_TARGET_PE \
157 -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
158 -DCONFIG_TCC_LIBPATHS="\"{B}/lib/32;{B}/lib\""
159 $(WIN64_CROSS) : DEFINES = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE \
160 -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
161 -DCONFIG_TCC_LIBPATHS="\"{B}/lib/64;{B}/lib\""
162 $(WINCE_CROSS): DEFINES = -DTCC_TARGET_PE
163 $(C67_CROSS): DEFINES = -DTCC_TARGET_C67 -w # disable warnigs
164 $(ARM_FPA_CROSS): DEFINES = -DTCC_TARGET_ARM
165 $(ARM_FPA_LD_CROSS)$(EXESUF): DEFINES = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
166 $(ARM_VFP_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_VFP
167 $(ARM_EABI_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_EABI -DTCC_ARM_VFP
168 $(ARM64_CROSS): DEFINES = -DTCC_TARGET_ARM64
170 $(I386_CROSS) : $(I386_FILES)
171 $(X64_CROSS) : $(X86_64_FILES)
172 $(WIN32_CROSS) : $(WIN32_FILES)
173 $(WIN64_CROSS) : $(WIN64_FILES)
174 $(WINCE_CROSS) : $(WINCE_FILES)
175 $(C67_CROSS) : $(C67_FILES)
176 $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS): $(ARM_FILES)
177 $(ARM64_CROSS): $(ARM64_FILES)
179 # libtcc generation and test
180 ifndef ONE_SOURCE
181 LIBTCC_OBJ = $(filter-out tcc.o,$(patsubst %.c,%.o,$(filter %.c,$(NATIVE_FILES))))
182 LIBTCC_INC = $(filter %.h,$(CORE_FILES)) $(filter-out $(CORE_FILES),$(NATIVE_FILES))
183 else
184 LIBTCC_OBJ = libtcc.o
185 LIBTCC_INC = $(NATIVE_FILES)
186 libtcc.o : NATIVE_DEFINES += -DONE_SOURCE
187 tcc.o : NATIVE_DEFINES += -DONE_SOURCE
188 endif
190 $(LIBTCC_OBJ) tcc.o : %.o : %.c $(LIBTCC_INC)
191 $(CC) -o $@ -c $< $(NATIVE_DEFINES) $(CFLAGS)
193 libtcc.a: $(LIBTCC_OBJ)
194 $(AR) rcs $@ $^
196 libtcc.so: $(LIBTCC_OBJ)
197 $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDFLAGS)
199 libtcc.so: CFLAGS+=-fPIC
201 # windows : libtcc.dll
202 libtcc.dll : $(LIBTCC_OBJ) tiny_impdef$(EXESUF)
203 $(CC) -shared $(LIBTCC_OBJ) -o $@ $(LDFLAGS)
204 ./tiny_impdef $@
206 libtcc.dll : NATIVE_DEFINES += -DLIBTCC_AS_DLL
208 # windows : utilities
209 tiny_%$(EXESUF): $(SRCTOP)/win32/tools/tiny_%.c
210 $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) $(NATIVE_DEFINES)
212 ifneq ($(LIBTCC1),)
213 # TinyCC runtime libraries
214 $(LIBTCC1) : FORCE $(PROGS)
215 $(MAKE) -C lib native
216 endif
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
225 INSTALL=install
227 ifdef STRIP_BINARIES
228 INSTALLBIN=$(INSTALL) -s
229 else
230 INSTALLBIN=$(INSTALL)
231 endif
233 install-strip: install
234 strip $(foreach PROG,$(PROGS),"$(bindir)"/$(PROG))
236 ifndef CONFIG_WIN32
237 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
238 mkdir -p "$(bindir)"
239 $(INSTALLBIN) -m755 $(PROGS) "$(bindir)"
240 mkdir -p "$(mandir)/man1"
241 -$(INSTALL) -m644 tcc.1 "$(mandir)/man1"
242 mkdir -p "$(infodir)"
243 -$(INSTALL) -m644 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 include/,$(TCC_INCLUDES)) tcclib.h "$(tccdir)/include"
250 mkdir -p "$(libdir)"
251 $(INSTALL) -m644 $(LIBTCC) "$(libdir)"
252 mkdir -p "$(includedir)"
253 $(INSTALL) -m644 libtcc.h "$(includedir)"
254 mkdir -p "$(docdir)"
255 -$(INSTALL) -m644 tcc-doc.html "$(docdir)"
256 ifdef CONFIG_CROSS
257 mkdir -p "$(tccdir)/win32/lib/32"
258 mkdir -p "$(tccdir)/win32/lib/64"
259 $(INSTALL) -m644 win32/lib/*.def "$(tccdir)/win32/lib"
260 -$(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/win32/lib/32"
261 -$(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/win32/lib/64"
262 cp -r win32/include/. "$(tccdir)/win32/include"
263 cp -r "$(tccdir)/include" "$(tccdir)/win32"
264 endif
266 uninstall:
267 rm -fv $(foreach P,$(PROGS),"$(bindir)/$P")
268 rm -fv $(foreach P,$(LIBTCC1),"$(tccdir)/$P")
269 rm -fv $(foreach P,$(TCC_INCLUDES),"$(tccdir)/include/$P")
270 rm -fv "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
271 rm -fv "$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
272 rm -fv $(libdir)/libtcc.so*
273 rm -rv "$(tccdir)"
274 rm -rv "$(docdir)"
275 else
276 # on windows
277 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
278 mkdir -p "$(tccdir)"
279 mkdir -p "$(tccdir)/lib"
280 mkdir -p "$(tccdir)/include"
281 mkdir -p "$(tccdir)/examples"
282 mkdir -p "$(tccdir)/doc"
283 mkdir -p "$(tccdir)/libtcc"
284 $(INSTALLBIN) -m755 $(PROGS) $(LIBTCC) "$(tccdir)"
285 $(INSTALL) -m644 libtcc1.a win32/lib/*.def "$(tccdir)/lib"
286 cp -r win32/include/. "$(tccdir)/include"
287 cp -r win32/examples/. "$(tccdir)/examples"
288 cp tests/libtcc_test.c "$(tccdir)/examples"
289 $(INSTALL) -m644 $(addprefix include/,$(TCC_INCLUDES)) tcclib.h "$(tccdir)/include"
290 $(INSTALL) -m644 tcc-doc.html win32/tcc-win32.txt "$(tccdir)/doc"
291 $(INSTALL) -m644 libtcc.h libtcc.def "$(tccdir)/libtcc"
292 ifdef CONFIG_CROSS
293 mkdir -p "$(tccdir)/lib/32"
294 mkdir -p "$(tccdir)/lib/64"
295 -$(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/lib/32"
296 -$(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/lib/64"
297 endif
299 uninstall:
300 rm -rfv "$(tccdir)/"*
301 endif
303 # documentation and man page
304 tcc-doc.html: tcc-doc.texi
305 -makeinfo --no-split --html --number-sections -o $@ $<
307 tcc.1: tcc-doc.texi
308 -texi2pod.pl $< tcc.pod
309 -pod2man --section=1 --center="Tiny C Compiler" --release="$(VERSION)" tcc.pod > $@
311 tcc-doc.info: tcc-doc.texi
312 -makeinfo $<
314 # in tests subdir
315 test:
316 $(MAKE) -C tests
318 clean:
319 rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.so* *.out *.log \
320 lib*.def *.exe *.dll a.out tags TAGS libtcc_test$(EXESUF) tcc$(EXESUF)
321 $(MAKE) -C tests $@
322 $(MAKE) -C lib $@
324 distclean: clean
325 rm -vf config.h config.mak config.texi tcc.1 tcc-doc.info tcc-doc.html
327 config.mak:
328 @echo "Please run ./configure."
329 @exit 1
331 TAGFILES = *.[ch] include/*.h lib/*.[chS]
332 tags : ; ctags $(TAGFILES)
333 TAGS : ; etags $(TAGFILES)
335 # create release tarball from *current* git branch (including tcc-doc.html
336 # and converting two files to CRLF)
337 TCC-VERSION = $(VERSION)
338 tar: tcc-doc.html
339 mkdir $(TCC-VERSION)
340 ( cd $(TCC-VERSION) && git --git-dir ../.git checkout -f )
341 cp tcc-doc.html $(TCC-VERSION)
342 for f in tcc-win32.txt build-tcc.bat ; do \
343 cat win32/$$f | sed 's,\(.*\),\1\r,g' > $(TCC-VERSION)/win32/$$f ; \
344 done
345 tar cjf $(TCC-VERSION).tar.bz2 $(TCC-VERSION)
346 rm -rf $(TCC-VERSION)
347 git reset
349 .PHONY: all clean test tar tags TAGS distclean install uninstall FORCE
351 endif # ifeq ($(TOP),.)