1 # --------------------------------------------------------------------------
3 # Tiny C Compiler Makefile
11 include $(TOP
)/config.mak
13 ifeq (-$(findstring gcc
,$(CC
))-,-gcc-
)
14 ifeq (-$(GCC_MAJOR
)-$(findstring $(GCC_MINOR
),56789)-,-4--)
15 CFLAGS
+= -D_FORTIFY_SOURCE
=0
18 ifeq (-$(findstring clang
,$(CC
))-,-clang-
)
19 # make clang accept gnuisms in libtcc1.c
20 CFLAGS
+=-fheinous-gnu-extensions
33 ifneq ($(DISABLE_STATIC
),no
)
34 LIBTCC
= libtcc
$(DLLSUF
)
35 LIBTCCDEF
= libtcc.def
38 NATIVE_TARGET
= $(ARCH
)-win
$(if
$(findstring arm
,$(ARCH
)),ce
,32)
44 # make libtcc as static or dynamic library?
45 ifeq ($(DISABLE_STATIC
),yes
)
46 LIBTCC
=libtcc
$(DLLSUF
)
47 export LD_LIBRARY_PATH
:= $(CURDIR
)/$(TOP
)
49 LINK_LIBTCC
+= -Wl
,-rpath
,"$(libdir)"
53 NATIVE_TARGET
= $(ARCH
)
55 NATIVE_TARGET
= $(ARCH
)-osx
56 LDFLAGS
+= -flat_namespace
-undefined warning
57 export MACOSX_DEPLOYMENT_TARGET
:= 10.2
61 # run local version of tcc with local libraries and includes
62 TCCFLAGS-unx
= -B
$(TOP
) -I
$(TOPSRC
)/include -I
$(TOPSRC
) -I
$(TOP
)
63 TCCFLAGS-win
= -B
$(TOPSRC
)/win32
-I
$(TOPSRC
)/include -I
$(TOPSRC
) -I
$(TOP
) -L
$(TOP
)
64 TCCFLAGS
= $(TCCFLAGS
$(CFGWIN
))
65 TCC
= $(TOP
)/tcc
$(EXESUF
) $(TCCFLAGS
)
67 TCCFLAGS
+= -D_ANSI_SOURCE
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_arm
) += -DTCC_TARGET_ARM
82 NATIVE_DEFINES_
$(CONFIG_arm_eabihf
) += -DTCC_ARM_EABI
-DTCC_ARM_HARDFLOAT
83 NATIVE_DEFINES_
$(CONFIG_arm_eabi
) += -DTCC_ARM_EABI
84 NATIVE_DEFINES_
$(CONFIG_arm_vfp
) += -DTCC_ARM_VFP
85 NATIVE_DEFINES_
$(CONFIG_arm64
) += -DTCC_TARGET_ARM64
86 NATIVE_DEFINES
+= $(NATIVE_DEFINES_yes
)
89 # --------------------------------------------------------------------------
90 # running top Makefile
93 TCCLIBS
= $(LIBTCC1
) $(LIBTCC
) $(LIBTCCDEF
)
94 TCCDOCS
= tcc
.1 tcc-doc.html tcc-doc.
info
96 all: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
98 # cross compiler targets to build
99 TCC_X
= i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince c67
100 # TCC_X += arm-fpa arm-fpa-ld arm-vfp arm-eabi
102 # cross libtcc1.a targets to build
103 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
),libtcc1-
$X.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: install$(CFGWIN
)
115 uninstall: uninstall$(CFGWIN
)
121 # --------------------------------------------
123 T
= $(or
$(CROSS_TARGET
),$(NATIVE_TARGET
),unknown
)
124 X
= $(if
$(CROSS_TARGET
),$(CROSS_TARGET
)-)
126 DEF-i386
= -DTCC_TARGET_I386
127 DEF-x86_64
= -DTCC_TARGET_X86_64
128 DEF-i386-win32
= -DTCC_TARGET_PE
-DTCC_TARGET_I386
129 DEF-x86_64-win32
= -DTCC_TARGET_PE
-DTCC_TARGET_X86_64
130 DEF-x86_64-osx
= -DTCC_TARGET_MACHO
-DTCC_TARGET_X86_64
131 DEF-arm-wince
= -DTCC_TARGET_PE
-DTCC_TARGET_ARM
-DTCC_ARM_EABI
-DTCC_ARM_VFP
-DTCC_ARM_HARDFLOAT
132 DEF-arm64
= -DTCC_TARGET_ARM64
133 DEF-c67
= -DTCC_TARGET_C67
-w
# disable warnigs
134 DEF-arm-fpa
= -DTCC_TARGET_ARM
135 DEF-arm-fpa-ld
= -DTCC_TARGET_ARM
-DLDOUBLE_SIZE
=12
136 DEF-arm-vfp
= -DTCC_TARGET_ARM
-DTCC_ARM_VFP
137 DEF-arm-eabi
= -DTCC_TARGET_ARM
-DTCC_ARM_VFP
-DTCC_ARM_EABI
138 DEF-arm-eabihf
= -DTCC_TARGET_ARM
-DTCC_ARM_VFP
-DTCC_ARM_EABI
-DTCC_ARM_HARDFLOAT
139 DEF-arm
= $(DEF-arm-eabihf
)
140 DEF-
$(NATIVE_TARGET
) = $(NATIVE_DEFINES
)
142 DEFINES
+= $(DEF-
$T) $(DEF-all
)
143 DEFINES
+= $(if
$(ROOT-
$T),-DCONFIG_SYSROOT
="\"$(ROOT-$T)\"")
144 DEFINES
+= $(if
$(CRT-
$T),-DCONFIG_TCC_CRTPREFIX
="\"$(CRT-$T)\"")
145 DEFINES
+= $(if
$(LIB-
$T),-DCONFIG_TCC_LIBPATHS
="\"$(LIB-$T)\"")
146 DEFINES
+= $(if
$(INC-
$T),-DCONFIG_TCC_SYSINCLUDEPATHS
="\"$(INC-$T)\"")
147 DEFINES
+= $(DEF-
$(or
$(findstring win
,$T),unx
))
150 ifeq ($(CONFIG_WIN32
),yes
)
151 DEF-win
+= -DTCC_LIBTCC1
="\"libtcc1-$T.a\""
152 DEF-unx
+= -DTCC_LIBTCC1
="\"lib/libtcc1-$T.a\""
154 DEF-all
+= -DTCC_LIBTCC1
="\"libtcc1-$T.a\""
155 DEF-win
+= -DCONFIG_TCCDIR
="\"$(tccdir)/win32\""
159 # include custom cross-compiler configuration (see make help)
160 -include config-cross.mak
162 CORE_FILES
= tcc.c tcctools.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
163 CORE_FILES
+= tcc.h config.h libtcc.h tcctok.h
164 i386_FILES
= $(CORE_FILES
) i386-gen.c i386-link.c i386-asm.c i386-asm.h i386-tok.h
165 i386-win32_FILES
= $(i386_FILES
) tccpe.c
166 x86_64_FILES
= $(CORE_FILES
) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h
167 x86_64-win32_FILES
= $(x86_64_FILES
) tccpe.c
168 x86_64-osx_FILES
= $(x86_64_FILES
)
169 arm_FILES
= $(CORE_FILES
) arm-gen.c arm-link.c arm-asm.c
170 arm-wince_FILES
= $(arm_FILES
) tccpe.c
171 arm64_FILES
= $(CORE_FILES
) arm64-gen.c arm64-link.c
172 c67_FILES
= $(CORE_FILES
) c67-gen.c c67-link.c tcccoff.c
175 LIBTCC_SRC
= $(filter-out tcc.c tcctools.c arm-asm.c
,$(filter %.c
,$($T_FILES)))
177 ifeq ($(ONE_SOURCE
),yes
)
178 LIBTCC_OBJ
= $(X
)libtcc.o
179 LIBTCC_INC
= $($T_FILES)
181 $(X
)libtcc.o
$T-tcc
$(EXESUF
) : DEFINES
+= -DONE_SOURCE
183 LIBTCC_OBJ
= $(patsubst %.c
,$(X
)%.o
,$(LIBTCC_SRC
))
184 LIBTCC_INC
= $(filter %.h
%-gen.c
%-link.c
,$($T_FILES))
185 TCC_FILES
= $(X
)tcc.o
$(LIBTCC_OBJ
)
188 # target specific object rule
189 $(X
)%.o
: %.c
$(LIBTCC_INC
)
190 $(CC
) -o
$@
-c
$< $(DEFINES
) $(CFLAGS
)
192 # additional dependencies
193 $(X
)tcc.o
: tcctools.c
194 $(X
)arm-gen.o
: arm-asm.c
196 # Host Tiny C Compiler
197 tcc
$(EXESUF
): tcc.o
$(LIBTCC
)
198 $(CC
) -o
$@
$^
$(DEFINES
) $(CFLAGS
) $(LIBS
) $(LDFLAGS
) $(LINK_LIBTCC
)
200 # Cross Tiny C Compilers
201 %-tcc
$(EXESUF
): FORCE
202 @
$(MAKE
) --no-print-directory
$@ CROSS_TARGET
=$* ONE_SOURCE
=$(or
$(ONE_SOURCE
),yes
)
204 $(CROSS_TARGET
)-tcc
$(EXESUF
): $(TCC_FILES
)
205 $(CC
) -o
$@
$^
$(DEFINES
) $(CFLAGS
) $(LIBS
) $(LDFLAGS
)
208 tcc_p
$(EXESUF
): $($T_FILES)
209 $(CC
) -o
$@
$< $(DEFINES
) -DONE_SOURCE
$(CFLAGS_P
) $(LIBS_P
) $(LDFLAGS_P
)
211 # static libtcc library
212 libtcc.a
: $(LIBTCC_OBJ
)
215 # dynamic libtcc library
216 libtcc.so
: $(LIBTCC_OBJ
)
217 $(CC
) -shared
-Wl
,-soname
,$@
-o
$@
$^
$(CFLAGS
) $(LDFLAGS
)
219 libtcc.so
: CFLAGS
+=-fPIC
221 # windows dynamic libtcc library
222 libtcc.dll
: $(LIBTCC_OBJ
)
223 $(CC
) -shared
-o
$@
$^
$(CFLAGS
) $(LDFLAGS
)
225 libtcc.def
: libtcc.dll tcc
$(EXESUF
)
226 .
/tcc
$(EXESUF
) -impdef
$< -o
$@
228 libtcc.dll
: DEFINES
+= -DLIBTCC_AS_DLL
230 # TinyCC runtime libraries
231 libtcc1.a
: tcc
$(EXESUF
) FORCE
235 libtcc1-
%.a
: %-tcc
$(EXESUF
) FORCE
236 @
$(MAKE
) -C lib CROSS_TARGET
=$*
240 # --------------------------------------------------------------------------
241 # documentation and man page
242 tcc-doc.html
: tcc-doc.texi
243 -makeinfo --no-split
--html
--number-sections
-o
$@
$<
246 -$(TOPSRC
)/texi2pod.pl
$< tcc.pod
247 -pod2man
--section
=1 --center
="Tiny C Compiler" --release
="$(VERSION)" tcc.pod
> $@
249 tcc-doc.
info: tcc-doc.texi
252 # --------------------------------------------------------------------------
255 INSTALL
= install -m644
256 INSTALLBIN
= install -m755
$(STRIP_
$(STRIP_BINARIES
))
258 install-strip
: install
259 install-strip
: STRIP_BINARIES
= yes
261 TRY-INSTALL
= $(if
$(wildcard $1),mkdir
-p
$2 && $(INSTALL
) $1 $2)
262 LIBTCC1_W
= $(wildcard $(filter %-win32.a
%-wince.a
,$(LIBTCC1_CROSS
)))
263 LIBTCC1_U
= $(wildcard $(filter-out $(LIBTCC1_W
),$(LIBTCC1_CROSS
)))
264 PROGS_X
= $(wildcard $(PROGS_CROSS
))
266 # install progs & libs
269 $(INSTALLBIN
) $(PROGS
) $(PROGS_X
) "$(bindir)"
271 $(INSTALL
) $(LIBTCC1
) $(LIBTCC1_U
) "$(tccdir)"
272 mkdir
-p
"$(tccdir)/include"
273 $(INSTALL
) $(TOPSRC
)/include/*.h
$(TOPSRC
)/tcclib.h
"$(tccdir)/include"
275 $(INSTALL
) $(LIBTCC
) "$(libdir)"
276 mkdir
-p
"$(includedir)"
277 $(INSTALL
) $(TOPSRC
)/libtcc.h
"$(includedir)"
278 $(call TRY-INSTALL
,tcc
.1,"$(mandir)/man1")
279 $(call TRY-INSTALL
,tcc-doc.
info,"$(infodir)")
280 $(call TRY-INSTALL
,tcc-doc.html
,"$(docdir)")
281 ifneq "$(LIBTCC1_W)" ""
282 mkdir
-p
"$(tccdir)/win32/lib"
283 $(INSTALL
) $(TOPSRC
)/win32
/lib
/*.def
$(LIBTCC1_W
) "$(tccdir)/win32/lib"
284 mkdir
-p
"$(tccdir)/win32/include"
285 cp
-r
$(TOPSRC
)/win32
/include/.
"$(tccdir)/win32/include"
286 $(INSTALL
) $(TOPSRC
)/include/*.h
$(TOPSRC
)/tcclib.h
"$(tccdir)/win32/include"
291 @
rm -fv
$(foreach P
,$(PROGS
) $(PROGS_CROSS
),"$(bindir)/$P")
292 @
rm -fv
"$(libdir)/libtcc.a" "$(libdir)/libtcc.so" "$(includedir)/libtcc.h"
293 @
rm -fv
"$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
294 @
rm -fv
"$(docdir)/tcc-doc.html"
297 # install progs & libs on windows
300 $(INSTALL
) $(PROGS
) $(subst libtcc.a
,,$(LIBTCC
)) $(PROGS_X
) "$(tccdir)"
301 mkdir
-p
"$(tccdir)/lib"
302 $(INSTALL
) $(TOPSRC
)/win32
/lib
/*.def
"$(tccdir)/lib"
303 $(INSTALL
) libtcc1.a
$(LIBTCC1_W
) "$(tccdir)/lib"
304 mkdir
-p
"$(tccdir)/include"
305 cp
-r
$(TOPSRC
)/win32
/include/.
"$(tccdir)/include"
306 $(INSTALL
) $(TOPSRC
)/include/*.h
$(TOPSRC
)/tcclib.h
"$(tccdir)/include"
307 mkdir
-p
"$(tccdir)/examples"
308 cp
-r
$(TOPSRC
)/win32
/examples
/.
"$(tccdir)/examples"
309 $(INSTALL
) $(TOPSRC
)/tests
/libtcc_test.c
"$(tccdir)/examples"
310 mkdir
-p
"$(tccdir)/libtcc"
311 $(INSTALL
) $(TOPSRC
)/libtcc.h
$(subst .dll
,.def
,$(LIBTCC
)) "$(tccdir)/libtcc"
312 mkdir
-p
"$(tccdir)/doc"
313 $(INSTALL
) $(TOPSRC
)/win32
/tcc-win32.txt
$(wildcard tcc-doc.html
) "$(tccdir)/doc"
314 ifneq "$(LIBTCC1_U)" ""
315 $(INSTALL
) $(LIBTCC1_U
) "$(tccdir)/lib"
316 mkdir
-p
"$(tccdir)/lib/include";
317 $(INSTALL
) $(TOPSRC
)/include/*.h
$(TOPSRC
)/tcclib.h
"$(tccdir)/lib/include"
320 # the msys-git shell works to configure && make except it does not have install
321 install-win
: INSTALL
= cp
323 # uninstall on windows
327 # --------------------------------------------------------------------------
330 TAGFILES
= *.
[ch
] include/*.h lib
/*.
[chS
]
331 tags : ; ctags
$(TAGFILES
)
332 # cannot have both tags and TAGS on windows
333 ETAGS
: ; etags
$(TAGFILES
)
335 # create release tarball from *current* git branch (including tcc-doc.html
336 # and converting two files to CRLF)
337 TCC-VERSION
= tcc-
$(VERSION
)
340 ( cd
$(TCC-VERSION
) && git
--git-dir ..
/.git checkout
-f
)
341 cp tcc-doc.html
$(TCC-VERSION
)
342 for f in tcc-win32.txt build-tcc.bat
; do \
343 cat win32
/$$f | sed
's,\(.*\),\1\r,g' > $(TCC-VERSION
)/win32
/$$f ; \
345 tar cjf
$(TCC-VERSION
).
tar.bz2
$(TCC-VERSION
)
346 rm -rf
$(TCC-VERSION
)
350 $(if
$(wildcard $@
),,@echo
"Please run ./configure." && exit
1)
357 rm -f
$(PROGS
) $(PROGS_CROSS
) tcc_p
$(EXESUF
) tcc.pod
358 rm -f
*~
*.o
*.a
*.so
* *.out
*.log lib
*.def
*.exe
*.dll a.out
tags TAGS
363 rm -f config.h config.mak config.texi tcc
.1 tcc-doc.
info tcc-doc.html
365 .PHONY
: all clean test tar tags ETAGS
distclean install uninstall FORCE
369 @echo
" build native compiler (from separate objects)"
372 @echo
" build cross compilers (from one source)"
374 @echo
"make ONE_SOURCE=yes / no"
375 @echo
" force building from one source / separate objects"
377 @echo
"make cross-TARGET"
378 @echo
" build one specific cross compiler for 'TARGET', as in"
381 @echo
"Cross compiler configuration:"
382 @echo
" make will read custom configuration for cross compilers from a file"
383 @echo
" 'config-cross.mak' if present. For example for a windows->i386-linux"
384 @echo
" cross-compiler that expects the linux files in <tccdir>/i386-linux:"
386 @echo
" ROOT-i386 = {B}/i386-linux"
387 @echo
" CRT-i386 = {B}/i386-linux/usr/lib"
388 @echo
" LIB-i386 = {B}/i386-linux/lib:{B}/i386-linux/usr/lib"
389 @echo
" INC-i386 = {B}/lib/include:{B}/i386-linux/usr/include"
390 @echo
" DEF-i386 += -D__linux__"
392 @echo
"Other supported make targets:"
393 @echo
" install install-strip test tags ETAGS tar clean distclean help"
395 # --------------------------------------------------------------------------
396 endif # ($(INCLUDED),no)