2 # Tiny C Compiler Makefile
6 include $(TOP
)/config.mak
10 ifeq (-$(findstring gcc
,$(CC
))-,-gcc-
)
11 ifeq (-$(GCC_MAJOR
)-$(findstring $(GCC_MINOR
),56789)-,-4--)
12 CFLAGS
+= -D_FORTIFY_SOURCE
=0
15 ifeq (-$(findstring clang
,$(CC
))-,-clang-
)
16 # make clang accept gnuisms in libtcc1.c
17 CFLAGS
+=-fheinous-gnu-extensions
33 # make libtcc as static or dynamic library?
37 LINK_LIBTCC
+= -Wl
,-rpath
,"$(libdir)"
38 export LD_LIBRARY_PATH
:= $(CURDIR
)/$(TOP
)
43 ifeq ($(TARGETOS
),Darwin
)
44 CFLAGS
+= -Wl
,-flat_namespace
,-undefined
,warning
45 export MACOSX_DEPLOYMENT_TARGET
:=10.2
48 CFLAGS_P
= $(CFLAGS
) -pg
-static
-DCONFIG_TCC_STATIC
-DTCC_PROFILE
50 LDFLAGS_P
= $(LDFLAGS
)
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-tcc
$(EXESUF
)
68 WIN32_CROSS
= i386-win32-tcc
$(EXESUF
)
69 WIN64_CROSS
= x86_64-win32-tcc
$(EXESUF
)
70 WINCE_CROSS
= arm-wince-tcc
$(EXESUF
)
71 X64_CROSS
= x86_64-tcc
$(EXESUF
)
72 ARM_FPA_CROSS
= arm-fpa-tcc
$(EXESUF
)
73 ARM_FPA_LD_CROSS
= arm-fpa-ld-tcc
$(EXESUF
)
74 ARM_VFP_CROSS
= arm-vfp-tcc
$(EXESUF
)
75 ARM_EABI_CROSS
= arm-eabi-tcc
$(EXESUF
)
76 ARM_EABIHF_CROSS
= arm-eabihf-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 CORE_FILES
= tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
82 CORE_FILES
+= tcc.h config.h libtcc.h tcctok.h
83 I386_FILES
= $(CORE_FILES
) i386-gen.c i386-asm.c i386-asm.h i386-tok.h
84 WIN32_FILES
= $(CORE_FILES
) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
85 WIN64_FILES
= $(CORE_FILES
) x86_64-gen.c i386-asm.c x86_64-asm.h tccpe.c
86 WINCE_FILES
= $(CORE_FILES
) arm-gen.c tccpe.c
87 X86_64_FILES
= $(CORE_FILES
) x86_64-gen.c i386-asm.c x86_64-asm.h
88 ARM_FILES
= $(CORE_FILES
) arm-gen.c
89 ARM64_FILES
= $(CORE_FILES
) arm64-gen.c
90 C67_FILES
= $(CORE_FILES
) c67-gen.c tcccoff.c
93 PROGS
+=tiny_impdef
$(EXESUF
) tiny_libmaker
$(EXESUF
) $(LIBTCC
)
95 NATIVE_FILES
=$(WIN64_FILES
)
96 PROGS_CROSS
=$(WIN32_CROSS
) $(X64_CROSS
) $(ARM_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
97 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a
99 NATIVE_FILES
=$(WIN32_FILES
)
100 PROGS_CROSS
=$(WIN64_CROSS
) $(X64_CROSS
) $(ARM_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
101 LIBTCC1_CROSS
=lib
/x86_64-win32
/libtcc1.a
104 else ifeq ($(ARCH
),i386
)
105 NATIVE_FILES
=$(I386_FILES
)
106 PROGS_CROSS
=$(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
107 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a lib
/x86_64-win32
/libtcc1.a
109 else ifeq ($(ARCH
),x86-64
)
110 NATIVE_FILES
=$(X86_64_FILES
)
111 PROGS_CROSS
=$(I386_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
112 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a lib
/x86_64-win32
/libtcc1.a
114 else ifeq ($(ARCH
),arm
)
115 NATIVE_FILES
=$(ARM_FILES
)
116 PROGS_CROSS
=$(I386_CROSS
) $(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
118 else ifeq ($(ARCH
),arm64
)
119 NATIVE_FILES
=$(ARM64_FILES
)
120 PROGS_CROSS
=$(I386_CROSS
) $(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
123 ifeq ($(TARGETOS
),Darwin
)
124 PROGS
+= tiny_libmaker
$(EXESUF
)
127 TCCLIBS
= $(LIBTCC1
) $(LIBTCC
)
128 TCCDOCS
= tcc
.1 tcc-doc.html tcc-doc.
info
131 PROGS
+= $(PROGS_CROSS
)
132 TCCLIBS
+= $(LIBTCC1_CROSS
)
135 all: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
137 # Host Tiny C Compiler
138 tcc
$(EXESUF
): tcc.o
$(LIBTCC
)
139 $(CC
) -o
$@
$^
$(CFLAGS
) $(LDFLAGS
) $(LIBS
) $(LINK_LIBTCC
)
141 # Cross Tiny C Compilers
142 %-tcc
$(EXESUF
): tcc.c
143 $(CC
) -o
$@
$< -DONE_SOURCE
$(DEFINES
) $(CFLAGS
) $(LIBS
) $(LDFLAGS
)
146 tcc_p
$(EXESUF
): $(NATIVE_FILES
)
147 $(CC
) -o
$@
$< -DONE_SOURCE
$(NATIVE_DEFINES
) $(CPPFLAGS_P
) $(CFLAGS_P
) $(LIBS_P
) $(LDFLAGS_P
)
149 $(I386_CROSS
): DEFINES
= -DTCC_TARGET_I386 \
150 -DCONFIG_TCCDIR
="\"$(tccdir)/i386\""
151 $(X64_CROSS
) : DEFINES
= -DTCC_TARGET_X86_64
152 -DCONFIG_TCCDIR
="\"$(tccdir)/x86_64\""
153 $(WIN32_CROSS
) : DEFINES
= -DTCC_TARGET_I386
-DTCC_TARGET_PE \
154 -DCONFIG_TCCDIR
="\"$(tccdir)/win32\"" \
155 -DCONFIG_TCC_LIBPATHS
="\"{B}/lib/32;{B}/lib\""
156 $(WIN64_CROSS
) : DEFINES
= -DTCC_TARGET_X86_64
-DTCC_TARGET_PE \
157 -DCONFIG_TCCDIR
="\"$(tccdir)/win32\"" \
158 -DCONFIG_TCC_LIBPATHS
="\"{B}/lib/64;{B}/lib\""
159 $(WINCE_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_TARGET_PE
160 $(C67_CROSS
): DEFINES
= -DTCC_TARGET_C67
-w
# disable warnigs
161 $(ARM_FPA_CROSS
): DEFINES
= -DTCC_TARGET_ARM
162 $(ARM_FPA_LD_CROSS
)$(EXESUF
): DEFINES
= -DTCC_TARGET_ARM
-DLDOUBLE_SIZE
=12
163 $(ARM_VFP_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_ARM_VFP
164 $(ARM_EABI_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_ARM_EABI
-DTCC_ARM_VFP
165 $(ARM64_CROSS
): DEFINES
= -DTCC_TARGET_ARM64
167 $(I386_CROSS
) : $(I386_FILES
)
168 $(X64_CROSS
) : $(X86_64_FILES
)
169 $(WIN32_CROSS
) : $(WIN32_FILES
)
170 $(WIN64_CROSS
) : $(WIN64_FILES
)
171 $(WINCE_CROSS
) : $(WINCE_FILES
)
172 $(C67_CROSS
) : $(C67_FILES
)
173 $(ARM_FPA_CROSS
) $(ARM_FPA_LD_CROSS
) $(ARM_VFP_CROSS
) $(ARM_EABI_CROSS
): $(ARM_FILES
)
174 $(ARM64_CROSS
): $(ARM64_FILES
)
176 # libtcc generation and test
178 LIBTCC_OBJ
= $(filter-out tcc.o
,$(patsubst %.c
,%.o
,$(filter %.c
,$(NATIVE_FILES
))))
179 LIBTCC_INC
= $(filter %.h
,$(CORE_FILES
)) $(filter-out $(CORE_FILES
) i386-asm.c
,$(NATIVE_FILES
))
181 LIBTCC_OBJ
= libtcc.o
182 LIBTCC_INC
= $(NATIVE_FILES
)
183 libtcc.o
: NATIVE_DEFINES
+= -DONE_SOURCE
186 $(LIBTCC_OBJ
) tcc.o
: %.o
: %.c
$(LIBTCC_INC
)
187 $(CC
) -o
$@
-c
$< $(NATIVE_DEFINES
) $(CFLAGS
)
189 libtcc.a
: $(LIBTCC_OBJ
)
192 libtcc.so
: $(LIBTCC_OBJ
)
193 $(CC
) -shared
-Wl
,-soname
,$@
-o
$@
$^
$(LDFLAGS
)
195 libtcc.so
: CFLAGS
+=-fPIC
197 # windows : libtcc.dll
198 libtcc.dll
: $(LIBTCC_OBJ
) tiny_impdef
$(EXESUF
)
199 $(CC
) -shared
$(LIBTCC_OBJ
) -o
$@
$(LDFLAGS
)
202 libtcc.dll
: NATIVE_DEFINES
+= -DLIBTCC_AS_DLL
204 # windows : utilities
205 tiny_
%$(EXESUF
): $(TOPSRC
)/win32
/tools
/tiny_
%.c
206 $(CC
) -o
$@
$< $(CFLAGS
) $(LDFLAGS
) $(NATIVE_DEFINES
)
209 # TinyCC runtime libraries
210 $(LIBTCC1
) : FORCE
$(PROGS
)
211 $(MAKE
) -C lib native
214 lib
/%/libtcc1.a
: FORCE
$(PROGS_CROSS
)
215 $(MAKE
) -C lib cross TARGET
=$*
221 INSTALLBIN
= install $(STRIP_
$(STRIP_BINARIES
))
224 install-strip
: install
225 install-strip
: STRIP_BINARIES
= yes
230 $(INSTALLBIN
) -m755
$(PROGS
) "$(bindir)"
233 $(INSTALL
) -m644
$(LIBTCC1
) "$(tccdir)"
235 mkdir
-p
"$(tccdir)/include"
236 $(INSTALL
) -m644
$(TOPSRC
)/include/*.h
$(TOPSRC
)/tcclib.h
"$(tccdir)/include"
238 $(INSTALL
) -m644
$(LIBTCC
) "$(libdir)"
239 mkdir
-p
"$(includedir)"
240 $(INSTALL
) -m644
$(TOPSRC
)/libtcc.h
"$(includedir)"
242 mkdir
-p
"$(mandir)/man1"
243 -$(INSTALL
) -m644 tcc
.1 "$(mandir)/man1"
244 mkdir
-p
"$(infodir)"
245 -$(INSTALL
) -m644 tcc-doc.
info "$(infodir)"
247 -$(INSTALL
) -m644 tcc-doc.html
"$(docdir)"
249 mkdir
-p
"$(tccdir)/win32/lib/32"
250 mkdir
-p
"$(tccdir)/win32/lib/64"
251 $(INSTALL
) -m644
$(TOPSRC
)/win32
/lib
/*.def
"$(tccdir)/win32/lib"
252 -$(INSTALL
) -m644 lib
/i386-win32
/libtcc1.a
"$(tccdir)/win32/lib/32"
253 -$(INSTALL
) -m644 lib
/x86_64-win32
/libtcc1.a
"$(tccdir)/win32/lib/64"
254 cp
-r
$(TOPSRC
)/include/.
"$(tccdir)/win32/include"
255 cp
-r
$(TOPSRC
)/win32
/include/.
"$(tccdir)/win32/include"
259 rm -fv
$(foreach P
,$(PROGS
),"$(bindir)/$P")
260 rm -fv
"$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
261 rm -fv
"$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
262 rm -fv
"$(docdir)/tcc-doc.html"
268 mkdir
-p
"$(tccdir)/lib"
269 mkdir
-p
"$(tccdir)/include"
270 mkdir
-p
"$(tccdir)/examples"
271 mkdir
-p
"$(tccdir)/doc"
272 mkdir
-p
"$(tccdir)/libtcc"
273 $(INSTALLBIN
) -m755
$(PROGS
) "$(tccdir)"
274 $(INSTALL
) -m644 libtcc1.a
$(TOPSRC
)/win32
/lib
/*.def
"$(tccdir)/lib"
275 cp
-r
$(TOPSRC
)/win32
/include/.
"$(tccdir)/include"
276 cp
-r
$(TOPSRC
)/win32
/examples
/.
"$(tccdir)/examples"
277 cp
$(TOPSRC
)/tests
/libtcc_test.c
"$(tccdir)/examples"
278 $(INSTALL
) -m644
$(TOPSRC
)/include/*.h
$(TOPSRC
)/tcclib.h
"$(tccdir)/include"
279 $(INSTALL
) -m644 tcc-doc.html
$(TOPSRC
)/win32
/tcc-win32.txt
"$(tccdir)/doc"
280 $(INSTALL
) -m644
$(TOPSRC
)/libtcc.h libtcc.def
"$(tccdir)/libtcc"
282 mkdir
-p
"$(tccdir)/lib/32"
283 mkdir
-p
"$(tccdir)/lib/64"
284 -$(INSTALL
) -m644 lib
/i386-win32
/libtcc1.a
"$(tccdir)/lib/32"
285 -$(INSTALL
) -m644 lib
/x86_64-win32
/libtcc1.a
"$(tccdir)/lib/64"
289 rm -rfv
"$(tccdir)/"*
292 # documentation and man page
293 tcc-doc.html
: tcc-doc.texi
294 -makeinfo --no-split
--html
--number-sections
-o
$@
$<
297 -$(TOPSRC
)/texi2pod.pl
$< tcc.pod
298 -pod2man
--section
=1 --center
="Tiny C Compiler" --release
="$(VERSION)" tcc.pod
> $@
300 tcc-doc.
info: tcc-doc.texi
308 rm -f
$(PROGS
) tcc_p
$(EXESUF
) tcc.pod
*~
*.o
*.a
*.so
* *.out
*.log \
309 lib
*.def
*.exe
*.dll a.out
tags TAGS libtcc_test
$(EXESUF
) tcc
$(EXESUF
)
314 rm -f config.h config.mak config.texi tcc
.1 tcc-doc.
info tcc-doc.html
317 @echo
"Please run ./configure."
320 TAGFILES
= *.
[ch
] include/*.h lib
/*.
[chS
]
321 tags : ; ctags
$(TAGFILES
)
322 TAGS
: ; etags
$(TAGFILES
)
324 # create release tarball from *current* git branch (including tcc-doc.html
325 # and converting two files to CRLF)
326 TCC-VERSION
= $(VERSION
)
329 ( cd
$(TCC-VERSION
) && git
--git-dir ..
/.git checkout
-f
)
330 cp tcc-doc.html
$(TCC-VERSION
)
331 for f in tcc-win32.txt build-tcc.bat
; do \
332 cat win32
/$$f | sed
's,\(.*\),\1\r,g' > $(TCC-VERSION
)/win32
/$$f ; \
334 tar cjf
$(TCC-VERSION
).
tar.bz2
$(TCC-VERSION
)
335 rm -rf
$(TCC-VERSION
)
338 .PHONY
: all clean test tar tags TAGS
distclean install uninstall FORCE
340 endif # ifeq ($(TOP),.)