2 # Tiny C Compiler Makefile
6 include $(TOP
)/config.mak
8 CFLAGS_P
=$(CFLAGS
) -pg
-static
-DCONFIG_TCC_STATIC
11 ifneq ($(GCC_MAJOR
),2)
12 CFLAGS
+=-fno-strict-aliasing
13 ifneq ($(GCC_MAJOR
),3)
14 CFLAGS
+=-Wno-pointer-sign
-Wno-sign-compare
-D_FORTIFY_SOURCE
=0
18 ifneq ($(TARGETOS
),Darwin
)
20 CFLAGS
+=-mpreferred-stack-boundary
=2
22 CFLAGS
+=-m386
-malign-functions
=0
24 CFLAGS
+=-march
=i386
-falign-functions
=0
41 NATIVE_DEFINES
=-DTCC_TARGET_I386
42 NATIVE_DEFINES
+=$(if
$(wildcard /lib
/i386-linux-gnu
),-DCONFIG_MULTIARCHDIR
=\"i386-linux-gnu
\")
43 NATIVE_DEFINES
+=$(if
$(wildcard /lib
/i386-kfreebsd-gnu
),-DCONFIG_MULTIARCHDIR
=\"i386-kfreebsd-gnu
\")
44 NATIVE_DEFINES
+=$(if
$(wildcard /lib
/i386-gnu
),-DCONFIG_MULTIARCHDIR
=\"i386-gnu
\")
48 NATIVE_DEFINES
=-DTCC_TARGET_X86_64
50 NATIVE_DEFINES
+=$(if
$(wildcard /usr
/lib64
),-DCONFIG_LDDIR
=\"lib64
\")
51 NATIVE_DEFINES
+=$(if
$(wildcard /lib
/x86_64-linux-gnu
),-DCONFIG_MULTIARCHDIR
=\"x86_64-linux-gnu
\")
52 NATIVE_DEFINES
+=$(if
$(wildcard /lib
/x86_64-kfreebsd-gnu
),-DCONFIG_MULTIARCHDIR
=\"x86_64-kfreebsd-gnu
\")
57 NATIVE_DEFINES
=-DTCC_TARGET_ARM
58 NATIVE_DEFINES
+=-DWITHOUT_LIBTCC
59 NATIVE_DEFINES
+=$(if
$(wildcard /lib
/ld-linux.so
.3),-DTCC_ARM_EABI
)
60 NATIVE_DEFINES
+=$(if
$(wildcard /lib
/arm-linux-gnueabi
),-DCONFIG_MULTIARCHDIR
=\"arm-linux-gnueabi
\")
61 NATIVE_DEFINES
+=$(if
$(shell grep
-l
"^Features.* \(vfp\|iwmmxt\) " /proc
/cpuinfo
),-DTCC_ARM_VFP
)
62 # To use ARM hardfloat calling convension
63 #NATIVE_DEFINES+=-DTCC_ARM_HARDFLOAT
67 NATIVE_DEFINES
+=-DTCC_TARGET_PE
70 ifneq ($(wildcard /lib
/ld-uClibc.so
.0),)
71 NATIVE_DEFINES
+=-DTCC_UCLIBC
75 # make libtcc as static or dynamic library?
78 LINK_LIBTCC
=-Wl
,-rpath
,"$(libdir)"
90 I386_CROSS
= i386-tcc
$(EXESUF
)
91 WIN32_CROSS
= i386-win32-tcc
$(EXESUF
)
92 WIN64_CROSS
= x86_64-win32-tcc
$(EXESUF
)
93 WINCE_CROSS
= arm-win32-tcc
$(EXESUF
)
94 X64_CROSS
= x86_64-tcc
$(EXESUF
)
95 ARM_FPA_CROSS
= arm-fpa-tcc
$(EXESUF
)
96 ARM_FPA_LD_CROSS
= arm-fpa-ld-tcc
$(EXESUF
)
97 ARM_VFP_CROSS
= arm-vfp-tcc
$(EXESUF
)
98 ARM_EABI_CROSS
= arm-eabi-tcc
$(EXESUF
)
99 ARM_CROSS
= $(ARM_FPA_CROSS
) $(ARM_FPA_LD_CROSS
) $(ARM_VFP_CROSS
) $(ARM_EABI_CROSS
)
100 C67_CROSS
= c67-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
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
120 PROGS
+=tiny_impdef
$(EXESUF
) tiny_libmaker
$(EXESUF
)
121 NATIVE_FILES
=$(WIN32_FILES
)
122 PROGS_CROSS
=$(WIN64_CROSS
) $(I386_CROSS
) $(X64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
)
123 LIBTCC1_CROSS
=lib
/x86_64-win32
/libtcc1.a
127 NATIVE_FILES
=$(I386_FILES
)
128 PROGS_CROSS
=$(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
)
129 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a lib
/x86_64-win32
/libtcc1.a
133 ifeq ($(ARCH
),x86-64
)
134 NATIVE_FILES
=$(X86_64_FILES
)
135 PROGS_CROSS
=$(I386_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
)
136 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a lib
/x86_64-win32
/libtcc1.a lib
/i386
/libtcc1.a
140 NATIVE_FILES
=$(ARM_FILES
)
141 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
) $(CFLAGS
) $(LDFLAGS
) $(LINK_LIBTCC
)
174 # Cross Tiny C Compilers
176 $(CC
) -o
$@ tcc.c
-DONE_SOURCE
$(DEFINES
) $(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
) $(CFLAGS
)
215 libtcc.a
: $(LIBTCC_OBJ
)
218 libtcc.so
.1.0: $(LIBTCC_OBJ
)
219 $(CC
) -shared
-Wl
,-soname
,$@
-o
$@
$^
221 libtcc.so
.1.0: CFLAGS
+=-fPIC
224 tcc_p
$(EXESUF
): $(NATIVE_FILES
)
225 $(CC
) -o
$@
$< $(NATIVE_DEFINES
) $(CFLAGS_P
) $(LIBS_P
)
228 tiny_impdef
$(EXESUF
): win32
/tools
/tiny_impdef.c
229 $(CC
) -o
$@
$< $(CFLAGS
)
230 tiny_libmaker
$(EXESUF
): win32
/tools
/tiny_libmaker.c
231 $(CC
) -o
$@
$< $(CFLAGS
)
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
$@
$(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 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 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 -.
/texi2pod.pl
$< tcc.pod
342 -pod2man
--section
=1 --center
=" " --release
=" " tcc.pod
> $@
344 tcc-doc.
info: tcc-doc.texi
345 -makeinfo tcc-doc.texi
347 .PHONY
: all clean tar distclean install uninstall FORCE
349 # tar release (use 'make -k tar' on a checkouted tree)
350 TCC-VERSION
=tcc-
$(shell cat VERSION
)
352 rm -rf
/tmp
/$(TCC-VERSION
)
353 cp
-r .
/tmp
/$(TCC-VERSION
)
354 ( cd
/tmp
; tar zcvf ~
/$(TCC-VERSION
).
tar.gz
$(TCC-VERSION
) --exclude CVS
)
355 rm -rf
/tmp
/$(TCC-VERSION
)
365 rm -vf
$(PROGS
) tcc_p
$(EXESUF
) tcc.pod
*~
*.o
*.a
*.so
* *.out
*.exe libtcc_test
$(EXESUF
)
373 rm -vf config.h config.mak config.texi tcc
.1 tcc-doc.
info tcc-doc.html
376 @echo
"Please run ./configure."
379 endif # ifeq ($(TOP),.)