1 # --------------------------------------------------------------------------
3 # Tiny C Compiler Makefile
11 ifeq ($(findstring $(MAKECMDGOALS
),clean distclean),)
12 include $(TOP
)/config.mak
15 ifeq (-$(GCC_MAJOR
)-$(findstring $(GCC_MINOR
),56789)-,-4--)
16 CFLAGS
+= -D_FORTIFY_SOURCE
=0
28 ifneq ($(CONFIG_static
),yes
)
29 LIBTCC
= libtcc
$(DLLSUF
)
30 LIBTCCDEF
= libtcc.def
33 NATIVE_TARGET
= $(ARCH
)-win
$(if
$(findstring arm
,$(ARCH
)),ce
,32)
36 ifneq ($(CONFIG_ldl
),no
)
39 # make libtcc as static or dynamic library?
40 ifeq ($(CONFIG_static
),no
)
41 LIBTCC
=libtcc
$(DLLSUF
)
42 export LD_LIBRARY_PATH
:= $(CURDIR
)/$(TOP
)
43 ifneq ($(CONFIG_rpath
),no
)
44 LINK_LIBTCC
+= -Wl
,-rpath
,"$(libdir)"
48 NATIVE_TARGET
= $(ARCH
)
50 NATIVE_TARGET
= $(ARCH
)-osx
51 LDFLAGS
+= -flat_namespace
-undefined warning
52 export MACOSX_DEPLOYMENT_TARGET
:= 10.6
56 # run local version of tcc with local libraries and includes
57 TCCFLAGS-unx
= -B
$(TOP
) -I
$(TOPSRC
)/include -I
$(TOPSRC
) -I
$(TOP
)
58 TCCFLAGS-win
= -B
$(TOPSRC
)/win32
-I
$(TOPSRC
)/include -I
$(TOPSRC
) -I
$(TOP
) -L
$(TOP
)
59 TCCFLAGS
= $(TCCFLAGS
$(CFGWIN
))
60 TCC
= $(TOP
)/tcc
$(EXESUF
) $(TCCFLAGS
)
62 TCCFLAGS
+= -D_ANSI_SOURCE
65 # cross compiler targets to build
66 TCC_X
= i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince c67
68 # TCC_X += arm-fpa arm-fpa-ld arm-vfp arm-eabi
70 CFLAGS_P
= $(CFLAGS
) -pg
-static
-DCONFIG_TCC_STATIC
-DTCC_PROFILE
72 LDFLAGS_P
= $(LDFLAGS
)
75 NATIVE_DEFINES_
$(CONFIG_i386
) += -DTCC_TARGET_I386
76 NATIVE_DEFINES_
$(CONFIG_x86_64
) += -DTCC_TARGET_X86_64
77 NATIVE_DEFINES_
$(CONFIG_WIN32
) += -DTCC_TARGET_PE
78 NATIVE_DEFINES_
$(CONFIG_OSX
) += -DTCC_TARGET_MACHO
79 NATIVE_DEFINES_
$(CONFIG_uClibc
) += -DTCC_UCLIBC
80 NATIVE_DEFINES_
$(CONFIG_musl
) += -DTCC_MUSL
81 NATIVE_DEFINES_
$(CONFIG_libgcc
) += -DCONFIG_USE_LIBGCC
82 NATIVE_DEFINES_
$(CONFIG_selinux
) += -DHAVE_SELINUX
83 NATIVE_DEFINES_
$(CONFIG_arm
) += -DTCC_TARGET_ARM
84 NATIVE_DEFINES_
$(CONFIG_arm_eabihf
) += -DTCC_ARM_EABI
-DTCC_ARM_HARDFLOAT
85 NATIVE_DEFINES_
$(CONFIG_arm_eabi
) += -DTCC_ARM_EABI
86 NATIVE_DEFINES_
$(CONFIG_arm_vfp
) += -DTCC_ARM_VFP
87 NATIVE_DEFINES_
$(CONFIG_arm64
) += -DTCC_TARGET_ARM64
88 NATIVE_DEFINES_
$(CONFIG_riscv64
) += -DTCC_TARGET_RISCV64
89 NATIVE_DEFINES
+= $(NATIVE_DEFINES_yes
)
92 # --------------------------------------------------------------------------
93 # running top Makefile
96 TCCLIBS
= $(LIBTCCDEF
) $(LIBTCC
) $(LIBTCC1
)
97 TCCDOCS
= tcc
.1 tcc-doc.html tcc-doc.
info
99 all: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
101 # cross libtcc1.a targets to build
102 LIBTCC1_X
= i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince
105 PROGS_CROSS
= $(foreach X
,$(TCC_X
),$X-tcc
$(EXESUF
))
106 LIBTCC1_CROSS
= $(foreach X
,$(LIBTCC1_X
),$X-libtcc
1.a
)
108 # build cross compilers & libs
109 cross
: $(LIBTCC1_CROSS
) $(PROGS_CROSS
)
111 # build specific cross compiler & lib
112 cross-
%: %-tcc
$(EXESUF
) %-libtcc1.a
;
114 install: ; @
$(MAKE
) --no-print-directory
install$(CFGWIN
)
115 install-strip
: ; @
$(MAKE
) --no-print-directory
install$(CFGWIN
) CONFIG_strip
=yes
116 uninstall: ; @
$(MAKE
) --no-print-directory
uninstall$(CFGWIN
)
122 # --------------------------------------------
124 T
= $(or
$(CROSS_TARGET
),$(NATIVE_TARGET
),unknown
)
125 X
= $(if
$(CROSS_TARGET
),$(CROSS_TARGET
)-)
127 DEF-i386
= -DTCC_TARGET_I386
128 DEF-x86_64
= -DTCC_TARGET_X86_64
129 DEF-i386-win32
= -DTCC_TARGET_PE
-DTCC_TARGET_I386
130 DEF-x86_64-win32
= -DTCC_TARGET_PE
-DTCC_TARGET_X86_64
131 DEF-x86_64-osx
= -DTCC_TARGET_MACHO
-DTCC_TARGET_X86_64
132 DEF-arm-wince
= -DTCC_TARGET_PE
-DTCC_TARGET_ARM
-DTCC_ARM_EABI
-DTCC_ARM_VFP
-DTCC_ARM_HARDFLOAT
133 DEF-arm64
= -DTCC_TARGET_ARM64
-Wno-format
134 DEF-c67
= -DTCC_TARGET_C67
-w
# disable warnigs
135 DEF-arm-fpa
= -DTCC_TARGET_ARM
136 DEF-arm-fpa-ld
= -DTCC_TARGET_ARM
-DLDOUBLE_SIZE
=12
137 DEF-arm-vfp
= -DTCC_TARGET_ARM
-DTCC_ARM_VFP
138 DEF-arm-eabi
= -DTCC_TARGET_ARM
-DTCC_ARM_VFP
-DTCC_ARM_EABI
139 DEF-arm-eabihf
= -DTCC_TARGET_ARM
-DTCC_ARM_VFP
-DTCC_ARM_EABI
-DTCC_ARM_HARDFLOAT
140 DEF-arm
= $(DEF-arm-eabihf
)
141 DEF-riscv64
= -DTCC_TARGET_RISCV64
142 DEF-
$(NATIVE_TARGET
) = $(NATIVE_DEFINES
)
144 DEFINES
+= $(DEF-
$T) $(DEF-all
)
145 DEFINES
+= $(if
$(ROOT-
$T),-DCONFIG_SYSROOT
="\"$(ROOT-$T)\"")
146 DEFINES
+= $(if
$(CRT-
$T),-DCONFIG_TCC_CRTPREFIX
="\"$(CRT-$T)\"")
147 DEFINES
+= $(if
$(LIB-
$T),-DCONFIG_TCC_LIBPATHS
="\"$(LIB-$T)\"")
148 DEFINES
+= $(if
$(INC-
$T),-DCONFIG_TCC_SYSINCLUDEPATHS
="\"$(INC-$T)\"")
149 DEFINES
+= $(DEF-
$(or
$(findstring win
,$T),unx
))
152 ifeq ($(CONFIG_WIN32
),yes
)
153 DEF-win
+= -DTCC_LIBTCC1
="\"$(X)libtcc1.a\""
154 DEF-unx
+= -DTCC_LIBTCC1
="\"lib/$(X)libtcc1.a\""
156 DEF-all
+= -DTCC_LIBTCC1
="\"$(X)libtcc1.a\""
157 DEF-win
+= -DCONFIG_TCCDIR
="\"$(tccdir)/win32\""
161 # include custom configuration (see make help)
162 -include config-extra.mak
164 CORE_FILES
= tcc.c tcctools.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
165 CORE_FILES
+= tcc.h config.h libtcc.h tcctok.h
166 i386_FILES
= $(CORE_FILES
) i386-gen.c i386-link.c i386-asm.c i386-asm.h i386-tok.h
167 i386-win32_FILES
= $(i386_FILES
) tccpe.c
168 x86_64_FILES
= $(CORE_FILES
) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h
169 x86_64-win32_FILES
= $(x86_64_FILES
) tccpe.c
170 x86_64-osx_FILES
= $(x86_64_FILES
)
171 arm_FILES
= $(CORE_FILES
) arm-gen.c arm-link.c arm-asm.c
172 arm-wince_FILES
= $(arm_FILES
) tccpe.c
173 arm-eabihf_FILES
= $(arm_FILES
)
174 arm-fpa_FILES
= $(arm_FILES
)
175 arm-fpa-ld_FILES
= $(arm_FILES
)
176 arm-vfp_FILES
= $(arm_FILES
)
177 arm-eabi_FILES
= $(arm_FILES
)
178 arm-eabihf_FILES
= $(arm_FILES
)
179 arm64_FILES
= $(CORE_FILES
) arm64-gen.c arm64-link.c arm-asm.c
180 c67_FILES
= $(CORE_FILES
) c67-gen.c c67-link.c tcccoff.c
181 riscv64_FILES
= $(CORE_FILES
) riscv64-gen.c riscv64-link.c riscv64-asm.c
184 LIBTCC_SRC
= $(filter-out tcc.c tcctools.c
,$(filter %.c
,$($T_FILES)))
186 ifeq ($(ONE_SOURCE
),yes
)
187 LIBTCC_OBJ
= $(X
)libtcc.o
188 LIBTCC_INC
= $($T_FILES)
189 TCC_FILES
= $(X
)tcc.o
190 tcc.o
: DEFINES
+= -DONE_SOURCE
=0
192 LIBTCC_OBJ
= $(patsubst %.c
,$(X
)%.o
,$(LIBTCC_SRC
))
193 LIBTCC_INC
= $(filter %.h
%-gen.c
%-link.c
,$($T_FILES))
194 TCC_FILES
= $(X
)tcc.o
$(LIBTCC_OBJ
)
195 $(TCC_FILES
) : DEFINES
+= -DONE_SOURCE
=0
198 ifeq ($(CONFIG_strip
),no
)
206 # target specific object rule
207 $(X
)%.o
: %.c
$(LIBTCC_INC
)
208 $S$(CC
) -o
$@
-c
$< $(DEFINES
) $(CFLAGS
)
210 # additional dependencies
211 $(X
)tcc.o
: tcctools.c
213 # Host Tiny C Compiler
214 tcc
$(EXESUF
): tcc.o
$(LIBTCC
)
215 $S$(CC
) -o
$@
$^
$(LIBS
) $(LDFLAGS
) $(LINK_LIBTCC
)
217 # Cross Tiny C Compilers
218 %-tcc
$(EXESUF
): FORCE
219 @
$(MAKE
) --no-print-directory
$@ CROSS_TARGET
=$* ONE_SOURCE
=$(or
$(ONE_SOURCE
),yes
)
221 $(CROSS_TARGET
)-tcc
$(EXESUF
): $(TCC_FILES
)
222 $S$(CC
) -o
$@
$^
$(LIBS
) $(LDFLAGS
)
225 tcc_p
$(EXESUF
): $($T_FILES)
226 $S$(CC
) -o
$@
$< $(DEFINES
) $(CFLAGS_P
) $(LIBS_P
) $(LDFLAGS_P
)
228 # static libtcc library
229 libtcc.a
: $(LIBTCC_OBJ
)
232 # dynamic libtcc library
233 libtcc.so
: $(LIBTCC_OBJ
)
234 $S$(CC
) -shared
-Wl
,-soname
,$@
-o
$@
$^
$(LDFLAGS
)
236 libtcc.so
: CFLAGS
+=-fPIC
237 libtcc.so
: LDFLAGS
+=-fPIC
239 # OSX dynamic libtcc library
240 libtcc.dylib
: $(LIBTCC_OBJ
)
241 $S$(CC
) -shared
-o
$@
$^
$(LDFLAGS
)
243 # windows dynamic libtcc library
244 libtcc.dll
: $(LIBTCC_OBJ
)
245 $S$(CC
) -shared
-o
$@
$^
$(LDFLAGS
)
246 libtcc.dll
: DEFINES
+= -DLIBTCC_AS_DLL
248 # import file for windows libtcc.dll
249 libtcc.def
: libtcc.dll tcc
$(EXESUF
)
250 $S$(XTCC
) -impdef
$< -o
$@
251 XTCC ?
= .
/tcc
$(EXESUF
)
253 # TinyCC runtime libraries
254 libtcc1.a
: tcc
$(EXESUF
) FORCE
258 %-libtcc1.a
: %-tcc
$(EXESUF
) FORCE
259 @
$(MAKE
) -C lib CROSS_TARGET
=$*
261 .PRECIOUS
: %-libtcc1.a
264 run-if
= $(if
$(shell which
$1),$S $1 $2)
265 S
= $(if
$(findstring yes
,$(SILENT
)),@
$(info * $@
))
267 # --------------------------------------------------------------------------
268 # documentation and man page
269 tcc-doc.html
: tcc-doc.texi
270 $(call run-if
,makeinfo,--no-split
--html
--number-sections
-o
$@
$<)
272 tcc-doc.
info: tcc-doc.texi
273 $(call run-if
,makeinfo,$< || true
)
276 $(call run-if
,pod2man
,--section
=1 --center
="Tiny C Compiler" \
277 --release
="$(VERSION)" $< >$@
&& rm -f
$<)
279 $(call run-if
,perl
,$(TOPSRC
)/texi2pod.pl
$< $@
)
281 # --------------------------------------------------------------------------
284 INSTALL
= install -m644
285 INSTALLBIN
= install -m755
$(STRIP_
$(CONFIG_strip
))
288 LIBTCC1_W
= $(filter %-win32-libtcc1.a
%-wince-libtcc1.a
,$(LIBTCC1_CROSS
))
289 LIBTCC1_U
= $(filter-out $(LIBTCC1_W
),$(LIBTCC1_CROSS
))
290 IB
= $(if
$1,$(IM
) mkdir
-p
$2 && $(INSTALLBIN
) $1 $2)
291 IBw
= $(call IB
,$(wildcard $1),$2)
292 IF
= $(if
$1,$(IM
) mkdir
-p
$2 && $(INSTALL
) $1 $2)
293 IFw
= $(call IF
,$(wildcard $1),$2)
294 IR
= $(IM
) mkdir
-p
$2 && cp
-r
$1/.
$2
295 IM
= $(info -> $2 : $1)@
297 B_O
= bcheck.o bt-exe.o bt-log.o bt-dll.o
299 # install progs & libs
301 $(call IBw
,$(PROGS
) $(PROGS_CROSS
),"$(bindir)")
302 $(call IFw
,$(LIBTCC1
) $(B_O
) $(LIBTCC1_U
),"$(tccdir)")
303 $(call IF
,$(TOPSRC
)/include/*.h
$(TOPSRC
)/tcclib.h
,"$(tccdir)/include")
304 $(call
$(if
$(findstring .so
,$(LIBTCC
)),IBw
,IFw
),$(LIBTCC
),"$(libdir)")
305 $(call IF
,$(TOPSRC
)/libtcc.h
,"$(includedir)")
306 $(call IFw
,tcc
.1,"$(mandir)/man1")
307 $(call IFw
,tcc-doc.
info,"$(infodir)")
308 $(call IFw
,tcc-doc.html
,"$(docdir)")
309 ifneq "$(wildcard $(LIBTCC1_W))" ""
310 $(call IFw
,$(TOPSRC
)/win32
/lib
/*.def
$(LIBTCC1_W
),"$(tccdir)/win32/lib")
311 $(call IR
,$(TOPSRC
)/win32
/include,"$(tccdir)/win32/include")
312 $(call IF
,$(TOPSRC
)/include/*.h
$(TOPSRC
)/tcclib.h
,"$(tccdir)/win32/include")
317 @
rm -fv
$(foreach P
,$(PROGS
) $(PROGS_CROSS
),"$(bindir)/$P")
318 @
rm -fv
"$(libdir)/libtcc.a" "$(libdir)/libtcc.so" "$(includedir)/libtcc.h"
319 @
rm -fv
"$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
320 @
rm -fv
"$(docdir)/tcc-doc.html"
323 # install progs & libs on windows
325 $(call IBw
,$(PROGS
) $(PROGS_CROSS
) $(subst libtcc.a
,,$(LIBTCC
)),"$(bindir)")
326 $(call IF
,$(TOPSRC
)/win32
/lib
/*.def
,"$(tccdir)/lib")
327 $(call IFw
,libtcc1.a
$(B_O
) $(LIBTCC1_W
),"$(tccdir)/lib")
328 $(call IF
,$(TOPSRC
)/include/*.h
$(TOPSRC
)/tcclib.h
,"$(tccdir)/include")
329 $(call IR
,$(TOPSRC
)/win32
/include,"$(tccdir)/include")
330 $(call IR
,$(TOPSRC
)/win32
/examples
,"$(tccdir)/examples")
331 $(call IF
,$(TOPSRC
)/tests
/libtcc_test.c
,"$(tccdir)/examples")
332 $(call IFw
,$(TOPSRC
)/libtcc.h
$(subst .dll
,.def
,$(LIBTCC
)),"$(libdir)")
333 $(call IFw
,$(TOPSRC
)/win32
/tcc-win32.txt tcc-doc.html
,"$(docdir)")
334 ifneq "$(wildcard $(LIBTCC1_U))" ""
335 $(call IFw
,$(LIBTCC1_U
),"$(tccdir)/lib")
336 $(call IF
,$(TOPSRC
)/include/*.h
$(TOPSRC
)/tcclib.h
,"$(tccdir)/lib/include")
339 # the msys-git shell works to configure && make except it does not have install
340 ifeq ($(CONFIG_WIN32
)-$(shell which
install || echo no
),yes-no
)
341 install-win
: INSTALL
= cp
342 install-win
: INSTALLBIN
= cp
345 # uninstall on windows
347 @
rm -fv
$(foreach P
,libtcc.dll
$(PROGS
) *-tcc.exe
,"$(bindir)"/$P)
348 @
rm -fr
$(foreach P
,doc examples
include lib libtcc
,"$(tccdir)/$P"/*)
349 @
rm -frv
$(foreach P
,doc examples
include lib libtcc
,"$(tccdir)/$P")
351 # --------------------------------------------------------------------------
354 TAGFILES
= *.
[ch
] include/*.h lib
/*.
[chS
]
355 tags : ; ctags
$(TAGFILES
)
356 # cannot have both tags and TAGS on windows
357 ETAGS
: ; etags
$(TAGFILES
)
359 # create release tarball from *current* git branch (including tcc-doc.html
360 # and converting two files to CRLF)
361 TCC-VERSION
= tcc-
$(VERSION
)
362 TCC-VERSION
= tinycc-mob-
$(shell git rev-parse
--short
=7 HEAD
)
364 mkdir
-p
$(TCC-VERSION
)
365 ( cd
$(TCC-VERSION
) && git
--git-dir ..
/.git checkout
-f
)
366 cp tcc-doc.html
$(TCC-VERSION
)
367 for f in tcc-win32.txt build-tcc.bat
; do \
368 cat win32
/$$f | sed
's,\(.*\),\1\r,g' > $(TCC-VERSION
)/win32
/$$f ; \
370 tar cjf
$(TCC-VERSION
).
tar.bz2
$(TCC-VERSION
)
371 rm -rf
$(TCC-VERSION
)
375 $(if
$(wildcard $@
),,@echo
"Please run ./configure." && exit
1)
380 # run test(s) from tests2 subdir (see make help)
382 @
$(MAKE
) -C tests
/tests2
$@
385 @
$(MAKE
) -C tests
/pp
$@
388 @
rm -f tcc
$(EXESUF
) tcc_p
$(EXESUF
) *-tcc
$(EXESUF
) tcc.pod
389 @
rm -f
*.o
*.a
*.so
* *.out
*.log lib
*.def
*.exe
*.dll a.out
tags TAGS
*.dylib
390 @
$(MAKE
) -s
-C lib
$@
391 @
$(MAKE
) -s
-C tests
$@
394 @
rm -fv config.h config.mak config.texi tcc
.1 tcc-doc.
info tcc-doc.html
396 .PHONY
: all clean test tar tags ETAGS
distclean install uninstall FORCE
400 @echo
" build native compiler (from separate objects)"
403 @echo
" build cross compilers (from one source)"
405 @echo
"make ONE_SOURCE=no/yes SILENT=no/yes"
406 @echo
" force building from separate/one object(s), less/more silently"
408 @echo
"make cross-TARGET"
409 @echo
" build one specific cross compiler for 'TARGET'. Currently supported:"
410 @echo
" $(wordlist 1,6,$(TCC_X))"
411 @echo
" $(wordlist 7,99,$(TCC_X))"
414 @echo
" run all tests"
416 @echo
"make tests2.all / make tests2.37 / make tests2.37+"
417 @echo
" run all/single test(s) from tests2, optionally update .expect"
419 @echo
"make testspp.all / make testspp.17"
420 @echo
" run all/single test(s) from tests/pp"
422 @echo
"Other supported make targets:"
423 @echo
" install install-strip doc clean tags ETAGS tar distclean help"
425 @echo
"Custom configuration:"
426 @echo
" The makefile includes a file 'config-extra.mak' if it is present."
427 @echo
" This file may contain some custom configuration. For example:"
428 @echo
" NATIVE_DEFINES += -D..."
429 @echo
" Or for example to configure the search paths for a cross-compiler"
430 @echo
" that expects the linux files in <tccdir>/i386-linux:"
431 @echo
" ROOT-i386 = {B}/i386-linux"
432 @echo
" CRT-i386 = {B}/i386-linux/usr/lib"
433 @echo
" LIB-i386 = {B}/i386-linux/lib:{B}/i386-linux/usr/lib"
434 @echo
" INC-i386 = {B}/lib/include:{B}/i386-linux/usr/include"
435 @echo
" DEF-i386 += -D__linux__"
437 # --------------------------------------------------------------------------
438 endif # ($(INCLUDED),no)