Fixed out of tree build problem on Windows.
[tinycc.git] / Makefile
blob3dffaa80fbaef411d68702cb84309d206cc81e0e
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 LIBTCC=libtcc.so.1.0
49 LINK_LIBTCC=-Wl,-rpath,"$(libdir)"
50 ifdef DISABLE_RPATH
51 LINK_LIBTCC=
52 endif
53 else
54 LIBTCC=libtcc.a
55 LINK_LIBTCC=
56 endif
58 CONFIG_$(ARCH) = yes
59 NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
60 NATIVE_DEFINES_$(CONFIG_x86-64) += -DTCC_TARGET_X86_64
61 NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE
62 NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC
63 NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM -DWITHOUT_LIBTCC
64 NATIVE_DEFINES_$(CONFIG_arm_eabihf) += -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT
65 NATIVE_DEFINES_$(CONFIG_arm_eabi) += -DTCC_ARM_EABI
66 NATIVE_DEFINES_$(CONFIG_arm_vfp) += -DTCC_ARM_VFP
67 NATIVE_DEFINES += $(NATIVE_DEFINES_yes)
69 ifeq ($(TOP),.)
71 PROGS=tcc$(EXESUF)
72 I386_CROSS = i386-tcc$(EXESUF)
73 WIN32_CROSS = i386-win32-tcc$(EXESUF)
74 WIN64_CROSS = x86_64-win32-tcc$(EXESUF)
75 WINCE_CROSS = arm-win32-tcc$(EXESUF)
76 X64_CROSS = x86_64-tcc$(EXESUF)
77 ARM_FPA_CROSS = arm-fpa-tcc$(EXESUF)
78 ARM_FPA_LD_CROSS = arm-fpa-ld-tcc$(EXESUF)
79 ARM_VFP_CROSS = arm-vfp-tcc$(EXESUF)
80 ARM_EABI_CROSS = arm-eabi-tcc$(EXESUF)
81 ARM_CROSS = $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS)
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 C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c
94 ifdef CONFIG_WIN64
95 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
96 NATIVE_FILES=$(WIN64_FILES)
97 PROGS_CROSS=$(WIN32_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
98 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a
99 LIBTCC1=libtcc1.a
100 else ifdef CONFIG_WIN32
101 PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF)
102 NATIVE_FILES=$(WIN32_FILES)
103 PROGS_CROSS=$(WIN64_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS)
104 LIBTCC1_CROSS=lib/x86_64-win32/libtcc1.a
105 LIBTCC1=libtcc1.a
106 else ifeq ($(ARCH),i386)
107 NATIVE_FILES=$(I386_FILES)
108 PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
109 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a
110 LIBTCC1=libtcc1.a
111 else ifeq ($(ARCH),x86-64)
112 NATIVE_FILES=$(X86_64_FILES)
113 PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS)
114 LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a lib/i386/libtcc1.a
115 LIBTCC1=libtcc1.a
116 else ifeq ($(ARCH),arm)
117 NATIVE_FILES=$(ARM_FILES)
118 PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(C67_CROSS)
119 endif
121 ifeq ($(TARGETOS),Darwin)
122 PROGS+=tiny_libmaker$(EXESUF)
123 endif
125 ifdef CONFIG_USE_LIBGCC
126 LIBTCC1=
127 endif
129 TCCLIBS = $(LIBTCC1) $(LIBTCC)
130 TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info
132 ifdef CONFIG_CROSS
133 PROGS+=$(PROGS_CROSS)
134 TCCLIBS+=$(LIBTCC1_CROSS)
135 endif
137 all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
139 # Host Tiny C Compiler
140 tcc$(EXESUF): tcc.o $(LIBTCC)
141 $(CC) -o $@ $^ $(LIBS) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(LINK_LIBTCC)
143 # Cross Tiny C Compilers
144 %-tcc$(EXESUF): tcc.c
145 $(CC) -o $@ $< -DONE_SOURCE $(DEFINES) $(CPPFLAGS) $(CFLAGS) $(LIBS) $(LDFLAGS)
147 # profiling version
148 tcc_p$(EXESUF): $(NATIVE_FILES)
149 $(CC) -o $@ $< -DONE_SOURCE $(NATIVE_DEFINES) $(CPPFLAGS_P) $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P)
151 $(I386_CROSS): DEFINES = -DTCC_TARGET_I386 \
152 -DCONFIG_TCCDIR="\"$(tccdir)/i386\""
153 $(X64_CROSS): DEFINES = -DTCC_TARGET_X86_64
154 $(WIN32_CROSS): DEFINES = -DTCC_TARGET_I386 -DTCC_TARGET_PE \
155 -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
156 -DCONFIG_TCC_LIBPATHS="\"{B}/lib/32;{B}/lib\""
157 $(WIN64_CROSS): DEFINES = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE \
158 -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
159 -DCONFIG_TCC_LIBPATHS="\"{B}/lib/64;{B}/lib\""
160 $(WINCE_CROSS): DEFINES = -DTCC_TARGET_PE
161 $(C67_CROSS): DEFINES = -DTCC_TARGET_C67
162 $(ARM_FPA_CROSS): DEFINES = -DTCC_TARGET_ARM
163 $(ARM_FPA_LD_CROSS)$(EXESUF): DEFINES = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
164 $(ARM_VFP_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_VFP
165 $(ARM_EABI_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_EABI
167 $(I386_CROSS): $(I386_FILES)
168 $(X64_CROSS): $(X86_64_FILES)
169 $(WIN32_CROSS): $(WIN32_FILES)
170 $(WIN64_CROSS): $(WIN64_FILES)
171 $(WINCE_CROSS): $(WINCE_FILES)
172 $(C67_CROSS): $(C67_FILES)
173 $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS): $(ARM_FILES)
175 # libtcc generation and test
176 ifndef ONE_SOURCE
177 LIBTCC_OBJ = $(filter-out tcc.o,$(patsubst %.c,%.o,$(filter %.c,$(NATIVE_FILES))))
178 LIBTCC_INC = $(filter %.h,$(CORE_FILES)) $(filter-out $(CORE_FILES),$(NATIVE_FILES))
179 else
180 LIBTCC_OBJ = libtcc.o
181 LIBTCC_INC = $(NATIVE_FILES)
182 libtcc.o : NATIVE_DEFINES += -DONE_SOURCE
183 endif
185 $(LIBTCC_OBJ) tcc.o : %.o : %.c $(LIBTCC_INC)
186 $(CC) -o $@ -c $< $(NATIVE_DEFINES) $(CPPFLAGS) $(CFLAGS)
188 libtcc.a: $(LIBTCC_OBJ)
189 $(AR) rcs $@ $^
191 libtcc.so.1.0: $(LIBTCC_OBJ)
192 $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDFLAGS)
194 libtcc.so.1.0: CFLAGS+=-fPIC
196 # windows utilities
197 tiny_impdef$(EXESUF): win32/tools/tiny_impdef.c
198 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
199 tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c
200 $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
202 # TinyCC runtime libraries
203 libtcc1.a : FORCE
204 $(MAKE) -C lib native
205 lib/%/libtcc1.a : FORCE $(PROGS_CROSS)
206 $(MAKE) -C lib cross TARGET=$*
208 FORCE:
210 # install
211 TCC_INCLUDES = stdarg.h stddef.h stdbool.h float.h varargs.h tcclib.h
212 INSTALL=install
213 ifdef STRIP_BINARIES
214 INSTALLBIN=$(INSTALL) -s
215 else
216 INSTALLBIN=$(INSTALL)
217 endif
219 ifndef CONFIG_WIN32
220 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
221 mkdir -p "$(bindir)"
222 ifeq ($(CC),tcc)
223 $(INSTALL) -m755 $(PROGS) "$(bindir)"
224 else
225 $(INSTALLBIN) -m755 $(PROGS) "$(bindir)"
226 endif
227 mkdir -p "$(mandir)/man1"
228 -$(INSTALL) tcc.1 "$(mandir)/man1"
229 mkdir -p "$(infodir)"
230 -$(INSTALL) tcc-doc.info "$(infodir)"
231 mkdir -p "$(tccdir)"
232 mkdir -p "$(tccdir)/include"
233 ifneq ($(LIBTCC1),)
234 $(INSTALL) -m644 $(LIBTCC1) "$(tccdir)"
235 endif
236 $(INSTALL) -m644 $(addprefix $(top_srcdir)/include/,$(TCC_INCLUDES)) "$(tccdir)/include"
237 mkdir -p "$(libdir)"
238 $(INSTALL) -m755 $(LIBTCC) "$(libdir)"
239 ifdef DISABLE_STATIC
240 ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so.1"
241 ln -sf "$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so"
242 endif
243 mkdir -p "$(includedir)"
244 $(INSTALL) -m644 $(top_srcdir)/libtcc.h "$(includedir)"
245 mkdir -p "$(docdir)"
246 -$(INSTALL) -m644 tcc-doc.html "$(docdir)"
247 ifdef CONFIG_CROSS
248 mkdir -p "$(tccdir)/win32/lib/32"
249 mkdir -p "$(tccdir)/win32/lib/64"
250 ifeq ($(ARCH),x86-64)
251 mkdir -p "$(tccdir)/i386"
252 $(INSTALL) -m644 lib/i386/libtcc1.a "$(tccdir)/i386"
253 cp -r "$(tccdir)/include" "$(tccdir)/i386"
254 endif
255 $(INSTALL) -m644 win32/lib/*.def "$(tccdir)/win32/lib"
256 $(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/win32/lib/32"
257 $(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/win32/lib/64"
258 cp -r win32/include/. "$(tccdir)/win32/include"
259 cp -r include/. "$(tccdir)/win32/include"
260 endif
262 uninstall:
263 rm -fv $(foreach P,$(PROGS),"$(bindir)/$P")
264 rm -fv $(foreach P,$(LIBTCC1),"$(tccdir)/$P")
265 rm -fv $(foreach P,$(TCC_INCLUDES),"$(tccdir)/include/$P")
266 rm -fv "$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
267 rm -fv "$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
268 rm -fv "$(libdir)/libtcc.so*"
269 rm -rf "$(tccdir)/win32"
270 -rmdir $(tccdir)/include
271 ifeq ($(ARCH),x86-64)
272 rm -rf "$(tccdir)/i386"
273 endif
274 else
275 # on windows
276 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
277 mkdir -p "$(tccdir)"
278 mkdir -p "$(tccdir)/lib"
279 mkdir -p "$(tccdir)/include"
280 mkdir -p "$(tccdir)/examples"
281 mkdir -p "$(tccdir)/doc"
282 mkdir -p "$(tccdir)/libtcc"
283 $(INSTALLBIN) -m755 $(PROGS) "$(tccdir)"
284 $(INSTALL) -m644 $(LIBTCC1) $(top_srcdir)/win32/lib/*.def "$(tccdir)/lib"
285 cp -r $(top_srcdir)/win32/include/. "$(tccdir)/include"
286 cp -r $(top_srcdir)/win32/examples/. "$(tccdir)/examples"
287 $(INSTALL) -m644 $(addprefix $(top_srcdir)/include/,$(TCC_INCLUDES)) "$(tccdir)/include"
288 $(INSTALL) -m644 tcc-doc.html $(top_srcdir)/win32/tcc-win32.txt "$(tccdir)/doc"
289 $(INSTALL) -m644 $(LIBTCC) $(top_srcdir)/libtcc.h "$(tccdir)/libtcc"
290 ifdef CONFIG_CROSS
291 mkdir -p "$(tccdir)/lib/32"
292 mkdir -p "$(tccdir)/lib/64"
293 -$(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/lib/32"
294 -$(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/lib/64"
295 endif
297 uninstall:
298 rm -rfv "$(tccdir)/*"
299 endif
301 # documentation and man page
302 tcc-doc.html: tcc-doc.texi
303 makeinfo --no-split --html -o $@ $<
305 tcc.1: tcc-doc.texi
306 -$(top_srcdir)/texi2pod.pl $< tcc.pod
307 -pod2man --section=1 --center="Tiny C Compiler" --release=`cat $(top_srcdir)/VERSION` tcc.pod > $@
309 tcc-doc.info: tcc-doc.texi
310 -makeinfo $<
312 # in tests subdir
313 export LIBTCC1
315 %est:
316 $(MAKE) -C tests $@
318 clean:
319 rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.so* *.out *.exe libtcc_test$(EXESUF)
320 $(MAKE) -C tests $@
321 ifneq ($(LIBTCC1),)
322 $(MAKE) -C lib $@
323 endif
325 distclean: clean
326 rm -vf config.h config.mak config.texi tcc.1 tcc-doc.info tcc-doc.html
328 config.mak:
329 @echo "Please run ./configure."
330 @exit 1
332 # create release tarball from *current* git branch (including tcc-doc.html
333 # and converting two files to CRLF)
334 TCC-VERSION := tcc-$(shell cat $(top_srcdir)/VERSION)
335 tar: tcc-doc.html
336 mkdir $(TCC-VERSION)
337 ( cd $(TCC-VERSION) && git --git-dir ../.git checkout -f )
338 cp tcc-doc.html $(TCC-VERSION)
339 for f in tcc-win32.txt build-tcc.bat ; do \
340 cat win32/$$f | sed 's,\(.*\),\1\r,g' > $(TCC-VERSION)/win32/$$f ; \
341 done
342 tar cjf $(TCC-VERSION).tar.bz2 $(TCC-VERSION)
343 rm -rf $(TCC-VERSION)
344 git reset
347 .PHONY: all clean tar distclean install uninstall FORCE
349 endif # ifeq ($(TOP),.)