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_
$(CONFIG_arm64
) += -DTCC_TARGET_ARM64
74 NATIVE_DEFINES
+= $(NATIVE_DEFINES_yes
)
79 I386_CROSS
= i386-linux-gnu-tcc
$(EXESUF
)
80 WIN32_CROSS
= i386-w64-mingw32-tcc
$(EXESUF
)
81 WIN64_CROSS
= x86_64-w64-mingw32-tcc
$(EXESUF
)
82 WINCE_CROSS
= arm-wince-mingw32ce-tcc
$(EXESUF
)
83 X64_CROSS
= x86_64-linux-gnu-tcc
$(EXESUF
)
84 ARM_FPA_CROSS
= arm-linux-fpa-tcc
$(EXESUF
)
85 ARM_FPA_LD_CROSS
= arm-linux-fpa-ld-tcc
$(EXESUF
)
86 ARM_VFP_CROSS
= arm-linux-gnu-tcc
$(EXESUF
)
87 ARM_EABI_CROSS
= arm-linux-gnueabi-tcc
$(EXESUF
)
88 ARM_EABIHF_CROSS
= arm-linux-gnueabihf-tcc
$(EXESUF
)
89 ARM_CROSS
= $(ARM_FPA_CROSS
) $(ARM_FPA_LD_CROSS
) $(ARM_VFP_CROSS
) $(ARM_EABI_CROSS
)
90 ARM64_CROSS
= arm64-tcc
$(EXESUF
)
91 C67_CROSS
= c67-tcc
$(EXESUF
)
93 # Legacy symlinks for cross compilers
94 $(I386_CROSS
)_LINK
= i386-tcc
$(EXESUF
)
95 $(WIN32_CROSS
)_LINK
= i386-win32-tcc
$(EXESUF
)
96 $(WIN64_CROSS
)_LINK
= x86_64-win32-tcc
$(EXESUF
)
97 $(WINCE_CROSS
)_LINK
= arm-win32-tcc
$(EXESUF
)
98 $(X64_CROSS
)_LINK
= x86_64-tcc
$(EXESUF
)
99 $(ARM_FPA_CROSS
)_LINK
= arm-fpa-tcc
$(EXESUF
)
100 $(ARM_FPA_LD_CROSS
)_LINK
= arm-fpa-ld-tcc
$(EXESUF
)
101 $(ARM_VFP_CROSS
)_LINK
= arm-vfp-tcc
$(EXESUF
)
102 $(ARM_EABI_CROSS
)_LINK
= arm-eabi-tcc
$(EXESUF
)
104 CORE_FILES
= tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
105 CORE_FILES
+= tcc.h config.h libtcc.h tcctok.h
106 I386_FILES
= $(CORE_FILES
) i386-gen.c i386-asm.c i386-asm.h i386-tok.h
107 WIN32_FILES
= $(CORE_FILES
) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
108 WIN64_FILES
= $(CORE_FILES
) x86_64-gen.c i386-asm.c x86_64-asm.h tccpe.c
109 WINCE_FILES
= $(CORE_FILES
) arm-gen.c tccpe.c
110 X86_64_FILES
= $(CORE_FILES
) x86_64-gen.c i386-asm.c x86_64-asm.h
111 ARM_FILES
= $(CORE_FILES
) arm-gen.c
112 ARM64_FILES
= $(CORE_FILES
) arm64-gen.c
113 C67_FILES
= $(CORE_FILES
) c67-gen.c tcccoff.c
116 PROGS
+=tiny_impdef
$(EXESUF
) tiny_libmaker
$(EXESUF
)
117 NATIVE_FILES
=$(WIN64_FILES
)
118 PROGS_CROSS
=$(WIN32_CROSS
) $(I386_CROSS
) $(X64_CROSS
) $(ARM_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
119 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a
121 else ifdef CONFIG_WIN32
122 PROGS
+=tiny_impdef
$(EXESUF
) tiny_libmaker
$(EXESUF
)
123 NATIVE_FILES
=$(WIN32_FILES
)
124 PROGS_CROSS
=$(WIN64_CROSS
) $(I386_CROSS
) $(X64_CROSS
) $(ARM_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
125 LIBTCC1_CROSS
=lib
/x86_64-win32
/libtcc1.a
127 else ifeq ($(ARCH
),i386
)
128 NATIVE_FILES
=$(I386_FILES
)
129 PROGS_CROSS
=$(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
130 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a lib
/x86_64-win32
/libtcc1.a
132 else ifeq ($(ARCH
),x86-64
)
133 NATIVE_FILES
=$(X86_64_FILES
)
134 PROGS_CROSS
=$(I386_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
135 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a lib
/x86_64-win32
/libtcc1.a lib
/i386
/libtcc1.a
137 else ifeq ($(ARCH
),arm
)
138 NATIVE_FILES
=$(ARM_FILES
)
139 PROGS_CROSS
=$(I386_CROSS
) $(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
141 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a lib
/x86_64-win32
/libtcc1.a lib
/i386
/libtcc1.a
142 else ifeq ($(ARCH
),arm64
)
143 NATIVE_FILES
=$(ARM64_FILES
)
144 PROGS_CROSS
=$(I386_CROSS
) $(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
146 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a lib
/x86_64-win32
/libtcc1.a lib
/i386
/libtcc1.a
148 PROGS_CROSS_LINK
=$(foreach PROG_CROSS
,$(PROGS_CROSS
),$($(PROG_CROSS
)_LINK
))
150 ifeq ($(TARGETOS
),Darwin
)
151 PROGS
+=tiny_libmaker
$(EXESUF
)
154 TCCLIBS
= $(LIBTCC1
) $(LIBTCC
) $(LIBTCC_EXTRA
)
155 TCCDOCS
= tcc
.1 tcc-doc.html tcc-doc.
info
158 PROGS
+=$(PROGS_CROSS
)
159 TCCLIBS
+=$(LIBTCC1_CROSS
)
162 all: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
164 # Host Tiny C Compiler
165 tcc
$(EXESUF
): tcc.o
$(LIBTCC
)
166 $(CC
) -o
$@
$^
$(LIBS
) $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
) $(LINK_LIBTCC
)
168 # Cross Tiny C Compilers
169 %-tcc
$(EXESUF
): tcc.c
170 $(CC
) -o
$@
$< -DONE_SOURCE
$(DEFINES
) $(CPPFLAGS
) $(CFLAGS
) $(LIBS
) $(LDFLAGS
)
171 $(if
$($@_LINK
),ln
-sf
$@
$($@_LINK
))
174 tcc_p
$(EXESUF
): $(NATIVE_FILES
)
175 $(CC
) -o
$@
$< -DONE_SOURCE
$(NATIVE_DEFINES
) $(CPPFLAGS_P
) $(CFLAGS_P
) $(LIBS_P
) $(LDFLAGS_P
)
177 $(I386_CROSS
): DEFINES
= -DTCC_TARGET_I386 \
178 -DCONFIG_TCCDIR
="\"$(tccdir)/i386\"" -DCONFIG_MULTIARCHDIR
="\"i386-linux-gnu\""
179 $(X64_CROSS
): DEFINES
= -DTCC_TARGET_X86_64
-DCONFIG_MULTIARCHDIR
="\"x86_64-linux-gnu\""
180 $(WIN32_CROSS
): DEFINES
= -DTCC_TARGET_I386
-DTCC_TARGET_PE \
181 -DCONFIG_TCCDIR
="\"$(tccdir)/win32\"" \
182 -DCONFIG_TCC_LIBPATHS
="\"{B}/lib/32;{B}/lib\""
183 $(WIN64_CROSS
): DEFINES
= -DTCC_TARGET_X86_64
-DTCC_TARGET_PE \
184 -DCONFIG_TCCDIR
="\"$(tccdir)/win32\"" \
185 -DCONFIG_TCC_LIBPATHS
="\"{B}/lib/64;{B}/lib\""
186 $(WINCE_CROSS
): DEFINES
= -DTCC_TARGET_PE
187 $(C67_CROSS
): DEFINES
= -DTCC_TARGET_C67
188 $(ARM_FPA_CROSS
): DEFINES
= -DTCC_TARGET_ARM
189 $(ARM_FPA_LD_CROSS
)$(EXESUF
): DEFINES
= -DTCC_TARGET_ARM
-DLDOUBLE_SIZE
=12
190 $(ARM_VFP_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_ARM_VFP
-DCONFIG_MULTIARCHDIR
="\"arm-linux-gnu\""
191 $(ARM_EABI_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_ARM_EABI
-DTCC_ARM_VFP
-DCONFIG_MULTIARCHDIR
="\"arm-linux-gnueabi\""
192 $(ARM64_CROSS
): DEFINES
= -DTCC_TARGET_ARM64
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
)
201 $(ARM64_CROSS
): $(ARM64_FILES
)
203 # libtcc generation and test
205 LIBTCC_OBJ
= $(filter-out tcc.o
,$(patsubst %.c
,%.o
,$(filter %.c
,$(NATIVE_FILES
))))
206 LIBTCC_INC
= $(filter %.h
,$(CORE_FILES
)) $(filter-out $(CORE_FILES
),$(NATIVE_FILES
))
208 LIBTCC_OBJ
= libtcc.o
209 LIBTCC_INC
= $(NATIVE_FILES
)
210 libtcc.o
: NATIVE_DEFINES
+= -DONE_SOURCE
213 $(LIBTCC_OBJ
) tcc.o
: %.o
: %.c
$(LIBTCC_INC
)
214 $(CC
) -o
$@
-c
$< $(NATIVE_DEFINES
) $(CPPFLAGS
) $(CFLAGS
)
217 libtcc.a
: $(LIBTCC_OBJ
)
221 libtcc.so
.1.0: $(LIBTCC_OBJ
)
222 $(CC
) -shared
-Wl
,-soname
,$@
-o
$@
$^
$(LDFLAGS
)
224 libtcc.so
.1.0: CFLAGS
+=-fPIC
227 libtcc.dll libtcc.def libtcc.a
: $(LIBTCC_OBJ
)
228 $(CC
) -shared
$^
-o
$@
$(LDFLAGS
) -Wl
,--output-def
,libtcc.def
,--out-implib
,libtcc.a
232 tiny_impdef
$(EXESUF
): win32
/tools
/tiny_impdef.c
233 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
234 tiny_libmaker
$(EXESUF
): win32
/tools
/tiny_libmaker.c
235 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
237 # TinyCC runtime libraries
239 $(MAKE
) -C lib native
240 lib
/%/libtcc1.a
: FORCE
$(PROGS_CROSS
)
241 $(MAKE
) -C lib cross TARGET
=$*
246 TCC_INCLUDES
= stdarg.h stddef.h stdbool.h float.h varargs.h
249 INSTALLBIN
=$(INSTALL
) -s
251 INSTALLBIN
=$(INSTALL
)
254 install-strip
: install
255 strip $(foreach PROG
,$(PROGS
),"$(bindir)"/$(PROG
))
258 install: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
261 $(INSTALL
) -m755
$(PROGS
) $(PROGS_CROSS_LINK
) "$(bindir)"
263 $(INSTALLBIN
) -m755
$(PROGS
) "$(bindir)"
265 mkdir
-p
"$(mandir)/man1"
266 -$(INSTALL
) -m644 tcc
.1 "$(mandir)/man1"
267 mkdir
-p
"$(infodir)"
268 -$(INSTALL
) -m644 tcc-doc.
info "$(infodir)"
270 mkdir
-p
"$(tccdir)/include"
272 $(INSTALL
) -m644
$(LIBTCC1
) "$(tccdir)"
274 $(INSTALL
) -m644
$(addprefix $(top_srcdir
)/include/,$(TCC_INCLUDES
)) $(top_srcdir
)/tcclib.h
"$(tccdir)/include"
276 $(INSTALL
) -m644
$(LIBTCC
) "$(libdir)"
278 ln
-sf
"$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so.1"
279 ln
-sf
"$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so"
281 mkdir
-p
"$(includedir)"
282 $(INSTALL
) -m644
$(top_srcdir
)/libtcc.h
"$(includedir)"
284 -$(INSTALL
) -m644 tcc-doc.html
"$(docdir)"
286 mkdir
-p
"$(tccdir)/win32/lib/32"
287 mkdir
-p
"$(tccdir)/win32/lib/64"
289 mkdir
-p
"$(tccdir)/i386"
290 $(INSTALL
) -m644 lib
/i386
/libtcc1.a
"$(tccdir)/i386"
291 cp
-r
"$(tccdir)/include" "$(tccdir)/i386"
293 $(INSTALL
) -m644
$(top_srcdir
)/win32
/lib
/*.def
"$(tccdir)/win32/lib"
294 $(INSTALL
) -m644 lib
/i386-win32
/libtcc1.a
"$(tccdir)/win32/lib/32"
295 $(INSTALL
) -m644 lib
/x86_64-win32
/libtcc1.a
"$(tccdir)/win32/lib/64"
296 cp
-r
$(top_srcdir
)/win32
/include/.
"$(tccdir)/win32/include"
297 cp
-r
"$(tccdir)/include" "$(tccdir)/win32"
301 rm -fv
$(foreach P
,$(PROGS
),"$(bindir)/$P")
302 rm -fv
$(foreach P
,$(LIBTCC1
),"$(tccdir)/$P")
303 rm -fv
$(foreach P
,$(TCC_INCLUDES
),"$(tccdir)/include/$P")
304 rm -fv
"$(tccdir)/include/tcclib.h"
305 rm -fv
"$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
306 rm -fv
"$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
307 rm -fv
"$(libdir)/libtcc.so*"
308 rm -rf
"$(tccdir)/win32"
309 -rmdir
$(tccdir
)/include
311 rm -rf
"$(tccdir)/i386"
315 install: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
317 mkdir
-p
"$(tccdir)/lib"
318 mkdir
-p
"$(tccdir)/include"
319 mkdir
-p
"$(tccdir)/examples"
320 mkdir
-p
"$(tccdir)/doc"
321 mkdir
-p
"$(tccdir)/libtcc"
322 $(INSTALLBIN
) -m755
$(PROGS
) "$(tccdir)"
323 $(INSTALL
) -m644
$(LIBTCC1
) $(top_srcdir
)/win32
/lib
/*.def
"$(tccdir)/lib"
324 cp
-r
$(top_srcdir
)/win32
/include/.
"$(tccdir)/include"
325 cp
-r
$(top_srcdir
)/win32
/examples
/.
"$(tccdir)/examples"
326 $(INSTALL
) -m644
$(addprefix $(top_srcdir
)/include/,$(TCC_INCLUDES
)) $(top_srcdir
)/tcclib.h
"$(tccdir)/include"
327 $(INSTALL
) -m644 tcc-doc.html
$(top_srcdir
)/win32
/tcc-win32.txt
"$(tccdir)/doc"
328 $(INSTALL
) -m644
$(top_srcdir
)/libtcc.h
$(LIBTCC_EXTRA
) "$(tccdir)/libtcc"
329 $(INSTALL
) -m644
$(LIBTCC
) $(tccdir
)
331 mkdir
-p
"$(tccdir)/lib/32"
332 mkdir
-p
"$(tccdir)/lib/64"
333 -$(INSTALL
) -m644 lib
/i386-win32
/libtcc1.a
"$(tccdir)/lib/32"
334 -$(INSTALL
) -m644 lib
/x86_64-win32
/libtcc1.a
"$(tccdir)/lib/64"
338 rm -rfv
"$(tccdir)/*"
341 # documentation and man page
342 tcc-doc.html
: tcc-doc.texi
343 -makeinfo --no-split
--html
--number-sections
-o
$@
$<
346 -$(top_srcdir
)/texi2pod.pl
$< tcc.pod
347 -pod2man
--section
=1 --center
="Tiny C Compiler" --release
=`cat $(top_srcdir)/VERSION` tcc.pod
> $@
349 tcc-doc.
info: tcc-doc.texi
356 $(MAKE
) -C tests
$@
'PROGS_CROSS=$(PROGS_CROSS)'
359 rm -vf
$(PROGS
) tcc_p
$(EXESUF
) tcc.pod
*~
*.o
*.a
*.so
* *.out
*.log \
360 *.exe a.out
tags TAGS libtcc_test
$(EXESUF
)
367 rm -vf config.h config.mak config.texi tcc
.1 tcc-doc.
info tcc-doc.html
370 @echo
"Please run ./configure."
374 ctags
$(top_srcdir
)/*.
[ch
] $(top_srcdir
)/include/*.h
$(top_srcdir
)/lib
/*.
[chS
]
377 ctags
-e
$(top_srcdir
)/*.
[ch
] $(top_srcdir
)/include/*.h
$(top_srcdir
)/lib
/*.
[chS
]
379 # create release tarball from *current* git branch (including tcc-doc.html
380 # and converting two files to CRLF)
381 TCC-VERSION
:= tcc-
$(shell cat
$(top_srcdir
)/VERSION
)
384 ( cd
$(TCC-VERSION
) && git
--git-dir ..
/.git checkout
-f
)
385 cp tcc-doc.html
$(TCC-VERSION
)
386 for f in tcc-win32.txt build-tcc.bat
; do \
387 cat win32
/$$f | sed
's,\(.*\),\1\r,g' > $(TCC-VERSION
)/win32
/$$f ; \
389 tar cjf
$(TCC-VERSION
).
tar.bz2
$(TCC-VERSION
)
390 rm -rf
$(TCC-VERSION
)
393 .PHONY
: all clean tar tags TAGS
distclean install uninstall FORCE
395 endif # ifeq ($(TOP),.)