2 # Tiny C Compiler Makefile
6 include $(TOP
)/config.mak
9 CPPFLAGS
+= -I
$(TOP
) # for config.h
11 ifneq (-$(findstring gcc
,$(CC
))-,-gcc-
)
12 ifeq (-$(findstring clang
,$(CC
))-,-clang-
)
13 # make clang accept gnuisms in libtcc1.c
14 CFLAGS
+=-fheinous-gnu-extensions
18 CPPFLAGS_P
=$(CPPFLAGS
) -DCONFIG_TCC_STATIC
19 CFLAGS_P
=$(CFLAGS
) -pg
-static
34 # make libtcc as static or dynamic library?
41 LIBTCC_EXTRA
=libtcc.def libtcc.a
43 LINK_LIBTCC
=-Wl
,-rpath
,"$(libdir)"
53 NATIVE_DEFINES_
$(CONFIG_i386
) += -DTCC_TARGET_I386
54 NATIVE_DEFINES_
$(CONFIG_x86-64
) += -DTCC_TARGET_X86_64
55 NATIVE_DEFINES_
$(CONFIG_WIN32
) += -DTCC_TARGET_PE
56 NATIVE_DEFINES_
$(CONFIG_uClibc
) += -DTCC_UCLIBC
57 NATIVE_DEFINES_
$(CONFIG_arm
) += -DTCC_TARGET_ARM
58 NATIVE_DEFINES_
$(CONFIG_arm_eabihf
) += -DTCC_ARM_EABI
-DTCC_ARM_HARDFLOAT
59 NATIVE_DEFINES_
$(CONFIG_arm_eabi
) += -DTCC_ARM_EABI
60 NATIVE_DEFINES_
$(CONFIG_arm_vfp
) += -DTCC_ARM_VFP
61 NATIVE_DEFINES_
$(CONFIG_arm64
) += -DTCC_TARGET_ARM64
62 NATIVE_DEFINES
+= $(NATIVE_DEFINES_yes
)
67 I386_CROSS
= i386-linux-gnu-tcc
$(EXESUF
)
68 WIN32_CROSS
= i386-win-mingw32-tcc
$(EXESUF
)
69 WIN64_CROSS
= x86_64-win-mingw32-tcc
$(EXESUF
)
70 WINCE_CROSS
= arm-win-mingw32ce-tcc
$(EXESUF
)
71 X64_CROSS
= x86_64-linux-gnu-tcc
$(EXESUF
)
72 ARM_FPA_CROSS
= arm-linux-fpa-tcc
$(EXESUF
)
73 ARM_FPA_LD_CROSS
= arm-linux-fpa-ld-tcc
$(EXESUF
)
74 ARM_VFP_CROSS
= arm-linux-gnu-tcc
$(EXESUF
)
75 ARM_EABI_CROSS
= arm-linux-gnueabi-tcc
$(EXESUF
)
76 ARM_EABIHF_CROSS
= arm-linux-gnueabihf-tcc
$(EXESUF
)
77 ARM_CROSS
= $(ARM_FPA_CROSS
) $(ARM_FPA_LD_CROSS
) $(ARM_VFP_CROSS
) $(ARM_EABI_CROSS
)
78 ARM64_CROSS
= arm64-tcc
$(EXESUF
)
79 C67_CROSS
= c67-tcc
$(EXESUF
)
81 # Legacy symlinks for cross compilers
82 $(I386_CROSS
)_LINK
= i386-tcc
$(EXESUF
)
83 $(WIN32_CROSS
)_LINK
= i386-win-tcc
$(EXESUF
)
84 $(WIN64_CROSS
)_LINK
= x86_64-win-tcc
$(EXESUF
)
85 $(WINCE_CROSS
)_LINK
= arm-win-tcc
$(EXESUF
)
86 $(X64_CROSS
)_LINK
= x86_64-tcc
$(EXESUF
)
87 $(ARM_FPA_CROSS
)_LINK
= arm-fpa-tcc
$(EXESUF
)
88 $(ARM_FPA_LD_CROSS
)_LINK
= arm-fpa-ld-tcc
$(EXESUF
)
89 $(ARM_VFP_CROSS
)_LINK
= arm-vfp-tcc
$(EXESUF
)
90 $(ARM_EABI_CROSS
)_LINK
= arm-eabi-tcc
$(EXESUF
)
92 ifeq ($(TARGETOS
),Windows
)
94 PROGS
:=$($(WIN32_CROSS
)_LINK
)
95 $($(WIN32_CROSS
)_LINK
)_TCC
= yes
98 PROGS
:=$($(WIN64_CROSS
)_LINK
)
99 $($(WIN64_CROSS
)_LINK
)_TCC
= yes
103 ifeq ($(TARGETOS
),Linux
)
105 PROGS
:=$($(I386_CROSS
)_LINK
)
106 $($(I386_CROSS
)_LINK
)_TCC
= yes
108 ifeq ($(ARCH
),x86-64
)
109 PROGS
:=$($(X64_CROSS
)_LINK
)
110 $($(X64_CROSS
)_LINK
)_TCC
= yes
114 CORE_FILES
= tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
115 CORE_FILES
+= tcc.h config.h libtcc.h tcctok.h
116 I386_FILES
= $(CORE_FILES
) i386-gen.c i386-asm.c i386-asm.h i386-tok.h
117 WIN32_FILES
= $(CORE_FILES
) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
118 WIN64_FILES
= $(CORE_FILES
) x86_64-gen.c i386-asm.c x86_64-asm.h tccpe.c
119 WINCE_FILES
= $(CORE_FILES
) arm-gen.c tccpe.c
120 X86_64_FILES
= $(CORE_FILES
) x86_64-gen.c i386-asm.c x86_64-asm.h
121 ARM_FILES
= $(CORE_FILES
) arm-gen.c
122 ARM64_FILES
= $(CORE_FILES
) arm64-gen.c
123 C67_FILES
= $(CORE_FILES
) c67-gen.c tcccoff.c
126 PROGS
+=tiny_impdef
$(EXESUF
) tiny_libmaker
$(EXESUF
)
127 NATIVE_FILES
=$(WIN64_FILES
)
128 PROGS_CROSS
=$(WIN32_CROSS
) $(I386_CROSS
) $(X64_CROSS
) $(ARM_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
129 LIBTCC1_CROSS
=lib
/i386-win
/libtcc1.a
131 else ifdef CONFIG_WIN32
132 PROGS
+=tiny_impdef
$(EXESUF
) tiny_libmaker
$(EXESUF
)
133 NATIVE_FILES
=$(WIN32_FILES
)
134 PROGS_CROSS
=$(WIN64_CROSS
) $(I386_CROSS
) $(X64_CROSS
) $(ARM_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
135 LIBTCC1_CROSS
=lib
/x86_64-win
/libtcc1.a
137 else ifeq ($(ARCH
),i386
)
138 NATIVE_FILES
=$(I386_FILES
)
139 PROGS_CROSS
=$($(X64_CROSS
)_LINK
) $($(WIN32_CROSS
)_LINK
) $($(WIN64_CROSS
)_LINK
) $(ARM_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
140 LIBTCC1_CROSS
=lib
/i386-win
/libtcc1.a lib
/x86_64-win
/libtcc1.a lib
/i386
/libtcc1.a lib
/x86_64
/libtcc1.a \
143 else ifeq ($(ARCH
),x86-64
)
144 ifeq ($(TARGETOS
),Darwin
)
145 NATIVE_FILES
=$(X86_64_FILES
)
146 PROGS_CROSS
=$($(I386_CROSS
)_LINK
) $($(WIN32_CROSS
)_LINK
) $($(WIN64_CROSS
)_LINK
) $(ARM_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
147 LIBTCC1_CROSS
=lib
/i386-win
/libtcc1.a lib
/x86_64-win
/libtcc1.a lib
/i386
/libtcc1.a lib
/x86_64
/libtcc1.a
150 NATIVE_FILES
=$(X86_64_FILES
)
151 PROGS_CROSS
=$($(I386_CROSS
)_LINK
) $($(WIN32_CROSS
)_LINK
) $($(WIN64_CROSS
)_LINK
) $(ARM_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
152 LIBTCC1_CROSS
=lib
/i386-win
/libtcc1.a lib
/x86_64-win
/libtcc1.a lib
/i386
/libtcc1.a lib
/x86_64
/libtcc1.a \
156 else ifeq ($(ARCH
),arm
)
157 NATIVE_FILES
=$(ARM_FILES
)
158 PROGS_CROSS
=$(I386_CROSS
) $(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
160 LIBTCC1_CROSS
=lib
/i386-win
/libtcc1.a lib
/x86_64-win
/libtcc1.a lib
/i386
/libtcc1.a
161 else ifeq ($(ARCH
),arm64
)
162 NATIVE_FILES
=$(ARM64_FILES
)
163 PROGS_CROSS
=$(I386_CROSS
) $(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
165 LIBTCC1_CROSS
=lib
/i386-win
/libtcc1.a lib
/x86_64-win
/libtcc1.a lib
/i386
/libtcc1.a
167 PROGS_CROSS_LINK
=$(foreach PROG_CROSS
,$(PROGS_CROSS
),$($(PROG_CROSS
)_LINK
))
169 ifeq ($(TARGETOS
),Darwin
)
170 PROGS
+=tiny_libmaker
$(EXESUF
)
173 TCCLIBS
= $(LIBTCC1
) $(LIBTCC
) $(LIBTCC_EXTRA
)
174 TCCDOCS
= tcc
.1 tcc-doc.html tcc-doc.
info
177 PROGS
+=$(PROGS_CROSS
)
178 TCCLIBS
+=$(LIBTCC1_CROSS
)
181 all: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
183 # Host Tiny C Compiler
184 tcc
$(EXESUF
): tcc.o
$(LIBTCC
)
185 $(CC
) -o
$@
$^
$(LIBS
) $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
) $(LINK_LIBTCC
)
187 # Cross Tiny C Compilers
188 %-tcc
$(EXESUF
): tcc.c
189 $(CC
) -o
$@
$< -DONE_SOURCE
$(if
$($@_TCC
),$(NATIVE_DEFINES
),$(DEFINES
)) $(CPPFLAGS
) $(CFLAGS
) $(LIBS
) $(LDFLAGS
)
190 $(if
$($@_LINK
),ln
-sf
$@
$($@_LINK
))
191 $(if
$($@_TCC
),ln
-sf
$@ tcc
$(EXESUF
))
194 tcc_p
$(EXESUF
): $(NATIVE_FILES
)
195 $(CC
) -o
$@
$< -DONE_SOURCE
$(NATIVE_DEFINES
) $(CPPFLAGS_P
) $(CFLAGS_P
) $(LIBS_P
) $(LDFLAGS_P
)
197 $(I386_CROSS
) $($(I386_CROSS
)_LINK
): DEFINES
= -DTCC_TARGET_I386
198 $(X64_CROSS
) $($(X64_CROSS
)_LINK
): DEFINES
= -DTCC_TARGET_X86_64
199 $(WIN32_CROSS
) $($(WIN32_CROSS
)_LINK
): DEFINES
= -DTCC_TARGET_I386
-DTCC_TARGET_PE \
200 -DCONFIG_TCCDIR
="\"$(tccdir)/win32\"" \
201 -DCONFIG_TCC_LIBPATHS
="\"{B}/lib/32;{B}/lib\""
202 $(WIN64_CROSS
) $($(WIN64_CROSS
)_LINK
): DEFINES
= -DTCC_TARGET_X86_64
-DTCC_TARGET_PE \
203 -DCONFIG_TCCDIR
="\"$(tccdir)/win32\"" \
204 -DCONFIG_TCC_LIBPATHS
="\"{B}/lib/64;{B}/lib\""
205 $(WINCE_CROSS
): DEFINES
= -DTCC_TARGET_PE
206 $(C67_CROSS
): DEFINES
= -DTCC_TARGET_C67
207 $(ARM_FPA_CROSS
): DEFINES
= -DTCC_TARGET_ARM
208 $(ARM_FPA_LD_CROSS
)$(EXESUF
): DEFINES
= -DTCC_TARGET_ARM
-DLDOUBLE_SIZE
=12
209 $(ARM_VFP_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_ARM_VFP
210 $(ARM_EABI_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_ARM_EABI
-DTCC_ARM_VFP
211 $(ARM64_CROSS
): DEFINES
= -DTCC_TARGET_ARM64
213 $(I386_CROSS
) $($(I386_CROSS
)_LINK
): $(I386_FILES
)
214 $(X64_CROSS
) $($(X64_CROSS
)_LINK
): $(X86_64_FILES
)
215 $(WIN32_CROSS
) $($(WIN32_CROSS
)_LINK
): $(WIN32_FILES
)
216 $(WIN64_CROSS
) $($(WIN64_CROSS
)_LINK
): $(WIN64_FILES
)
217 $(WINCE_CROSS
) $($(WINCE_CROSS
)_LINK
): $(WINCE_FILES
)
218 $(C67_CROSS
) $($(C67_CROSS
)_LINK
): $(C67_FILES
)
219 $(ARM_FPA_CROSS
) $(ARM_FPA_LD_CROSS
) $(ARM_VFP_CROSS
) $(ARM_EABI_CROSS
): $(ARM_FILES
)
220 $($(ARM_FPA_CROSS
)_LINK
) $($(ARM_FPA_LD_CROSS
)_LINK
) $($(ARM_VFP_CROSS
)_LINK
) $($(ARM_EABI_CROSS
)_LINK
): $(ARM_FILES
)
221 $(ARM64_CROSS
): $(ARM64_FILES
)
223 # libtcc generation and test
225 LIBTCC_OBJ
= $(filter-out tcc.o
,$(patsubst %.c
,%.o
,$(filter %.c
,$(NATIVE_FILES
))))
226 LIBTCC_INC
= $(filter %.h
,$(CORE_FILES
)) $(filter-out $(CORE_FILES
),$(NATIVE_FILES
))
228 LIBTCC_OBJ
= libtcc.o
229 LIBTCC_INC
= $(NATIVE_FILES
)
230 libtcc.o
: NATIVE_DEFINES
+= -DONE_SOURCE
233 $(LIBTCC_OBJ
) tcc.o
: %.o
: %.c
$(LIBTCC_INC
)
234 $(CC
) -o
$@
-c
$< $(NATIVE_DEFINES
) $(CPPFLAGS
) $(CFLAGS
)
237 libtcc.a
: $(LIBTCC_OBJ
)
241 libtcc.so
.1.0: $(LIBTCC_OBJ
)
242 $(CC
) -shared
-Wl
,-soname
,$@
-o
$@
$^
$(LDFLAGS
)
244 libtcc.so
.1.0: CFLAGS
+=-fPIC
247 libtcc.dll libtcc.def libtcc.a
: $(LIBTCC_OBJ
)
248 $(CC
) -shared
$^
-o
$@
$(LDFLAGS
) -Wl
,--output-def
,libtcc.def
,--out-implib
,libtcc.a
252 tiny_impdef
$(EXESUF
): win32
/tools
/tiny_impdef.c
253 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
254 tiny_libmaker
$(EXESUF
): win32
/tools
/tiny_libmaker.c
255 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
257 # TinyCC runtime libraries
259 $(MAKE
) -C lib native
260 if
test ! -d
$(ARCH
); then mkdir
$(ARCH
); fi
261 if
test ! -L
$(ARCH
)/$@
; then ln
-sf ..
/$@
$(ARCH
)/$@
; fi
262 lib
/%/libtcc1.a
: FORCE
$(PROGS_CROSS
)
263 $(MAKE
) -C lib cross TARGET
=$*
268 TCC_INCLUDES
= stdarg.h stddef.h stdbool.h float.h varargs.h
271 INSTALLBIN
=$(INSTALL
) -s
273 INSTALLBIN
=$(INSTALL
)
276 install-strip
: install
277 strip $(foreach PROG
,$(PROGS
),"$(bindir)"/$(PROG
))
280 install: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
282 $(INSTALLBIN
) -m755
$(PROGS
) "$(bindir)"
283 cp
-P tcc
$(EXESUF
) "$(bindir)"
284 mkdir
-p
"$(mandir)/man1"
285 -$(INSTALL
) -m644 tcc
.1 "$(mandir)/man1"
286 mkdir
-p
"$(infodir)"
287 -$(INSTALL
) -m644 tcc-doc.
info "$(infodir)"
289 mkdir
-p
"$(tccdir)/include"
291 mkdir
-p
"$(tccdir)/$(ARCH)"
292 $(INSTALL
) -m644
$(LIBTCC1
) "$(tccdir)/$(ARCH)"
294 $(INSTALL
) -m644
$(addprefix $(top_srcdir
)/include/,$(TCC_INCLUDES
)) $(top_srcdir
)/tcclib.h
"$(tccdir)/include"
296 $(INSTALL
) -m644
$(LIBTCC
) "$(libdir)"
298 ln
-sf
"$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so.1"
299 ln
-sf
"$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so"
301 mkdir
-p
"$(includedir)"
302 $(INSTALL
) -m644
$(top_srcdir
)/libtcc.h
"$(includedir)"
304 -$(INSTALL
) -m644 tcc-doc.html
"$(docdir)"
306 mkdir
-p
"$(tccdir)/win32/lib/32"
307 mkdir
-p
"$(tccdir)/win32/lib/64"
308 mkdir
-p
"$(tccdir)/i386"
309 mkdir
-p
"$(tccdir)/x86-64"
310 ifneq ($(HOST_OS
),Darwin
)
311 mkdir
-p
"$(tccdir)/arm64"
312 $(INSTALL
) -m644 lib
/arm64
/libtcc1.a
"$(tccdir)/arm64"
314 $(INSTALL
) -m644 lib
/i386
/libtcc1.a
"$(tccdir)/i386"
315 $(INSTALL
) -m644 lib
/x86_64
/libtcc1.a
"$(tccdir)/x86-64"
316 $(INSTALL
) -m644
$(top_srcdir
)/win32
/lib
/*.def
"$(tccdir)/win32/lib"
317 $(INSTALL
) -m644 lib
/i386-win
/libtcc1.a
"$(tccdir)/win32/lib/32"
318 $(INSTALL
) -m644 lib
/x86_64-win
/libtcc1.a
"$(tccdir)/win32/lib/64"
319 cp
-r
$(top_srcdir
)/win32
/include/.
"$(tccdir)/win32/include"
320 cp
-r
"$(tccdir)/include" "$(tccdir)/win32"
324 rm -fv
$(foreach P
,$(PROGS
),"$(bindir)/$P")
325 rm -fv
"$(bindir)/tcc$(EXESUF)"
326 rm -fv
$(foreach P
,$(LIBTCC1
),"$(tccdir)/$P")
327 rm -fv
$(foreach P
,$(TCC_INCLUDES
),"$(tccdir)/include/$P")
328 rm -fv
"$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
329 rm -fv
"$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
330 rm -fv
"$(libdir)/libtcc.so*"
335 install: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
337 mkdir
-p
"$(tccdir)/lib"
338 mkdir
-p
"$(tccdir)/include"
339 mkdir
-p
"$(tccdir)/examples"
340 mkdir
-p
"$(tccdir)/doc"
341 mkdir
-p
"$(tccdir)/libtcc"
342 $(INSTALLBIN
) -m755
$(PROGS
) "$(tccdir)"
343 $(INSTALLBIN
) -m755 tcc.exe
"$(tccdir)"
344 $(INSTALL
) -m644
$(LIBTCC1
) $(top_srcdir
)/win32
/lib
/*.def
"$(tccdir)/lib"
345 cp
-r
$(top_srcdir
)/win32
/include/.
"$(tccdir)/include"
346 cp
-r
$(top_srcdir
)/win32
/examples
/.
"$(tccdir)/examples"
347 $(INSTALL
) -m644
$(addprefix $(top_srcdir
)/include/,$(TCC_INCLUDES
)) $(top_srcdir
)/tcclib.h
"$(tccdir)/include"
348 $(INSTALL
) -m644 tcc-doc.html
$(top_srcdir
)/win32
/tcc-win32.txt
"$(tccdir)/doc"
349 $(INSTALL
) -m644
$(top_srcdir
)/libtcc.h
$(LIBTCC_EXTRA
) "$(tccdir)/libtcc"
350 $(INSTALL
) -m644
$(LIBTCC
) "$(tccdir)"
352 mkdir
-p
"$(tccdir)/lib/32"
353 mkdir
-p
"$(tccdir)/lib/64"
354 -$(INSTALL
) -m644 lib
/i386-win
/libtcc1.a
"$(tccdir)/lib/32"
355 -$(INSTALL
) -m644 lib
/x86_64-win
/libtcc1.a
"$(tccdir)/lib/64"
359 rm -rfv
"$(tccdir)/*"
362 # documentation and man page
363 tcc-doc.html
: tcc-doc.texi
364 -makeinfo --no-split
--html
--number-sections
-o
$@
$<
367 -$(top_srcdir
)/texi2pod.pl
$< tcc.pod
368 -pod2man
--section
=1 --center
="Tiny C Compiler" --release
=`cat $(top_srcdir)/VERSION` tcc.pod
> $@
370 tcc-doc.
info: tcc-doc.texi
377 $(MAKE
) -C tests
$@
'PROGS_CROSS=$(PROGS_CROSS)'
380 rm -vf
$(PROGS
) tcc_p
$(EXESUF
) tcc.pod
*~
*.o
*.a
*.so
* *.out
*.log \
381 *.exe a.out
tags TAGS libtcc_test
$(EXESUF
) tcc
$(EXESUF
)
383 ifeq ($(HOST_OS
),Linux
)
393 rm -vf config.h config.mak config.texi tcc
.1 tcc-doc.
info tcc-doc.html
396 @echo
"Please run ./configure."
400 ctags
$(top_srcdir
)/*.
[ch
] $(top_srcdir
)/include/*.h
$(top_srcdir
)/lib
/*.
[chS
]
403 ctags
-e
$(top_srcdir
)/*.
[ch
] $(top_srcdir
)/include/*.h
$(top_srcdir
)/lib
/*.
[chS
]
405 # create release tarball from *current* git branch (including tcc-doc.html
406 # and converting two files to CRLF)
407 TCC-VERSION
:= tcc-
$(shell cat
$(top_srcdir
)/VERSION
)
410 ( cd
$(TCC-VERSION
) && git
--git-dir ..
/.git checkout
-f
)
411 cp tcc-doc.html
$(TCC-VERSION
)
412 for f in tcc-win32.txt build-tcc.bat
; do \
413 cat win32
/$$f | sed
's,\(.*\),\1\r,g' > $(TCC-VERSION
)/win32
/$$f ; \
415 tar cjf
$(TCC-VERSION
).
tar.bz2
$(TCC-VERSION
)
416 rm -rf
$(TCC-VERSION
)
419 .PHONY
: all clean tar tags TAGS
distclean install uninstall FORCE
421 endif # ifeq ($(TOP),.)