2 # Tiny C Compiler Makefile
6 include $(TOP
)/config.mak
9 CFLAGS_P
=$(CFLAGS
) -pg
-static
-DCONFIG_TCC_STATIC
12 ifneq ($(GCC_MAJOR
),2)
13 CFLAGS
+=-fno-strict-aliasing
14 ifneq ($(GCC_MAJOR
),3)
15 CFLAGS
+=-Wno-pointer-sign
-Wno-sign-compare
-D_FORTIFY_SOURCE
=0
20 CFLAGS
+=-mpreferred-stack-boundary
=2
22 CFLAGS
+=-m386
-malign-functions
=0
24 CFLAGS
+=-march
=i386
-falign-functions
=0
36 NATIVE_DEFINES
=-DTCC_TARGET_I386
39 ALLOCA_O
=alloca86.o alloca86-bt.o
42 NATIVE_DEFINES
=-DTCC_TARGET_X86_64
43 NATIVE_DEFINES
+=$(if
$(wildcard /lib64
/ld-linux-x86-64.so
.2),-DTCC_TARGET_X86_64_CENTOS
)
46 ALLOCA_O
=alloca86_64.o
51 NATIVE_DEFINES
=-DTCC_TARGET_ARM
52 NATIVE_TARGET
=-DWITHOUT_LIBTCC
53 NATIVE_DEFINES
+=$(if
$(wildcard /lib
/ld-linux.so
.3),-DTCC_ARM_EABI
)
54 NATIVE_DEFINES
+=$(if
$(shell grep
-l
"^Features.* \(vfp\|iwmmxt\) " /proc
/cpuinfo
),-DTCC_ARM_VFP
)
58 NATIVE_DEFINES
+=-DTCC_TARGET_PE
62 ifneq ($(wildcard /lib
/ld-uClibc.so
.0),)
63 NATIVE_DEFINES
+=-DTCC_UCLIBC
67 ifdef CONFIG_USE_LIBGCC
74 I386_CROSS
= i386-tcc
$(EXESUF
)
75 WIN32_CROSS
= i386-win32-tcc
$(EXESUF
)
76 WIN64_CROSS
= x86_64-win32-tcc
$(EXESUF
)
77 WINCE_CROSS
= arm-win32-tcc
$(EXESUF
)
78 X64_CROSS
= x86_64-tcc
$(EXESUF
)
79 ARM_FPA_CROSS
= arm-fpa-tcc
$(EXESUF
)
80 ARM_FPA_LD_CROSS
= arm-fpa-ld-tcc
$(EXESUF
)
81 ARM_VFP_CROSS
= arm-vfp-tcc
$(EXESUF
)
82 ARM_EABI_CROSS
= arm-eabi-tcc
$(EXESUF
)
83 ARM_CROSS
= $(ARM_FPA_CROSS
) $(ARM_FPA_LD_CROSS
) $(ARM_VFP_CROSS
) $(ARM_EABI_CROSS
)
84 C67_CROSS
= c67-tcc
$(EXESUF
)
86 CORE_FILES
= tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
87 CORE_FILES
+= tcc.h config.h libtcc.h tcctok.h
88 I386_FILES
= $(CORE_FILES
) i386-gen.c i386-asm.c i386-asm.h i386-tok.h
89 WIN32_FILES
= $(CORE_FILES
) i386-gen.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
90 WIN64_FILES
= $(CORE_FILES
) x86_64-gen.c i386-asm.c x86_64-asm.h tccpe.c
91 WINCE_FILES
= $(CORE_FILES
) arm-gen.c tccpe.c
92 X86_64_FILES
= $(CORE_FILES
) x86_64-gen.c i386-asm.c x86_64-asm.h
93 ARM_FILES
= $(CORE_FILES
) arm-gen.c
94 C67_FILES
= $(CORE_FILES
) c67-gen.c tcccoff.c
97 PROGS
+=tiny_impdef
$(EXESUF
) tiny_libmaker
$(EXESUF
)
98 NATIVE_FILES
=$(WIN32_FILES
)
99 PROGS_CROSS
=$(WIN64_CROSS
) $(I386_CROSS
) $(X64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
)
102 NATIVE_FILES
=$(I386_FILES
)
103 PROGS_CROSS
=$(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
)
105 ifeq ($(ARCH
),x86-64
)
106 NATIVE_FILES
=$(X86_64_FILES
)
107 PROGS_CROSS
=$(I386_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
)
110 NATIVE_FILES
=$(ARM_FILES
)
111 PROGS_CROSS
=$(I386_CROSS
) $(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(C67_CROSS
)
117 # LIBTCCB decides whether libtcc is installed static or dynamic
122 LIBTCCB
=libtcc.so
.1.0
124 LIBTCCLIBS
=$(LIBTCCB
)
127 PROGS
+=$(PROGS_CROSS
)
128 # Try to build win32 cross-compiler lib on *nix
134 all: $(PROGS
) $(LIBTCC1
) $(BCHECK_O
) $(LIBTCCLIBS
) tcc-doc.html tcc
.1 libtcc_test
$(EXESUF
)
136 # Host Tiny C Compiler
137 tcc
$(EXESUF
): tcc.o
$(LIBTCCB
)
138 $(CC
) -o
$@
$^
$(LIBS
) $(LIBTCCL
)
140 # Cross Tiny C Compilers
142 $(CC
) -o
$@ tcc.c
$(DEFINES
) $(CFLAGS
) $(LIBS
)
144 $(I386_CROSS
): DEFINES
= -DTCC_TARGET_I386
145 $(X64_CROSS
): DEFINES
= -DTCC_TARGET_X86_64
146 $(WIN32_CROSS
): DEFINES
= -DTCC_TARGET_I386
-DTCC_TARGET_PE
147 $(WIN64_CROSS
): DEFINES
= -DTCC_TARGET_X86_64
-DTCC_TARGET_PE
148 $(WINCE_CROSS
): DEFINES
= -DTCC_TARGET_PE
149 $(C67_CROSS
): DEFINES
= -DTCC_TARGET_C67
150 $(ARM_FPA_CROSS
): DEFINES
= -DTCC_TARGET_ARM
151 $(ARM_FPA_LD_CROSS
)$(EXESUF
): DEFINES
= -DTCC_TARGET_ARM
-DLDOUBLE_SIZE
=12
152 $(ARM_VFP_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_ARM_VFP
153 $(ARM_EABI_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_ARM_EABI
155 $(I386_CROSS
): $(I386_FILES
)
156 $(X64_CROSS
): $(X86_64_FILES
)
157 $(WIN32_CROSS
): $(WIN32_FILES
)
158 $(WIN64_CROSS
): $(WIN64_FILES
)
159 $(WINCE_CROSS
): $(WINCE_FILES
)
160 $(C67_CROSS
): $(C67_FILES
)
161 $(ARM_FPA_CROSS
) $(ARM_FPA_LD_CROSS
) $(ARM_VFP_CROSS
) $(ARM_EABI_CROSS
): $(ARM_FILES
)
163 # libtcc generation and test
165 LIBTCC_OBJ
= $(filter-out tcc.o
,$(patsubst %.c
,%.o
,$(filter %.c
,$(NATIVE_FILES
))))
166 LIBTCC_INC
= $(filter %.h
,$(CORE_FILES
)) $(filter-out $(CORE_FILES
),$(NATIVE_FILES
))
167 $(LIBTCC_OBJ
) tcc.o
: NATIVE_DEFINES
+= -DNOTALLINONE
169 LIBTCC_OBJ
= libtcc.o
170 LIBTCC_INC
= $(NATIVE_FILES
)
171 tcc.o
: NATIVE_DEFINES
+= -DNOTALLINONE
174 $(LIBTCC_OBJ
) tcc.o
: %.o
: %.c
$(LIBTCC_INC
)
175 $(CC
) -o
$@
-c
$< $(NATIVE_DEFINES
) $(CFLAGS
)
177 libtcc.a
: $(LIBTCC_OBJ
)
180 libtcc.so
.1.0: $(LIBTCC_OBJ
)
181 $(CC
) -shared
-Wl
,-soname
,$@
-o
$@
$^
182 ln
-sf libtcc.so
.1.0 libtcc.so
.1
183 ln
-sf libtcc.so
.1.0 libtcc.so
185 libtcc_test
$(EXESUF
): tests
/libtcc_test.c
$(LIBTCCB
)
186 $(CC
) -o
$@
$^
-I.
$(CFLAGS
) $(LIBS
) $(LIBTCCL
)
188 # To build cross-compilers on Linux we must make a fake 32 bit tcc.exe
189 # and use it to build ELF objects into libtcc1.a which is then
190 # renamed to tcc1.def in order to have another target in the Makefile
192 mv config.mak config.mak.bak
193 mv config.h config.h.bak
194 cp config.h.bak config.h
195 cp config.mak.bak config.mak
196 echo
"ARCH=i386" >> config.mak
197 echo
"#undef HOST_X86_64" >> config.h
198 echo
"#define HOST_I386 1" >> config.h
199 echo
"CFLAGS=-O2 -g -pipe -Wall -m32" >> config.mak
200 echo
"ARCH=i386" >> config.mak
201 $(MAKE
) i386-win32-tcc
202 cp i386-win32-tcc tcc.exe
203 mv libtcc1.a libtcc1.bak
204 $(MAKE
) CONFIG_WIN32
=1 libtcc1.a
205 mv libtcc1.a lib
/tcc1.def
206 mv libtcc1.bak libtcc1.a
207 mv config.mak.bak config.mak
208 mv config.h.bak config.h
210 libtest
: libtcc_test
$(EXESUF
) $(LIBTCC1
)
211 .
/libtcc_test
$(EXESUF
) lib_path
=.
214 tcc_p
$(EXESUF
): $(NATIVE_FILES
)
215 $(CC
) -o
$@
$< $(NATIVE_DEFINES
) $(CFLAGS_P
) $(LIBS_P
)
218 tiny_impdef
$(EXESUF
): win32
/tools
/tiny_impdef.c
219 $(CC
) -o
$@
$< $(CFLAGS
)
220 tiny_libmaker
$(EXESUF
): win32
/tools
/tiny_libmaker.c
221 $(CC
) -o
$@
$< $(CFLAGS
)
223 # TinyCC runtime libraries
224 LIBTCC1_OBJS
=libtcc1.o
$(ALLOCA_O
)
229 # for windows, we must use TCC because we generate ELF objects
230 LIBTCC1_OBJS
+=crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o bcheck.o
231 LIBTCC1_CC
=.
/tcc.exe
-Bwin32
-Iinclude
$(NATIVE_DEFINES
)
236 $(LIBTCC1_CC
) -o
$@
-c
$< -O2
-Wall
238 $(LIBTCC1_CC
) -o
$@
-c
$<
240 libtcc1.a
: $(LIBTCC1_OBJS
)
244 TCC_INCLUDES
= stdarg.h stddef.h stdbool.h float.h varargs.h tcclib.h
248 install: $(PROGS
) $(LIBTCC1
) $(BCHECK_O
) $(LIBTCCLIBS
) tcc
.1 tcc-doc.html
250 $(INSTALL
) -s
-m755
$(PROGS
) "$(bindir)"
251 mkdir
-p
"$(mandir)/man1"
252 $(INSTALL
) tcc
.1 "$(mandir)/man1"
254 mkdir
-p
"$(tccdir)/include"
256 $(INSTALL
) -m644
$(LIBTCC1
) "$(tccdir)"
259 $(INSTALL
) -m644
$(BCHECK_O
) "$(tccdir)"
261 $(INSTALL
) -m644
$(addprefix include/,$(TCC_INCLUDES
)) "$(tccdir)/include"
263 $(INSTALL
) -m755
$(LIBTCCB
) "$(libdir)"
265 ln
-sf
"$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so.1"
266 ln
-sf
"$(ln_libdir)/libtcc.so.1.0" "$(libdir)/libtcc.so"
268 mkdir
-p
"$(includedir)"
269 $(INSTALL
) -m644 libtcc.h
"$(includedir)"
271 $(INSTALL
) -m644 tcc-doc.html
"$(docdir)"
273 mkdir
-p
"$(tccdir)/lib"
274 $(INSTALL
) -m644 win32
/lib
/*.def lib
/tcc1.def
"$(tccdir)/lib"
275 cp
-r win32
/include/.
"$(tccdir)/include"
276 cp
-r win32
/examples
/.
"$(tccdir)/examples"
280 rm -fv
$(foreach P
,$(PROGS
),"$(bindir)/$P")
281 rm -fv
$(foreach P
,$(LIBTCC1
) $(BCHECK_O
),"$(tccdir)/$P")
282 rm -fv
$(foreach P
,$(TCC_INCLUDES
),"$(tccdir)/include/$P")
283 rm -fv
"$(docdir)/tcc-doc.html" "$(mandir)/man1/tcc.1"
284 rm -fv
"$(libdir)/$(LIBTCCB)" "$(includedir)/libtcc.h"
286 rm -fv
"$(libdir)/libtcc.so*"
289 rm -rf
"$(tccdir)/include"
290 rm -rf
"$(tccdir)/lib"
291 rm -rf
"$(tccdir)/examples"
294 install: $(PROGS
) $(LIBTCC1
) libtcc.a tcc-doc.html
296 mkdir
-p
"$(tccdir)/lib"
297 mkdir
-p
"$(tccdir)/include"
298 mkdir
-p
"$(tccdir)/examples"
299 mkdir
-p
"$(tccdir)/doc"
300 mkdir
-p
"$(tccdir)/libtcc"
301 $(INSTALL
) -s
-m755
$(PROGS
) "$(tccdir)"
302 $(INSTALL
) -m644
$(LIBTCC1
) win32
/lib
/*.def
"$(tccdir)/lib"
303 cp
-r win32
/include/.
"$(tccdir)/include"
304 cp
-r win32
/examples
/.
"$(tccdir)/examples"
305 $(INSTALL
) -m644
$(addprefix include/,$(TCC_INCLUDES
)) "$(tccdir)/include"
306 $(INSTALL
) -m644 tcc-doc.html win32
/tcc-win32.txt
"$(tccdir)/doc"
307 $(INSTALL
) -m644
$(LIBTCCB
) libtcc.h
"$(tccdir)/libtcc"
310 # documentation and man page
311 tcc-doc.html
: tcc-doc.texi
312 -texi2html
-monolithic
-number
$<
315 -.
/texi2pod.pl
$< tcc.pod
316 -pod2man
--section
=1 --center
=" " --release
=" " tcc.pod
> $@
318 # tar release (use 'make -k tar' on a checkouted tree)
319 TCC-VERSION
=tcc-
$(shell cat VERSION
)
321 rm -rf
/tmp
/$(TCC-VERSION
)
322 cp
-r .
/tmp
/$(TCC-VERSION
)
323 ( cd
/tmp
; tar zcvf ~
/$(TCC-VERSION
).
tar.gz
$(TCC-VERSION
) --exclude CVS
)
324 rm -rf
/tmp
/$(TCC-VERSION
)
331 rm -vf
$(PROGS
) tcc_p
$(EXESUF
) tcc.pod
*~
*.o
*.a
*.out
*.so
* *.exe libtcc_test
$(EXESUF
) lib
/tcc1.def
335 rm -vf config.h config.mak config.texi tcc
.1 tcc-doc.html
338 @echo Running configure ...
341 endif # ifeq ($(TOP),.)