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
)
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
)
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 PROGS
+=tiny_libmaker
$(EXESUF
)
171 TCCLIBS
= $(LIBTCC1
) $(LIBTCC
) $(LIBTCC_EXTRA
)
172 TCCDOCS
= tcc
.1 tcc-doc.html tcc-doc.
info
175 PROGS
+=$(PROGS_CROSS
)
176 TCCLIBS
+=$(LIBTCC1_CROSS
)
179 all: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
181 # Host Tiny C Compiler
182 tcc
$(EXESUF
): tcc.o
$(LIBTCC
)
183 $(CC
) -o
$@
$^
$(LIBS
) $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
) $(LINK_LIBTCC
)
185 # Cross Tiny C Compilers
186 %-tcc
$(EXESUF
): tcc.c
187 $(CC
) -o
$@
$< -DONE_SOURCE
$(if
$($@_TCC
),$(NATIVE_DEFINES
),$(DEFINES
)) $(CPPFLAGS
) $(CFLAGS
) $(LIBS
) $(LDFLAGS
)
188 $(if
$($@_LINK
),ln
-sf
$@
$($@_LINK
))
189 $(if
$($@_TCC
),ln
-sf
$@ tcc
$(EXESUF
))
192 tcc_p
$(EXESUF
): $(NATIVE_FILES
)
193 $(CC
) -o
$@
$< -DONE_SOURCE
$(NATIVE_DEFINES
) $(CPPFLAGS_P
) $(CFLAGS_P
) $(LIBS_P
) $(LDFLAGS_P
)
195 $(I386_CROSS
) $($(I386_CROSS
)_LINK
): DEFINES
= -DTCC_TARGET_I386
196 $(X64_CROSS
) $($(X64_CROSS
)_LINK
): DEFINES
= -DTCC_TARGET_X86_64
197 $(WIN32_CROSS
) $($(WIN32_CROSS
)_LINK
): DEFINES
= -DTCC_TARGET_I386
-DTCC_TARGET_PE \
198 -DCONFIG_TCCDIR
="\"$(tccdir)/win32\"" \
199 -DCONFIG_TCC_LIBPATHS
="\"{B}/lib/32;{B}/lib\""
200 $(WIN64_CROSS
) $($(WIN64_CROSS
)_LINK
): DEFINES
= -DTCC_TARGET_X86_64
-DTCC_TARGET_PE \
201 -DCONFIG_TCCDIR
="\"$(tccdir)/win32\"" \
202 -DCONFIG_TCC_LIBPATHS
="\"{B}/lib/64;{B}/lib\""
203 $(WINCE_CROSS
): DEFINES
= -DTCC_TARGET_PE
204 $(C67_CROSS
): DEFINES
= -DTCC_TARGET_C67
205 $(ARM_FPA_CROSS
): DEFINES
= -DTCC_TARGET_ARM
206 $(ARM_FPA_LD_CROSS
)$(EXESUF
): DEFINES
= -DTCC_TARGET_ARM
-DLDOUBLE_SIZE
=12
207 $(ARM_VFP_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_ARM_VFP
208 $(ARM_EABI_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_ARM_EABI
-DTCC_ARM_VFP
209 $(ARM64_CROSS
): DEFINES
= -DTCC_TARGET_ARM64
211 $(I386_CROSS
) $($(I386_CROSS
)_LINK
): $(I386_FILES
)
212 $(X64_CROSS
) $($(X64_CROSS
)_LINK
): $(X86_64_FILES
)
213 $(WIN32_CROSS
) $($(WIN32_CROSS
)_LINK
): $(WIN32_FILES
)
214 $(WIN64_CROSS
) $($(WIN64_CROSS
)_LINK
): $(WIN64_FILES
)
215 $(WINCE_CROSS
) $($(WINCE_CROSS
)_LINK
): $(WINCE_FILES
)
216 $(C67_CROSS
) $($(C67_CROSS
)_LINK
): $(C67_FILES
)
217 $(ARM_FPA_CROSS
) $(ARM_FPA_LD_CROSS
) $(ARM_VFP_CROSS
) $(ARM_EABI_CROSS
): $(ARM_FILES
)
218 $($(ARM_FPA_CROSS
)_LINK
) $($(ARM_FPA_LD_CROSS
)_LINK
) $($(ARM_VFP_CROSS
)_LINK
) $($(ARM_EABI_CROSS
)_LINK
): $(ARM_FILES
)
219 $(ARM64_CROSS
): $(ARM64_FILES
)
221 # libtcc generation and test
223 LIBTCC_OBJ
= $(filter-out tcc.o
,$(patsubst %.c
,%.o
,$(filter %.c
,$(NATIVE_FILES
))))
224 LIBTCC_INC
= $(filter %.h
,$(CORE_FILES
)) $(filter-out $(CORE_FILES
),$(NATIVE_FILES
))
226 LIBTCC_OBJ
= libtcc.o
227 LIBTCC_INC
= $(NATIVE_FILES
)
228 libtcc.o
: NATIVE_DEFINES
+= -DONE_SOURCE
231 $(LIBTCC_OBJ
) tcc.o
: %.o
: %.c
$(LIBTCC_INC
)
232 $(CC
) -o
$@
-c
$< $(NATIVE_DEFINES
) $(CPPFLAGS
) $(CFLAGS
)
235 libtcc.a
: $(LIBTCC_OBJ
)
239 libtcc.so
.1.0: $(LIBTCC_OBJ
)
240 $(CC
) -shared
-Wl
,-soname
,$@
-o
$@
$^
$(LDFLAGS
)
242 libtcc.so
.1.0: CFLAGS
+=-fPIC
245 libtcc.dll libtcc.def libtcc.a
: $(LIBTCC_OBJ
)
246 $(CC
) -shared
$^
-o
$@
$(LDFLAGS
) -Wl
,--output-def
,libtcc.def
,--out-implib
,libtcc.a
250 tiny_impdef
$(EXESUF
): win32
/tools
/tiny_impdef.c
251 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
252 tiny_libmaker
$(EXESUF
): win32
/tools
/tiny_libmaker.c
253 $(CC
) -o
$@
$< $(CPPFLAGS
) $(CFLAGS
) $(LDFLAGS
)
255 # TinyCC runtime libraries
256 libtcc1.a
: FORCE
$(PROGS
)
257 $(MAKE
) -C lib native
258 if
test ! -d
$(ARCH
); then mkdir
$(ARCH
); fi
259 if
test ! -L
$(ARCH
)/$@
; then ln
-sf ..
/$@
$(ARCH
)/$@
; fi
260 lib
/%/libtcc1.a
: FORCE
$(PROGS_CROSS
)
261 $(MAKE
) -C lib cross TARGET
=$*
266 TCC_INCLUDES
= stdarg.h stddef.h stdbool.h float.h varargs.h
269 INSTALLBIN
=$(INSTALL
) -s
271 INSTALLBIN
=$(INSTALL
)
281 install-strip
: install
282 strip $(foreach PROG
,$(PROGS
),"$(bindir)"/$(PROG
))
285 install: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
287 $(INSTALLBIN
) -m755
$(PROGS
) "$(bindir)"
288 cp
-P tcc
$(EXESUF
) "$(bindir)"
289 mkdir
-p
"$(mandir)/man1"
290 -$(INSTALL
) -m644 tcc
.1 "$(mandir)/man1"
291 mkdir
-p
"$(infodir)"
292 -$(INSTALL
) -m644 tcc-doc.
info "$(infodir)"
294 mkdir
-p
"$(tccdir)/include"
296 mkdir
-p
"$(tccdir)/$(ARCH)"
297 $(INSTALL
) -m644
$(LIBTCC1
) "$(tccdir)/$(ARCH)"
299 $(INSTALL
) -m644
$(addprefix $(top_srcdir
)/include/,$(TCC_INCLUDES
)) $(top_srcdir
)/tcclib.h
"$(tccdir)/include"
301 $(INSTALL
) -m644
$(LIBTCC
) "$(libdir)"
303 ln
-sf
"$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so.1"
304 ln
-sf
"$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so"
306 mkdir
-p
"$(includedir)"
307 $(INSTALL
) -m644
$(top_srcdir
)/libtcc.h
"$(includedir)"
309 -$(INSTALL
) -m644 tcc-doc.html
"$(docdir)"
311 mkdir
-p
"$(tccdir)/win32/lib/32"
312 mkdir
-p
"$(tccdir)/win32/lib/64"
313 mkdir
-p
"$(tccdir)/i386"
314 mkdir
-p
"$(tccdir)/x86-64"
315 ifneq ($(HOST_OS
),Darwin
)
316 mkdir
-p
"$(tccdir)/arm64"
317 $(INSTALL
) -m644 lib
/arm64
/libtcc1.a
"$(tccdir)/arm64"
319 $(INSTALL
) -m644 lib
/i386
/libtcc1.a
"$(tccdir)/i386"
320 $(INSTALL
) -m644 lib
/x86_64
/libtcc1.a
"$(tccdir)/x86-64"
321 $(INSTALL
) -m644
$(top_srcdir
)/win32
/lib
/*.def
"$(tccdir)/win32/lib"
322 $(INSTALL
) -m644 lib
/i386-win
/libtcc1.a
"$(tccdir)/win32/lib/32"
323 $(INSTALL
) -m644 lib
/x86_64-win
/libtcc1.a
"$(tccdir)/win32/lib/64"
324 cp
-r
$(top_srcdir
)/win32
/include/.
"$(tccdir)/win32/include"
325 cp
-r
"$(tccdir)/include" "$(tccdir)/win32"
329 rm -fv
$(foreach P
,$(PROGS
),"$(bindir)/$P")
330 rm -fv
"$(bindir)/tcc$(EXESUF)"
331 rm -fv
$(foreach P
,$(LIBTCC1
),"$(tccdir)/$P")
332 rm -fv
$(foreach P
,$(TCC_INCLUDES
),"$(tccdir)/include/$P")
333 rm -fv
"$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
334 rm -fv
"$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
335 rm -fv
"$(libdir)/libtcc.so*"
340 install: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
342 mkdir
-p
"$(tccdir)/lib"
343 mkdir
-p
"$(tccdir)/include"
344 mkdir
-p
"$(tccdir)/examples"
345 mkdir
-p
"$(tccdir)/doc"
346 mkdir
-p
"$(tccdir)/libtcc"
347 $(INSTALLBIN
) -m755
$(PROGS
) "$(tccdir)"
348 $(INSTALLBIN
) -m755 tcc.exe
"$(tccdir)"
349 $(INSTALL
) -m644
$(LIBTCC1
) $(top_srcdir
)/win32
/lib
/*.def
"$(tccdir)/lib"
350 cp
-r
$(top_srcdir
)/win32
/include/.
"$(tccdir)/include"
351 cp
-r
$(top_srcdir
)/win32
/examples
/.
"$(tccdir)/examples"
352 $(INSTALL
) -m644
$(addprefix $(top_srcdir
)/include/,$(TCC_INCLUDES
)) $(top_srcdir
)/tcclib.h
"$(tccdir)/include"
353 $(INSTALL
) -m644 tcc-doc.html
$(top_srcdir
)/win32
/tcc-win32.txt
"$(tccdir)/doc"
354 $(INSTALL
) -m644
$(top_srcdir
)/libtcc.h
$(LIBTCC_EXTRA
) "$(tccdir)/libtcc"
355 $(INSTALL
) -m644
$(LIBTCC
) "$(tccdir)"
357 mkdir
-p
"$(tccdir)/lib/32"
358 mkdir
-p
"$(tccdir)/lib/64"
359 -$(INSTALL
) -m644 lib
/i386-win
/libtcc1.a
"$(tccdir)/lib/32"
360 -$(INSTALL
) -m644 lib
/x86_64-win
/libtcc1.a
"$(tccdir)/lib/64"
364 rm -rfv
"$(tccdir)/*"
367 # documentation and man page
368 tcc-doc.html
: tcc-doc.texi
369 -makeinfo --no-split
--html
--number-sections
-o
$@
$<
372 -$(top_srcdir
)/texi2pod.pl
$< tcc.pod
373 -pod2man
--section
=1 --center
="Tiny C Compiler" --release
=`cat $(top_srcdir)/VERSION` tcc.pod
> $@
375 tcc-doc.
info: tcc-doc.texi
382 $(MAKE
) -C tests
$@
'PROGS_CROSS=$(PROGS_CROSS)'
385 rm -vf
$(PROGS
) tcc_p
$(EXESUF
) tcc.pod
*~
*.o
*.a
*.so
* *.out
*.log \
386 *.exe a.out
tags TAGS libtcc_test
$(EXESUF
) tcc
$(EXESUF
)
388 ifeq ($(HOST_OS
),Linux
)
398 rm -vf config.h config.mak config.texi tcc
.1 tcc-doc.
info tcc-doc.html
401 @echo
"Please run ./configure."
405 ctags
$(top_srcdir
)/*.
[ch
] $(top_srcdir
)/include/*.h
$(top_srcdir
)/lib
/*.
[chS
]
408 ctags
-e
$(top_srcdir
)/*.
[ch
] $(top_srcdir
)/include/*.h
$(top_srcdir
)/lib
/*.
[chS
]
410 # create release tarball from *current* git branch (including tcc-doc.html
411 # and converting two files to CRLF)
412 TCC-VERSION
:= tcc-
$(shell cat
$(top_srcdir
)/VERSION
)
415 ( cd
$(TCC-VERSION
) && git
--git-dir ..
/.git checkout
-f
)
416 cp tcc-doc.html
$(TCC-VERSION
)
417 for f in tcc-win32.txt build-tcc.bat
; do \
418 cat win32
/$$f | sed
's,\(.*\),\1\r,g' > $(TCC-VERSION
)/win32
/$$f ; \
420 tar cjf
$(TCC-VERSION
).
tar.bz2
$(TCC-VERSION
)
421 rm -rf
$(TCC-VERSION
)
424 .PHONY
: all clean tar tags TAGS
distclean install uninstall FORCE
426 endif # ifeq ($(TOP),.)