2 # Tiny C Compiler Makefile
6 include $(TOP
)/config.mak
9 CPPFLAGS
+= -I
$(TOP
) # for config.h
11 ifeq (-$(findstring gcc
,$(CC
))-,-gcc-
)
12 ifeq (-$(findstring $(GCC_MAJOR
),01)-,--)
13 CFLAGS
+=-fno-strict-aliasing
14 ifeq (-$(findstring $(GCC_MAJOR
),23)-,--)
15 CFLAGS
+=-Wno-pointer-sign
-Wno-sign-compare
16 ifeq (-$(GCC_MAJOR
)-$(findstring $(GCC_MINOR
),56789)-,-4--)
17 CFLAGS
+=-D_FORTIFY_SOURCE
=0
19 CFLAGS
+=-Wno-unused-result
24 ifeq (-$(findstring clang
,$(CC
))-,-clang-
)
25 # make clang accept gnuisms in libtcc1.c
26 CFLAGS
+=-fheinous-gnu-extensions
30 CPPFLAGS_P
=$(CPPFLAGS
) -DCONFIG_TCC_STATIC
31 CFLAGS_P
=$(CFLAGS
) -pg
-static
46 # make libtcc as static or dynamic library?
53 LIBTCC_EXTRA
=libtcc.def libtcc.a
55 LINK_LIBTCC
=-Wl
,-rpath
,"$(libdir)"
65 NATIVE_DEFINES_
$(CONFIG_i386
) += -DTCC_TARGET_I386
66 NATIVE_DEFINES_
$(CONFIG_x86-64
) += -DTCC_TARGET_X86_64
67 NATIVE_DEFINES_
$(CONFIG_WIN32
) += -DTCC_TARGET_PE
68 NATIVE_DEFINES_
$(CONFIG_uClibc
) += -DTCC_UCLIBC
69 NATIVE_DEFINES_
$(CONFIG_arm
) += -DTCC_TARGET_ARM
70 NATIVE_DEFINES_
$(CONFIG_arm_eabihf
) += -DTCC_ARM_EABI
-DTCC_ARM_HARDFLOAT
71 NATIVE_DEFINES_
$(CONFIG_arm_eabi
) += -DTCC_ARM_EABI
72 NATIVE_DEFINES_
$(CONFIG_arm_vfp
) += -DTCC_ARM_VFP
73 NATIVE_DEFINES
+= $(NATIVE_DEFINES_yes
)
78 I386_CROSS
= i386-linux-gnu-tcc
$(EXESUF
)
79 WIN32_CROSS
= i386-w64-mingw32-tcc
$(EXESUF
)
80 WIN64_CROSS
= x86_64-w64-mingw32-tcc
$(EXESUF
)
81 WINCE_CROSS
= arm-wince-mingw32ce-tcc
$(EXESUF
)
82 X64_CROSS
= x86_64-linux-gnu-tcc
$(EXESUF
)
83 ARM_FPA_CROSS
= arm-linux-fpa-tcc
$(EXESUF
)
84 ARM_FPA_LD_CROSS
= arm-linux-fpa-ld-tcc
$(EXESUF
)
85 ARM_VFP_CROSS
= arm-linux-gnu-tcc
$(EXESUF
)
86 ARM_EABI_CROSS
= arm-linux-gnueabi-tcc
$(EXESUF
)
87 ARM_EABIHF_CROSS
= arm-linux-gnueabihf-tcc
$(EXESUF
)
88 ARM_CROSS
= $(ARM_FPA_CROSS
) $(ARM_FPA_LD_CROSS
) $(ARM_VFP_CROSS
) $(ARM_EABI_CROSS
)
89 C67_CROSS
= c67-tcc
$(EXESUF
)
91 # Legacy symlinks for cross compilers
92 $(I386_CROSS
)_LINK
= i386-tcc
$(EXESUF
)
93 $(WIN32_CROSS
)_LINK
= i386-win32-tcc
$(EXESUF
)
94 $(WIN64_CROSS
)_LINK
= x86_64-win32-tcc
$(EXESUF
)
95 $(WINCE_CROSS
)_LINK
= arm-win32-tcc
$(EXESUF
)
96 $(X64_CROSS
)_LINK
= x86_64-tcc
$(EXESUF
)
97 $(ARM_FPA_CROSS
)_LINK
= arm-fpa-tcc
$(EXESUF
)
98 $(ARM_FPA_LD_CROSS
)_LINK
= arm-fpa-ld-tcc
$(EXESUF
)
99 $(ARM_VFP_CROSS
)_LINK
= arm-vfp-tcc
$(EXESUF
)
100 $(ARM_EABI_CROSS
)_LINK
= arm-eabi-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
118 else ifdef CONFIG_WIN32
119 PROGS
+=tiny_impdef
$(EXESUF
) tiny_libmaker
$(EXESUF
)
120 NATIVE_FILES
=$(WIN32_FILES
)
121 PROGS_CROSS
=$(WIN64_CROSS
) $(I386_CROSS
) $(X64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
)
122 LIBTCC1_CROSS
=lib
/x86_64-win32
/libtcc1.a
124 else ifeq ($(ARCH
),i386
)
125 NATIVE_FILES
=$(I386_FILES
)
126 PROGS_CROSS
=$(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
)
127 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a lib
/x86_64-win32
/libtcc1.a
129 else ifeq ($(ARCH
),x86-64
)
130 NATIVE_FILES
=$(X86_64_FILES
)
131 PROGS_CROSS
=$(I386_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
)
132 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a lib
/x86_64-win32
/libtcc1.a lib
/i386
/libtcc1.a
134 else ifeq ($(ARCH
),arm
)
135 NATIVE_FILES
=$(ARM_FILES
)
136 PROGS_CROSS
=$(I386_CROSS
) $(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(C67_CROSS
)
138 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a lib
/x86_64-win32
/libtcc1.a lib
/i386
/libtcc1.a
140 PROGS_CROSS_LINK
=$(foreach PROG_CROSS
,$(PROGS_CROSS
),$($(PROG_CROSS
)_LINK
))
142 ifeq ($(TARGETOS
),Darwin
)
143 PROGS
+=tiny_libmaker
$(EXESUF
)
146 TCCLIBS
= $(LIBTCC1
) $(LIBTCC
) $(LIBTCC_EXTRA
)
147 TCCDOCS
= tcc
.1 tcc-doc.html tcc-doc.
info
150 PROGS
+=$(PROGS_CROSS
)
151 TCCLIBS
+=$(LIBTCC1_CROSS
)
154 all: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
156 # Host Tiny C Compiler
157 tcc
$(EXESUF
): tcc.o
$(LIBTCC
)
158 $(CC
) -o
$@
$^
$(LIBS
) $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
) $(LINK_LIBTCC
)
160 # Cross Tiny C Compilers
161 %-tcc
$(EXESUF
): tcc.c
162 $(CC
) -o
$@
$< -DONE_SOURCE
$(DEFINES
) $(CPPFLAGS
) $(CFLAGS
) $(LIBS
) $(LDFLAGS
)
163 $(if
$($@_LINK
),ln
-sf
$@
$($@_LINK
))
166 tcc_p
$(EXESUF
): $(NATIVE_FILES
)
167 $(CC
) -o
$@
$< -DONE_SOURCE
$(NATIVE_DEFINES
) $(CPPFLAGS_P
) $(CFLAGS_P
) $(LIBS_P
) $(LDFLAGS_P
)
169 $(I386_CROSS
): DEFINES
= -DTCC_TARGET_I386 \
170 -DCONFIG_TCCDIR
="\"$(tccdir)/i386\""
171 $(X64_CROSS
): DEFINES
= -DTCC_TARGET_X86_64
172 $(WIN32_CROSS
): DEFINES
= -DTCC_TARGET_I386
-DTCC_TARGET_PE \
173 -DCONFIG_TCCDIR
="\"$(tccdir)/win32\"" \
174 -DCONFIG_TCC_LIBPATHS
="\"{B}/lib/32;{B}/lib\""
175 $(WIN64_CROSS
): DEFINES
= -DTCC_TARGET_X86_64
-DTCC_TARGET_PE \
176 -DCONFIG_TCCDIR
="\"$(tccdir)/win32\"" \
177 -DCONFIG_TCC_LIBPATHS
="\"{B}/lib/64;{B}/lib\""
178 $(WINCE_CROSS
): DEFINES
= -DTCC_TARGET_PE
179 $(C67_CROSS
): DEFINES
= -DTCC_TARGET_C67
180 $(ARM_FPA_CROSS
): DEFINES
= -DTCC_TARGET_ARM
181 $(ARM_FPA_LD_CROSS
)$(EXESUF
): DEFINES
= -DTCC_TARGET_ARM
-DLDOUBLE_SIZE
=12
182 $(ARM_VFP_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_ARM_VFP
183 $(ARM_EABI_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_ARM_EABI
-DTCC_ARM_VFP
185 $(I386_CROSS
): $(I386_FILES
)
186 $(X64_CROSS
): $(X86_64_FILES
)
187 $(WIN32_CROSS
): $(WIN32_FILES
)
188 $(WIN64_CROSS
): $(WIN64_FILES
)
189 $(WINCE_CROSS
): $(WINCE_FILES
)
190 $(C67_CROSS
): $(C67_FILES
)
191 $(ARM_FPA_CROSS
) $(ARM_FPA_LD_CROSS
) $(ARM_VFP_CROSS
) $(ARM_EABI_CROSS
): $(ARM_FILES
)
193 # libtcc generation and test
195 LIBTCC_OBJ
= $(filter-out tcc.o
,$(patsubst %.c
,%.o
,$(filter %.c
,$(NATIVE_FILES
))))
196 LIBTCC_INC
= $(filter %.h
,$(CORE_FILES
)) $(filter-out $(CORE_FILES
),$(NATIVE_FILES
))
198 LIBTCC_OBJ
= libtcc.o
199 LIBTCC_INC
= $(NATIVE_FILES
)
200 libtcc.o
: NATIVE_DEFINES
+= -DONE_SOURCE
203 $(LIBTCC_OBJ
) tcc.o
: %.o
: %.c
$(LIBTCC_INC
)
204 $(CC
) -o
$@
-c
$< $(NATIVE_DEFINES
) $(CPPFLAGS
) $(CFLAGS
)
207 libtcc.a
: $(LIBTCC_OBJ
)
211 libtcc.so
.1.0: $(LIBTCC_OBJ
)
212 $(CC
) -shared
-Wl
,-soname
,$@
-o
$@
$^
$(LDFLAGS
)
214 libtcc.so
.1.0: CFLAGS
+=-fPIC
217 libtcc.dll libtcc.def libtcc.a
: $(LIBTCC_OBJ
)
218 $(CC
) -shared
$^
-o
$@
$(LDFLAGS
) -Wl
,--output-def
,libtcc.def
,--out-implib
,libtcc.a
222 tiny_impdef
$(EXESUF
): win32
/tools
/tiny_impdef.c
223 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
224 tiny_libmaker
$(EXESUF
): win32
/tools
/tiny_libmaker.c
225 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
227 # TinyCC runtime libraries
229 $(MAKE
) -C lib native
230 lib
/%/libtcc1.a
: FORCE
$(PROGS_CROSS
)
231 $(MAKE
) -C lib cross TARGET
=$*
236 TCC_INCLUDES
= stdarg.h stddef.h stdbool.h float.h varargs.h
239 INSTALLBIN
=$(INSTALL
) -s
241 INSTALLBIN
=$(INSTALL
)
244 install-strip
: install
245 strip $(foreach PROG
,$(PROGS
),"$(bindir)"/$(PROG
))
248 install: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
251 $(INSTALL
) -m755
$(PROGS
) $(PROGS_CROSS_LINK
) "$(bindir)"
253 $(INSTALLBIN
) -m755
$(PROGS
) "$(bindir)"
255 mkdir
-p
"$(mandir)/man1"
256 -$(INSTALL
) -m644 tcc
.1 "$(mandir)/man1"
257 mkdir
-p
"$(infodir)"
258 -$(INSTALL
) -m644 tcc-doc.
info "$(infodir)"
260 mkdir
-p
"$(tccdir)/include"
262 $(INSTALL
) -m644
$(LIBTCC1
) "$(tccdir)"
264 $(INSTALL
) -m644
$(addprefix $(top_srcdir
)/include/,$(TCC_INCLUDES
)) $(top_srcdir
)/tcclib.h
"$(tccdir)/include"
266 $(INSTALL
) -m644
$(LIBTCC
) "$(libdir)"
268 ln
-sf
"$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so.1"
269 ln
-sf
"$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so"
271 mkdir
-p
"$(includedir)"
272 $(INSTALL
) -m644
$(top_srcdir
)/libtcc.h
"$(includedir)"
274 -$(INSTALL
) -m644 tcc-doc.html
"$(docdir)"
276 mkdir
-p
"$(tccdir)/win32/lib/32"
277 mkdir
-p
"$(tccdir)/win32/lib/64"
279 mkdir
-p
"$(tccdir)/i386"
280 $(INSTALL
) -m644 lib
/i386
/libtcc1.a
"$(tccdir)/i386"
281 cp
-r
"$(tccdir)/include" "$(tccdir)/i386"
283 $(INSTALL
) -m644
$(top_srcdir
)/win32
/lib
/*.def
"$(tccdir)/win32/lib"
284 $(INSTALL
) -m644 lib
/i386-win32
/libtcc1.a
"$(tccdir)/win32/lib/32"
285 $(INSTALL
) -m644 lib
/x86_64-win32
/libtcc1.a
"$(tccdir)/win32/lib/64"
286 cp
-r
$(top_srcdir
)/win32
/include/.
"$(tccdir)/win32/include"
287 cp
-r
"$(tccdir)/include" "$(tccdir)/win32"
291 rm -fv
$(foreach P
,$(PROGS
),"$(bindir)/$P")
292 rm -fv
$(foreach P
,$(LIBTCC1
),"$(tccdir)/$P")
293 rm -fv
$(foreach P
,$(TCC_INCLUDES
),"$(tccdir)/include/$P")
294 rm -fv
"$(tccdir)/include/tcclib.h"
295 rm -fv
"$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
296 rm -fv
"$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
297 rm -fv
"$(libdir)/libtcc.so*"
298 rm -rf
"$(tccdir)/win32"
299 -rmdir
$(tccdir
)/include
301 rm -rf
"$(tccdir)/i386"
305 install: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
307 mkdir
-p
"$(tccdir)/lib"
308 mkdir
-p
"$(tccdir)/include"
309 mkdir
-p
"$(tccdir)/examples"
310 mkdir
-p
"$(tccdir)/doc"
311 mkdir
-p
"$(tccdir)/libtcc"
312 $(INSTALLBIN
) -m755
$(PROGS
) "$(tccdir)"
313 $(INSTALL
) -m644
$(LIBTCC1
) $(top_srcdir
)/win32
/lib
/*.def
"$(tccdir)/lib"
314 cp
-r
$(top_srcdir
)/win32
/include/.
"$(tccdir)/include"
315 cp
-r
$(top_srcdir
)/win32
/examples
/.
"$(tccdir)/examples"
316 $(INSTALL
) -m644
$(addprefix $(top_srcdir
)/include/,$(TCC_INCLUDES
)) $(top_srcdir
)/tcclib.h
"$(tccdir)/include"
317 $(INSTALL
) -m644 tcc-doc.html
$(top_srcdir
)/win32
/tcc-win32.txt
"$(tccdir)/doc"
318 $(INSTALL
) -m644
$(top_srcdir
)/libtcc.h
$(LIBTCC_EXTRA
) "$(tccdir)/libtcc"
319 $(INSTALL
) -m644
$(LIBTCC
) $(tccdir
)
321 mkdir
-p
"$(tccdir)/lib/32"
322 mkdir
-p
"$(tccdir)/lib/64"
323 -$(INSTALL
) -m644 lib
/i386-win32
/libtcc1.a
"$(tccdir)/lib/32"
324 -$(INSTALL
) -m644 lib
/x86_64-win32
/libtcc1.a
"$(tccdir)/lib/64"
328 rm -rfv
"$(tccdir)/*"
331 # documentation and man page
332 tcc-doc.html
: tcc-doc.texi
333 -makeinfo --no-split
--html
--number-sections
-o
$@
$<
336 -$(top_srcdir
)/texi2pod.pl
$< tcc.pod
337 -pod2man
--section
=1 --center
="Tiny C Compiler" --release
=`cat $(top_srcdir)/VERSION` tcc.pod
> $@
339 tcc-doc.
info: tcc-doc.texi
346 $(MAKE
) -C tests
$@
'PROGS_CROSS=$(PROGS_CROSS)'
349 rm -vf
$(PROGS
) tcc_p
$(EXESUF
) tcc.pod
*~
*.o
*.a
*.so
* *.out
*.log \
350 *.exe a.out
tags TAGS libtcc_test
$(EXESUF
)
357 rm -vf config.h config.mak config.texi tcc
.1 tcc-doc.
info tcc-doc.html
360 @echo
"Please run ./configure."
364 ctags
$(top_srcdir
)/*.
[ch
] $(top_srcdir
)/include/*.h
$(top_srcdir
)/lib
/*.
[chS
]
367 ctags
-e
$(top_srcdir
)/*.
[ch
] $(top_srcdir
)/include/*.h
$(top_srcdir
)/lib
/*.
[chS
]
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
)
383 .PHONY
: all clean tar tags TAGS
distclean install uninstall FORCE
385 endif # ifeq ($(TOP),.)