2 # Tiny C Compiler Makefile
6 include $(TOP
)/config.mak
9 CPPFLAGS
= -I
$(TOP
) # for config.h
11 CPPFLAGS_P
=$(CPPFLAGS
) -DCONFIG_TCC_STATIC
12 CFLAGS_P
=$(CFLAGS
) -pg
-static
16 ifneq ($(GCC_MAJOR
),2)
17 CFLAGS
+=-fno-strict-aliasing
18 ifneq ($(GCC_MAJOR
),3)
19 CFLAGS
+=-Wno-pointer-sign
-Wno-sign-compare
23 ifneq ($(TARGETOS
),Darwin
)
25 CFLAGS
+=-mpreferred-stack-boundary
=2
27 CFLAGS
+=-m386
-malign-functions
=0
29 CFLAGS
+=-march
=i386
-falign-functions
=0
46 NATIVE_DEFINES
=-DTCC_TARGET_I386
48 $(if
$(wildcard /lib
/i386-linux-gnu
),-DCONFIG_MULTIARCHDIR
=\"i386-linux-gnu
\",\
49 $(if
$(wildcard /lib
/i386-kfreebsd-gnu
),-DCONFIG_MULTIARCHDIR
=\"i386-kfreebsd-gnu
\",\
50 $(if
$(wildcard /lib
/i386-gnu
),-DCONFIG_MULTIARCHDIR
=\"i386-gnu
\")))
52 else ifeq ($(ARCH
),x86-64
)
53 NATIVE_DEFINES
=-DTCC_TARGET_X86_64
56 $(if
$(wildcard /usr
/lib64
),-DCONFIG_LDDIR
=\"lib64
\",\
57 $(if
$(wildcard /lib
/x86_64-linux-gnu
),-DCONFIG_MULTIARCHDIR
=\"x86_64-linux-gnu
\",\
58 $(if
$(wildcard /lib
/x86_64-kfreebsd-gnu
),-DCONFIG_MULTIARCHDIR
=\"x86_64-kfreebsd-gnu
\")))
62 NATIVE_DEFINES
=-DTCC_TARGET_ARM
63 NATIVE_DEFINES
+=-DWITHOUT_LIBTCC
64 ifneq (,$(wildcard /lib
/ld-linux-armhf.so
.3 /lib
/arm-linux-gnueabihf
/ld-linux.so
.3))
65 NATIVE_DEFINES
+=-DTCC_ARM_EABI
-DTCC_ARM_HARDFLOAT
66 NATIVE_DEFINES
+=$(if
$(wildcard /lib
/arm-linux-gnueabihf
),-DCONFIG_MULTIARCHDIR
=\"arm-linux-gnueabihf
\")
67 else ifneq (,$(wildcard /lib
/ld-linux.so
.3))
68 NATIVE_DEFINES
+=-DTCC_ARM_EABI
69 NATIVE_DEFINES
+=$(if
$(wildcard /lib
/arm-linux-gnueabi
), -DCONFIG_MULTIARCHDIR
=\"arm-linux-gnueabi
\")
71 NATIVE_DEFINES
+=$(if
$(shell grep
-l
"^Features.* \(vfp\|iwmmxt\) " /proc
/cpuinfo
),-DTCC_ARM_VFP
)
75 NATIVE_DEFINES
+=-DTCC_TARGET_PE
78 ifneq ($(wildcard /lib
/ld-uClibc.so
.0),)
79 NATIVE_DEFINES
+=-DTCC_UCLIBC
83 # make libtcc as static or dynamic library?
86 LINK_LIBTCC
=-Wl
,-rpath
,"$(libdir)"
98 I386_CROSS
= i386-tcc
$(EXESUF
)
99 WIN32_CROSS
= i386-win32-tcc
$(EXESUF
)
100 WIN64_CROSS
= x86_64-win32-tcc
$(EXESUF
)
101 WINCE_CROSS
= arm-win32-tcc
$(EXESUF
)
102 X64_CROSS
= x86_64-tcc
$(EXESUF
)
103 ARM_FPA_CROSS
= arm-fpa-tcc
$(EXESUF
)
104 ARM_FPA_LD_CROSS
= arm-fpa-ld-tcc
$(EXESUF
)
105 ARM_VFP_CROSS
= arm-vfp-tcc
$(EXESUF
)
106 ARM_EABI_CROSS
= arm-eabi-tcc
$(EXESUF
)
107 ARM_CROSS
= $(ARM_FPA_CROSS
) $(ARM_FPA_LD_CROSS
) $(ARM_VFP_CROSS
) $(ARM_EABI_CROSS
)
108 C67_CROSS
= c67-tcc
$(EXESUF
)
110 CORE_FILES
= tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
111 CORE_FILES
+= tcc.h config.h libtcc.h tcctok.h
112 I386_FILES
= $(CORE_FILES
) i386-gen.c i386-asm.c i386-asm.h i386-tok.h
113 WIN32_FILES
= $(CORE_FILES
) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
114 WIN64_FILES
= $(CORE_FILES
) x86_64-gen.c i386-asm.c x86_64-asm.h tccpe.c
115 WINCE_FILES
= $(CORE_FILES
) arm-gen.c tccpe.c
116 X86_64_FILES
= $(CORE_FILES
) x86_64-gen.c i386-asm.c x86_64-asm.h
117 ARM_FILES
= $(CORE_FILES
) arm-gen.c
118 C67_FILES
= $(CORE_FILES
) c67-gen.c tcccoff.c
121 PROGS
+=tiny_impdef
$(EXESUF
) tiny_libmaker
$(EXESUF
)
122 NATIVE_FILES
=$(WIN64_FILES
)
123 PROGS_CROSS
=$(WIN32_CROSS
) $(I386_CROSS
) $(X64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
)
124 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a
126 else ifdef CONFIG_WIN32
127 PROGS
+=tiny_impdef
$(EXESUF
) tiny_libmaker
$(EXESUF
)
128 NATIVE_FILES
=$(WIN32_FILES
)
129 PROGS_CROSS
=$(WIN64_CROSS
) $(I386_CROSS
) $(X64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
)
130 LIBTCC1_CROSS
=lib
/x86_64-win32
/libtcc1.a
132 else ifeq ($(ARCH
),i386
)
133 NATIVE_FILES
=$(I386_FILES
)
134 PROGS_CROSS
=$(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
)
135 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a lib
/x86_64-win32
/libtcc1.a
138 else ifeq ($(ARCH
),x86-64
)
139 NATIVE_FILES
=$(X86_64_FILES
)
140 PROGS_CROSS
=$(I386_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
)
141 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a lib
/x86_64-win32
/libtcc1.a lib
/i386
/libtcc1.a
143 else ifeq ($(ARCH
),arm
)
144 NATIVE_FILES
=$(ARM_FILES
)
145 PROGS_CROSS
=$(I386_CROSS
) $(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(C67_CROSS
)
151 ifeq ($(TARGETOS
),Darwin
)
153 PROGS
+=tiny_libmaker
$(EXESUF
)
156 ifdef CONFIG_USE_LIBGCC
160 TCCLIBS
= $(LIBTCC1
) $(LIBTCC
) $(BCHECK_O
)
161 TCCDOCS
= tcc
.1 tcc-doc.html tcc-doc.
info
164 PROGS
+=$(PROGS_CROSS
)
165 TCCLIBS
+=$(LIBTCC1_CROSS
)
168 all: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
170 # Host Tiny C Compiler
171 tcc
$(EXESUF
): tcc.o
$(LIBTCC
)
172 $(CC
) -o
$@
$^
$(LIBS
) $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
) $(LINK_LIBTCC
)
174 # Cross Tiny C Compilers
175 %-tcc
$(EXESUF
): tcc.c
176 $(CC
) -o
$@
$< -DONE_SOURCE
$(DEFINES
) $(CPPFLAGS
) $(CFLAGS
) $(LIBS
) $(LDFLAGS
)
178 $(I386_CROSS
): DEFINES
= -DTCC_TARGET_I386 \
179 -DCONFIG_TCCDIR
="\"$(tccdir)/i386\""
180 $(X64_CROSS
): DEFINES
= -DTCC_TARGET_X86_64
181 $(WIN32_CROSS
): DEFINES
= -DTCC_TARGET_I386
-DTCC_TARGET_PE \
182 -DCONFIG_TCCDIR
="\"$(tccdir)/win32\"" \
183 -DCONFIG_TCC_LIBPATHS
="\"{B}/lib/32;{B}/lib\""
184 $(WIN64_CROSS
): DEFINES
= -DTCC_TARGET_X86_64
-DTCC_TARGET_PE \
185 -DCONFIG_TCCDIR
="\"$(tccdir)/win32\"" \
186 -DCONFIG_TCC_LIBPATHS
="\"{B}/lib/64;{B}/lib\""
187 $(WINCE_CROSS
): DEFINES
= -DTCC_TARGET_PE
188 $(C67_CROSS
): DEFINES
= -DTCC_TARGET_C67
189 $(ARM_FPA_CROSS
): DEFINES
= -DTCC_TARGET_ARM
190 $(ARM_FPA_LD_CROSS
)$(EXESUF
): DEFINES
= -DTCC_TARGET_ARM
-DLDOUBLE_SIZE
=12
191 $(ARM_VFP_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_ARM_VFP
192 $(ARM_EABI_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_ARM_EABI
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
)
202 # libtcc generation and test
204 LIBTCC_OBJ
= $(filter-out tcc.o
,$(patsubst %.c
,%.o
,$(filter %.c
,$(NATIVE_FILES
))))
205 LIBTCC_INC
= $(filter %.h
,$(CORE_FILES
)) $(filter-out $(CORE_FILES
),$(NATIVE_FILES
))
207 LIBTCC_OBJ
= libtcc.o
208 LIBTCC_INC
= $(NATIVE_FILES
)
209 libtcc.o
: NATIVE_DEFINES
+= -DONE_SOURCE
212 $(LIBTCC_OBJ
) tcc.o
: %.o
: %.c
$(LIBTCC_INC
)
213 $(CC
) -o
$@
-c
$< $(NATIVE_DEFINES
) $(CPPFLAGS
) $(CFLAGS
)
215 libtcc.a
: $(LIBTCC_OBJ
)
218 libtcc.so
.1.0: $(LIBTCC_OBJ
)
219 $(CC
) -shared
-Wl
,-soname
,$@
-o
$@
$^
$(LDFLAGS
)
221 libtcc.so
.1.0: CFLAGS
+=-fPIC
224 tcc_p
$(EXESUF
): $(NATIVE_FILES
)
225 $(CC
) -o
$@
$< $(NATIVE_DEFINES
) $(CPPFLAGS_P
) $(CFLAGS_P
) $(LIBS_P
) $(LDFLAGS_P
)
228 tiny_impdef
$(EXESUF
): win32
/tools
/tiny_impdef.c
229 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
230 tiny_libmaker
$(EXESUF
): win32
/tools
/tiny_libmaker.c
231 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
233 # TinyCC runtime libraries
235 @
$(MAKE
) -C lib native
236 lib
/%/libtcc1.a
: FORCE
$(PROGS_CROSS
)
237 @
$(MAKE
) -C lib cross TARGET
=$*
238 bcheck.o
: lib
/bcheck.c
239 gcc
-c
$< -o
$@
$(CPPFLAGS
) $(CFLAGS
)
243 TCC_INCLUDES
= stdarg.h stddef.h stdbool.h float.h varargs.h tcclib.h
246 INSTALLBIN
=$(INSTALL
) -s
248 INSTALLBIN
=$(INSTALL
)
252 install: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
255 $(INSTALL
) -m755
$(PROGS
) "$(bindir)"
257 $(INSTALLBIN
) -m755
$(PROGS
) "$(bindir)"
259 mkdir
-p
"$(mandir)/man1"
260 -$(INSTALL
) tcc
.1 "$(mandir)/man1"
261 mkdir
-p
"$(infodir)"
262 -$(INSTALL
) tcc-doc.
info "$(infodir)"
264 mkdir
-p
"$(tccdir)/include"
266 $(INSTALL
) -m644
$(LIBTCC1
) "$(tccdir)"
269 $(INSTALL
) -m644
$(BCHECK_O
) "$(tccdir)"
271 $(INSTALL
) -m644
$(addprefix $(top_srcdir
)/include/,$(TCC_INCLUDES
)) "$(tccdir)/include"
273 $(INSTALL
) -m755
$(LIBTCC
) "$(libdir)"
275 ln
-sf
"$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so.1"
276 ln
-sf
"$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so"
278 mkdir
-p
"$(includedir)"
279 $(INSTALL
) -m644
$(top_srcdir
)/libtcc.h
"$(includedir)"
281 -$(INSTALL
) -m644 tcc-doc.html
"$(docdir)"
283 mkdir
-p
"$(tccdir)/win32/lib/32"
284 mkdir
-p
"$(tccdir)/win32/lib/64"
285 ifeq ($(ARCH
),x86-64
)
286 mkdir
-p
"$(tccdir)/i386"
287 $(INSTALL
) -m644 lib
/i386
/libtcc1.a
"$(tccdir)/i386"
288 cp
-r
"$(tccdir)/include" "$(tccdir)/i386"
290 $(INSTALL
) -m644 win32
/lib
/*.def
"$(tccdir)/win32/lib"
291 $(INSTALL
) -m644 lib
/i386-win32
/libtcc1.a
"$(tccdir)/win32/lib/32"
292 $(INSTALL
) -m644 lib
/x86_64-win32
/libtcc1.a
"$(tccdir)/win32/lib/64"
293 cp
-r win32
/include/.
"$(tccdir)/win32/include"
294 cp
-r
include/.
"$(tccdir)/win32/include"
298 rm -fv
$(foreach P
,$(PROGS
),"$(bindir)/$P")
299 rm -fv
$(foreach P
,$(LIBTCC1
) $(BCHECK_O
),"$(tccdir)/$P")
300 rm -fv
$(foreach P
,$(TCC_INCLUDES
),"$(tccdir)/include/$P")
301 rm -fv
"$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
302 rm -fv
"$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
303 rm -fv
"$(libdir)/libtcc.so*"
304 rm -rf
"$(tccdir)/win32"
305 -rmdir
$(tccdir
)/include
306 ifeq ($(ARCH
),x86-64
)
307 rm -rf
"$(tccdir)/i386"
311 install: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
313 mkdir
-p
"$(tccdir)/lib"
314 mkdir
-p
"$(tccdir)/include"
315 mkdir
-p
"$(tccdir)/examples"
316 mkdir
-p
"$(tccdir)/doc"
317 mkdir
-p
"$(tccdir)/libtcc"
318 $(INSTALLBIN
) -m755
$(PROGS
) "$(tccdir)"
319 $(INSTALL
) -m644
$(LIBTCC1
) win32
/lib
/*.def
"$(tccdir)/lib"
320 cp
-r win32
/include/.
"$(tccdir)/include"
321 cp
-r win32
/examples
/.
"$(tccdir)/examples"
322 $(INSTALL
) -m644
$(addprefix include/,$(TCC_INCLUDES
)) "$(tccdir)/include"
323 $(INSTALL
) -m644 tcc-doc.html win32
/tcc-win32.txt
"$(tccdir)/doc"
324 $(INSTALL
) -m644
$(LIBTCC
) libtcc.h
"$(tccdir)/libtcc"
326 mkdir
-p
"$(tccdir)/lib/32"
327 mkdir
-p
"$(tccdir)/lib/64"
328 -$(INSTALL
) -m644 lib
/i386-win32
/libtcc1.a
"$(tccdir)/lib/32"
329 -$(INSTALL
) -m644 lib
/x86_64-win32
/libtcc1.a
"$(tccdir)/lib/64"
333 rm -rfv
"$(tccdir)/*"
336 # documentation and man page
337 tcc-doc.html
: tcc-doc.texi
338 -texi2html
-monolithic
-number
$<
341 -$(top_srcdir
)/texi2pod.pl
$< tcc.pod
342 -pod2man
--section
=1 --center
=" " --release
=" " tcc.pod
> $@
344 tcc-doc.
info: tcc-doc.texi
355 rm -vf
$(PROGS
) tcc_p
$(EXESUF
) tcc.pod
*~
*.o
*.a
*.so
* *.out
*.exe libtcc_test
$(EXESUF
)
363 rm -vf config.h config.mak config.texi tcc
.1 tcc-doc.
info tcc-doc.html
366 @echo
"Please run ./configure."
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
)
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 ; \
379 tar cjf
$(TCC-VERSION
).
tar.bz2
$(TCC-VERSION
)
380 rm -rf
$(TCC-VERSION
)
384 .PHONY
: all clean tar distclean install uninstall FORCE
386 endif # ifeq ($(TOP),.)