2 # Tiny C Compiler Makefile
6 include $(TOP
)/config.mak
9 CPPFLAGS_P
=$(CPPFLAGS
) -DCONFIG_TCC_STATIC
10 CFLAGS_P
=$(CFLAGS
) -pg
-static
14 ifneq ($(GCC_MAJOR
),2)
15 CFLAGS
+=-fno-strict-aliasing
16 ifneq ($(GCC_MAJOR
),3)
17 CFLAGS
+=-Wno-pointer-sign
-Wno-sign-compare
19 # add -Wno-unused-result only on gcc >= 4.4
21 GCCGREATERTHEN44
:= $(shell expr
`gcc -dumpversion | cut -f2 -d.` \
>= 4)
25 ifeq ($(GCCGREATERTHEN44
),1)
26 CFLAGS
+=-Wno-unused-result
32 ifneq ($(TARGETOS
),Darwin
)
34 CFLAGS
+=-mpreferred-stack-boundary
=2
36 CFLAGS
+=-m386
-malign-functions
=0
38 CFLAGS
+=-march
=i386
-falign-functions
=0
55 NATIVE_DEFINES
=-DTCC_TARGET_I386
56 NATIVE_DEFINES
+=$(if
$(wildcard /lib
/i386-linux-gnu
),-DCONFIG_MULTIARCHDIR
=\"i386-linux-gnu
\")
57 NATIVE_DEFINES
+=$(if
$(wildcard /lib
/i386-kfreebsd-gnu
),-DCONFIG_MULTIARCHDIR
=\"i386-kfreebsd-gnu
\")
58 NATIVE_DEFINES
+=$(if
$(wildcard /lib
/i386-gnu
),-DCONFIG_MULTIARCHDIR
=\"i386-gnu
\")
60 else ifeq ($(ARCH
),x86-64
)
61 NATIVE_DEFINES
=-DTCC_TARGET_X86_64
63 NATIVE_DEFINES
+=$(if
$(wildcard /usr
/lib64
),-DCONFIG_LDDIR
=\"lib64
\")
64 NATIVE_DEFINES
+=$(if
$(wildcard /lib
/x86_64-linux-gnu
),-DCONFIG_MULTIARCHDIR
=\"x86_64-linux-gnu
\")
65 NATIVE_DEFINES
+=$(if
$(wildcard /lib
/x86_64-kfreebsd-gnu
),-DCONFIG_MULTIARCHDIR
=\"x86_64-kfreebsd-gnu
\")
69 NATIVE_DEFINES
=-DTCC_TARGET_ARM
70 NATIVE_DEFINES
+=-DWITHOUT_LIBTCC
71 ifneq (,$(wildcard /lib
/ld-linux.so
.3))
72 NATIVE_DEFINES
+=-DTCC_ARM_EABI
73 NATIVE_DEFINES
+=$(if
$(wildcard /lib
/arm-linux-gnueabi
), -DCONFIG_MULTIARCHDIR
=\"arm-linux-gnueabi
\")
74 else ifneq (,$(wildcard /lib
/ld-linux-armhf.so
.3 /lib
/arm-linux-gnueabihf
/ld-linux.so
.3))
75 NATIVE_DEFINES
+=-DTCC_ARM_EABI
-DTCC_ARM_HARDFLOAT
76 NATIVE_DEFINES
+=$(if
$(wildcard /lib
/arm-linux-gnueabihf
),-DCONFIG_MULTIARCHDIR
=\"arm-linux-gnueabihf
\")
78 NATIVE_DEFINES
+=$(if
$(shell grep
-l
"^Features.* \(vfp\|iwmmxt\) " /proc
/cpuinfo
),-DTCC_ARM_VFP
)
82 NATIVE_DEFINES
+=-DTCC_TARGET_PE
85 ifneq ($(wildcard /lib
/ld-uClibc.so
.0),)
86 NATIVE_DEFINES
+=-DTCC_UCLIBC
90 # make libtcc as static or dynamic library?
93 LINK_LIBTCC
=-Wl
,-rpath
,"$(libdir)"
105 I386_CROSS
= i386-tcc
$(EXESUF
)
106 WIN32_CROSS
= i386-win32-tcc
$(EXESUF
)
107 WIN64_CROSS
= x86_64-win32-tcc
$(EXESUF
)
108 WINCE_CROSS
= arm-win32-tcc
$(EXESUF
)
109 X64_CROSS
= x86_64-tcc
$(EXESUF
)
110 ARM_FPA_CROSS
= arm-fpa-tcc
$(EXESUF
)
111 ARM_FPA_LD_CROSS
= arm-fpa-ld-tcc
$(EXESUF
)
112 ARM_VFP_CROSS
= arm-vfp-tcc
$(EXESUF
)
113 ARM_EABI_CROSS
= arm-eabi-tcc
$(EXESUF
)
114 ARM_CROSS
= $(ARM_FPA_CROSS
) $(ARM_FPA_LD_CROSS
) $(ARM_VFP_CROSS
) $(ARM_EABI_CROSS
)
115 C67_CROSS
= c67-tcc
$(EXESUF
)
117 CORE_FILES
= tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
118 CORE_FILES
+= tcc.h config.h libtcc.h tcctok.h
119 I386_FILES
= $(CORE_FILES
) i386-gen.c i386-asm.c i386-asm.h i386-tok.h
120 WIN32_FILES
= $(CORE_FILES
) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
121 WIN64_FILES
= $(CORE_FILES
) x86_64-gen.c i386-asm.c x86_64-asm.h tccpe.c
122 WINCE_FILES
= $(CORE_FILES
) arm-gen.c tccpe.c
123 X86_64_FILES
= $(CORE_FILES
) x86_64-gen.c i386-asm.c x86_64-asm.h
124 ARM_FILES
= $(CORE_FILES
) arm-gen.c
125 C67_FILES
= $(CORE_FILES
) c67-gen.c tcccoff.c
128 PROGS
+=tiny_impdef
$(EXESUF
) tiny_libmaker
$(EXESUF
)
129 NATIVE_FILES
=$(WIN64_FILES
)
130 PROGS_CROSS
=$(WIN32_CROSS
) $(I386_CROSS
) $(X64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
)
131 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a
133 else ifdef CONFIG_WIN32
134 PROGS
+=tiny_impdef
$(EXESUF
) tiny_libmaker
$(EXESUF
)
135 NATIVE_FILES
=$(WIN32_FILES
)
136 PROGS_CROSS
=$(WIN64_CROSS
) $(I386_CROSS
) $(X64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
)
137 LIBTCC1_CROSS
=lib
/x86_64-win32
/libtcc1.a
139 else ifeq ($(ARCH
),i386
)
140 NATIVE_FILES
=$(I386_FILES
)
141 PROGS_CROSS
=$(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
)
142 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a lib
/x86_64-win32
/libtcc1.a
145 else ifeq ($(ARCH
),x86-64
)
146 NATIVE_FILES
=$(X86_64_FILES
)
147 PROGS_CROSS
=$(I386_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
)
148 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a lib
/x86_64-win32
/libtcc1.a lib
/i386
/libtcc1.a
150 else ifeq ($(ARCH
),arm
)
151 NATIVE_FILES
=$(ARM_FILES
)
152 PROGS_CROSS
=$(I386_CROSS
) $(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(C67_CROSS
)
158 ifeq ($(TARGETOS
),Darwin
)
160 PROGS
+=tiny_libmaker
$(EXESUF
)
163 ifdef CONFIG_USE_LIBGCC
167 TCCLIBS
= $(LIBTCC1
) $(LIBTCC
) $(BCHECK_O
)
168 TCCDOCS
= tcc
.1 tcc-doc.html tcc-doc.
info
171 PROGS
+=$(PROGS_CROSS
)
172 TCCLIBS
+=$(LIBTCC1_CROSS
)
175 all: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
177 # Host Tiny C Compiler
178 tcc
$(EXESUF
): tcc.o
$(LIBTCC
)
179 $(CC
) -o
$@
$^
$(LIBS
) $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
) $(LINK_LIBTCC
)
181 # Cross Tiny C Compilers
183 $(CC
) -o
$@ tcc.c
-DONE_SOURCE
$(DEFINES
) $(CPPFLAGS
) $(CFLAGS
) $(LIBS
) $(LDFLAGS
)
185 $(I386_CROSS
): DEFINES
= -DTCC_TARGET_I386 \
186 -DCONFIG_TCCDIR
="\"$(tccdir)/i386\""
187 $(X64_CROSS
): DEFINES
= -DTCC_TARGET_X86_64
188 $(WIN32_CROSS
): DEFINES
= -DTCC_TARGET_I386
-DTCC_TARGET_PE \
189 -DCONFIG_TCCDIR
="\"$(tccdir)/win32\"" \
190 -DCONFIG_TCC_LIBPATHS
="\"{B}/lib/32;{B}/lib\""
191 $(WIN64_CROSS
): DEFINES
= -DTCC_TARGET_X86_64
-DTCC_TARGET_PE \
192 -DCONFIG_TCCDIR
="\"$(tccdir)/win32\"" \
193 -DCONFIG_TCC_LIBPATHS
="\"{B}/lib/64;{B}/lib\""
194 $(WINCE_CROSS
): DEFINES
= -DTCC_TARGET_PE
195 $(C67_CROSS
): DEFINES
= -DTCC_TARGET_C67
196 $(ARM_FPA_CROSS
): DEFINES
= -DTCC_TARGET_ARM
197 $(ARM_FPA_LD_CROSS
)$(EXESUF
): DEFINES
= -DTCC_TARGET_ARM
-DLDOUBLE_SIZE
=12
198 $(ARM_VFP_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_ARM_VFP
199 $(ARM_EABI_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_ARM_EABI
201 $(I386_CROSS
): $(I386_FILES
)
202 $(X64_CROSS
): $(X86_64_FILES
)
203 $(WIN32_CROSS
): $(WIN32_FILES
)
204 $(WIN64_CROSS
): $(WIN64_FILES
)
205 $(WINCE_CROSS
): $(WINCE_FILES
)
206 $(C67_CROSS
): $(C67_FILES
)
207 $(ARM_FPA_CROSS
) $(ARM_FPA_LD_CROSS
) $(ARM_VFP_CROSS
) $(ARM_EABI_CROSS
): $(ARM_FILES
)
209 # libtcc generation and test
211 LIBTCC_OBJ
= $(filter-out tcc.o
,$(patsubst %.c
,%.o
,$(filter %.c
,$(NATIVE_FILES
))))
212 LIBTCC_INC
= $(filter %.h
,$(CORE_FILES
)) $(filter-out $(CORE_FILES
),$(NATIVE_FILES
))
214 LIBTCC_OBJ
= libtcc.o
215 LIBTCC_INC
= $(NATIVE_FILES
)
216 libtcc.o
: NATIVE_DEFINES
+= -DONE_SOURCE
219 $(LIBTCC_OBJ
) tcc.o
: %.o
: %.c
$(LIBTCC_INC
)
220 $(CC
) -o
$@
-c
$< $(NATIVE_DEFINES
) $(CPPFLAGS
) $(CFLAGS
)
222 libtcc.a
: $(LIBTCC_OBJ
)
225 libtcc.so
.1.0: $(LIBTCC_OBJ
)
226 $(CC
) -shared
-Wl
,-soname
,$@
-o
$@
$^
$(LDFLAGS
)
228 libtcc.so
.1.0: CFLAGS
+=-fPIC
231 tcc_p
$(EXESUF
): $(NATIVE_FILES
)
232 $(CC
) -o
$@
$< $(NATIVE_DEFINES
) $(CPPFLAGS_P
) $(CFLAGS_P
) $(LIBS_P
) $(LDFLAGS_P
)
235 tiny_impdef
$(EXESUF
): win32
/tools
/tiny_impdef.c
236 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
237 tiny_libmaker
$(EXESUF
): win32
/tools
/tiny_libmaker.c
238 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
240 # TinyCC runtime libraries
242 @
$(MAKE
) -C lib native
243 lib
/%/libtcc1.a
: FORCE
$(PROGS_CROSS
)
244 @
$(MAKE
) -C lib cross TARGET
=$*
245 bcheck.o
: lib
/bcheck.c
246 gcc
-c
$< -o
$@
$(CPPFLAGS
) $(CFLAGS
)
250 TCC_INCLUDES
= stdarg.h stddef.h stdbool.h float.h varargs.h tcclib.h
253 INSTALLBIN
=$(INSTALL
) -s
255 INSTALLBIN
=$(INSTALL
)
259 install: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
262 $(INSTALL
) -m755
$(PROGS
) "$(bindir)"
264 $(INSTALLBIN
) -m755
$(PROGS
) "$(bindir)"
266 mkdir
-p
"$(mandir)/man1"
267 -$(INSTALL
) tcc
.1 "$(mandir)/man1"
268 mkdir
-p
"$(infodir)"
269 -$(INSTALL
) tcc-doc.
info "$(infodir)"
271 mkdir
-p
"$(tccdir)/include"
273 $(INSTALL
) -m644
$(LIBTCC1
) "$(tccdir)"
276 $(INSTALL
) -m644
$(BCHECK_O
) "$(tccdir)"
278 $(INSTALL
) -m644
$(addprefix include/,$(TCC_INCLUDES
)) "$(tccdir)/include"
280 $(INSTALL
) -m755
$(LIBTCC
) "$(libdir)"
282 ln
-sf
"$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so.1"
283 ln
-sf
"$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so"
285 mkdir
-p
"$(includedir)"
286 $(INSTALL
) -m644 libtcc.h
"$(includedir)"
288 -$(INSTALL
) -m644 tcc-doc.html
"$(docdir)"
290 mkdir
-p
"$(tccdir)/win32/lib/32"
291 mkdir
-p
"$(tccdir)/win32/lib/64"
292 ifeq ($(ARCH
),x86-64
)
293 mkdir
-p
"$(tccdir)/i386"
294 $(INSTALL
) -m644 lib
/i386
/libtcc1.a
"$(tccdir)/i386"
295 cp
-r
"$(tccdir)/include" "$(tccdir)/i386"
297 $(INSTALL
) -m644 win32
/lib
/*.def
"$(tccdir)/win32/lib"
298 $(INSTALL
) -m644 lib
/i386-win32
/libtcc1.a
"$(tccdir)/win32/lib/32"
299 $(INSTALL
) -m644 lib
/x86_64-win32
/libtcc1.a
"$(tccdir)/win32/lib/64"
300 cp
-r win32
/include/.
"$(tccdir)/win32/include"
301 cp
-r
include/.
"$(tccdir)/win32/include"
305 rm -fv
$(foreach P
,$(PROGS
),"$(bindir)/$P")
306 rm -fv
$(foreach P
,$(LIBTCC1
) $(BCHECK_O
),"$(tccdir)/$P")
307 rm -fv
$(foreach P
,$(TCC_INCLUDES
),"$(tccdir)/include/$P")
308 rm -fv
"$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
309 rm -fv
"$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
310 rm -fv
"$(libdir)/libtcc.so*"
311 rm -rf
"$(tccdir)/win32"
312 -rmdir
$(tccdir
)/include
313 ifeq ($(ARCH
),x86-64
)
314 rm -rf
"$(tccdir)/i386"
318 install: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
320 mkdir
-p
"$(tccdir)/lib"
321 mkdir
-p
"$(tccdir)/include"
322 mkdir
-p
"$(tccdir)/examples"
323 mkdir
-p
"$(tccdir)/doc"
324 mkdir
-p
"$(tccdir)/libtcc"
325 $(INSTALLBIN
) -m755
$(PROGS
) "$(tccdir)"
326 $(INSTALL
) -m644
$(LIBTCC1
) win32
/lib
/*.def
"$(tccdir)/lib"
327 cp
-r win32
/include/.
"$(tccdir)/include"
328 cp
-r win32
/examples
/.
"$(tccdir)/examples"
329 $(INSTALL
) -m644
$(addprefix include/,$(TCC_INCLUDES
)) "$(tccdir)/include"
330 $(INSTALL
) -m644 tcc-doc.html win32
/tcc-win32.txt
"$(tccdir)/doc"
331 $(INSTALL
) -m644
$(LIBTCC
) libtcc.h
"$(tccdir)/libtcc"
333 mkdir
-p
"$(tccdir)/lib/32"
334 mkdir
-p
"$(tccdir)/lib/64"
335 -$(INSTALL
) -m644 lib
/i386-win32
/libtcc1.a
"$(tccdir)/lib/32"
336 -$(INSTALL
) -m644 lib
/x86_64-win32
/libtcc1.a
"$(tccdir)/lib/64"
340 rm -rfv
"$(tccdir)/*"
343 # documentation and man page
344 tcc-doc.html
: tcc-doc.texi
345 -texi2html
-monolithic
-number
$<
348 -$(top_srcdir
)/texi2pod.pl
$< tcc.pod
349 -pod2man
--section
=1 --center
=" " --release
=" " tcc.pod
> $@
351 tcc-doc.
info: tcc-doc.texi
362 rm -vf
$(PROGS
) tcc_p
$(EXESUF
) tcc.pod
*~
*.o
*.a
*.so
* *.out
*.exe libtcc_test
$(EXESUF
)
370 rm -vf config.h config.mak config.texi tcc
.1 tcc-doc.
info tcc-doc.html
373 @echo
"Please run ./configure."
376 # create release tarball from *current* git branch (including tcc-doc.html
377 # and converting two files to CRLF)
378 TCC-VERSION
:= tcc-
$(shell cat
$(top_srcdir
)/VERSION
)
381 ( cd
$(TCC-VERSION
) && git
--git-dir ..
/.git checkout
-f
)
382 cp tcc-doc.html
$(TCC-VERSION
)
383 for f in tcc-win32.txt build-tcc.bat
; do \
384 cat win32
/$$f | sed
's,\(.*\),\1\r,g' > $(TCC-VERSION
)/win32
/$$f ; \
386 tar cjf
$(TCC-VERSION
).
tar.bz2
$(TCC-VERSION
)
387 rm -rf
$(TCC-VERSION
)
391 .PHONY
: all clean tar distclean install uninstall FORCE
393 endif # ifeq ($(TOP),.)