2 # Tiny C Compiler Makefile
6 include $(TOP
)/config.mak
12 ifeq (-$(findstring gcc
,$(CC
))-,-gcc-
)
13 ifeq (-$(GCC_MAJOR
)-$(findstring $(GCC_MINOR
),56789)-,-4--)
14 CFLAGS
+= -D_FORTIFY_SOURCE
=0
17 ifeq (-$(findstring clang
,$(CC
))-,-clang-
)
18 # make clang accept gnuisms in libtcc1.c
19 CFLAGS
+=-fheinous-gnu-extensions
35 # make libtcc as static or dynamic library?
39 LINK_LIBTCC
+= -Wl
,-rpath
,"$(libdir)"
40 export LD_LIBRARY_PATH
:= $(CURDIR
)/$(TOP
)
45 ifeq ($(TARGETOS
),Darwin
)
46 CFLAGS
+= -Wl
,-flat_namespace
,-undefined
,warning
47 export MACOSX_DEPLOYMENT_TARGET
:=10.2
50 CFLAGS_P
= $(CFLAGS
) -pg
-static
-DCONFIG_TCC_STATIC
-DTCC_PROFILE
52 LDFLAGS_P
= $(LDFLAGS
)
55 NATIVE_DEFINES_
$(CONFIG_i386
) += -DTCC_TARGET_I386
56 NATIVE_DEFINES_
$(CONFIG_x86-64
) += -DTCC_TARGET_X86_64
57 NATIVE_DEFINES_
$(CONFIG_WIN32
) += -DTCC_TARGET_PE
58 NATIVE_DEFINES_
$(CONFIG_uClibc
) += -DTCC_UCLIBC
59 NATIVE_DEFINES_
$(CONFIG_arm
) += -DTCC_TARGET_ARM
60 NATIVE_DEFINES_
$(CONFIG_arm_eabihf
) += -DTCC_ARM_EABI
-DTCC_ARM_HARDFLOAT
61 NATIVE_DEFINES_
$(CONFIG_arm_eabi
) += -DTCC_ARM_EABI
62 NATIVE_DEFINES_
$(CONFIG_arm_vfp
) += -DTCC_ARM_VFP
63 NATIVE_DEFINES_
$(CONFIG_arm64
) += -DTCC_TARGET_ARM64
64 NATIVE_DEFINES
+= $(NATIVE_DEFINES_yes
)
69 I386_CROSS
= i386-tcc
$(EXESUF
)
70 WIN32_CROSS
= i386-win32-tcc
$(EXESUF
)
71 WIN64_CROSS
= x86_64-win32-tcc
$(EXESUF
)
72 WINCE_CROSS
= arm-wince-tcc
$(EXESUF
)
73 X64_CROSS
= x86_64-tcc
$(EXESUF
)
74 ARM_FPA_CROSS
= arm-fpa-tcc
$(EXESUF
)
75 ARM_FPA_LD_CROSS
= arm-fpa-ld-tcc
$(EXESUF
)
76 ARM_VFP_CROSS
= arm-vfp-tcc
$(EXESUF
)
77 ARM_EABI_CROSS
= arm-eabi-tcc
$(EXESUF
)
78 ARM_EABIHF_CROSS
= arm-eabihf-tcc
$(EXESUF
)
79 ARM_CROSS
= $(ARM_FPA_CROSS
) $(ARM_FPA_LD_CROSS
) $(ARM_VFP_CROSS
) $(ARM_EABI_CROSS
)
80 ARM64_CROSS
= arm64-tcc
$(EXESUF
)
81 C67_CROSS
= c67-tcc
$(EXESUF
)
83 CORE_FILES
= tcc.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
84 CORE_FILES
+= tcc.h config.h libtcc.h tcctok.h
85 I386_FILES
= $(CORE_FILES
) i386-gen.c i386-link.c i386-asm.c i386-asm.h i386-tok.h
86 WIN32_FILES
= $(CORE_FILES
) i386-gen.c i386-link.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
87 WIN64_FILES
= $(CORE_FILES
) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h tccpe.c
88 WINCE_FILES
= $(CORE_FILES
) arm-gen.c arm-link.c tccpe.c
89 X86_64_FILES
= $(CORE_FILES
) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h
90 ARM_FILES
= $(CORE_FILES
) arm-gen.c arm-link.c
91 ARM64_FILES
= $(CORE_FILES
) arm64-gen.c arm64-link.c
92 C67_FILES
= $(CORE_FILES
) c67-gen.c c67-link.c tcccoff.c
95 PROGS
+=tiny_impdef
$(EXESUF
) tiny_libmaker
$(EXESUF
) $(LIBTCC
)
97 NATIVE_FILES
=$(WIN64_FILES
)
98 PROGS_CROSS
=$(WIN32_CROSS
) $(X64_CROSS
) $(ARM_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
99 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a
101 NATIVE_FILES
=$(WIN32_FILES
)
102 PROGS_CROSS
=$(WIN64_CROSS
) $(X64_CROSS
) $(ARM_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
103 LIBTCC1_CROSS
=lib
/x86_64-win32
/libtcc1.a
106 else ifeq ($(ARCH
),i386
)
107 NATIVE_FILES
=$(I386_FILES
)
108 PROGS_CROSS
=$(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
109 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a lib
/x86_64-win32
/libtcc1.a
111 else ifeq ($(ARCH
),x86-64
)
112 NATIVE_FILES
=$(X86_64_FILES
)
113 PROGS_CROSS
=$(I386_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
114 LIBTCC1_CROSS
=lib
/i386-win32
/libtcc1.a lib
/x86_64-win32
/libtcc1.a
116 else ifeq ($(ARCH
),arm
)
117 NATIVE_FILES
=$(ARM_FILES
)
118 PROGS_CROSS
=$(I386_CROSS
) $(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM64_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
120 else ifeq ($(ARCH
),arm64
)
121 NATIVE_FILES
=$(ARM64_FILES
)
122 PROGS_CROSS
=$(I386_CROSS
) $(X64_CROSS
) $(WIN32_CROSS
) $(WIN64_CROSS
) $(ARM_CROSS
) $(C67_CROSS
) $(WINCE_CROSS
)
125 ifeq ($(TARGETOS
),Darwin
)
126 PROGS
+= tiny_libmaker
$(EXESUF
)
129 TCCLIBS
= $(LIBTCC1
) $(LIBTCC
)
130 TCCDOCS
= tcc
.1 tcc-doc.html tcc-doc.
info
133 PROGS
+= $(PROGS_CROSS
)
134 TCCLIBS
+= $(LIBTCC1_CROSS
)
137 all: $(PROGS
) $(TCCLIBS
) $(TCCDOCS
)
139 # Host Tiny C Compiler
140 tcc
$(EXESUF
): tcc.o
$(LIBTCC
)
141 $(CC
) -o
$@
$^
$(CFLAGS
) $(LDFLAGS
) $(LIBS
) $(LINK_LIBTCC
)
143 # Cross Tiny C Compilers
144 %-tcc
$(EXESUF
): tcc.c
145 $(CC
) -o
$@
$< -DONE_SOURCE
$(DEFINES
) $(CFLAGS
) $(LIBS
) $(LDFLAGS
)
148 tcc_p
$(EXESUF
): $(NATIVE_FILES
)
149 $(CC
) -o
$@
$< -DONE_SOURCE
$(NATIVE_DEFINES
) $(CPPFLAGS_P
) $(CFLAGS_P
) $(LIBS_P
) $(LDFLAGS_P
)
151 $(I386_CROSS
): DEFINES
= -DTCC_TARGET_I386 \
152 -DCONFIG_TCCDIR
="\"$(tccdir)/i386\""
153 $(X64_CROSS
) : DEFINES
= -DTCC_TARGET_X86_64
154 -DCONFIG_TCCDIR
="\"$(tccdir)/x86_64\""
155 $(WIN32_CROSS
) : DEFINES
= -DTCC_TARGET_I386
-DTCC_TARGET_PE \
156 -DCONFIG_TCCDIR
="\"$(tccdir)/win32\"" \
157 -DCONFIG_TCC_LIBPATHS
="\"{B}/lib/32;{B}/lib\""
158 $(WIN64_CROSS
) : DEFINES
= -DTCC_TARGET_X86_64
-DTCC_TARGET_PE \
159 -DCONFIG_TCCDIR
="\"$(tccdir)/win32\"" \
160 -DCONFIG_TCC_LIBPATHS
="\"{B}/lib/64;{B}/lib\""
161 $(WINCE_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_TARGET_PE
162 $(C67_CROSS
): DEFINES
= -DTCC_TARGET_C67
-w
# disable warnigs
163 $(ARM_FPA_CROSS
): DEFINES
= -DTCC_TARGET_ARM
164 $(ARM_FPA_LD_CROSS
)$(EXESUF
): DEFINES
= -DTCC_TARGET_ARM
-DLDOUBLE_SIZE
=12
165 $(ARM_VFP_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_ARM_VFP
166 $(ARM_EABI_CROSS
): DEFINES
= -DTCC_TARGET_ARM
-DTCC_ARM_EABI
-DTCC_ARM_VFP
167 $(ARM64_CROSS
): DEFINES
= -DTCC_TARGET_ARM64
169 $(I386_CROSS
) : $(I386_FILES
)
170 $(X64_CROSS
) : $(X86_64_FILES
)
171 $(WIN32_CROSS
) : $(WIN32_FILES
)
172 $(WIN64_CROSS
) : $(WIN64_FILES
)
173 $(WINCE_CROSS
) : $(WINCE_FILES
)
174 $(C67_CROSS
) : $(C67_FILES
)
175 $(ARM_FPA_CROSS
) $(ARM_FPA_LD_CROSS
) $(ARM_VFP_CROSS
) $(ARM_EABI_CROSS
): $(ARM_FILES
)
176 $(ARM64_CROSS
): $(ARM64_FILES
)
178 # libtcc generation and test
180 LIBTCC_OBJ
= $(filter-out tcc.o
,$(patsubst %.c
,%.o
,$(filter %.c
,$(NATIVE_FILES
))))
181 LIBTCC_INC
= $(filter %.h
,$(CORE_FILES
)) $(filter-out $(CORE_FILES
) i386-asm.c
,$(NATIVE_FILES
))
183 LIBTCC_OBJ
= libtcc.o
184 LIBTCC_INC
= $(NATIVE_FILES
)
185 libtcc.o
: NATIVE_DEFINES
+= -DONE_SOURCE
188 $(LIBTCC_OBJ
) tcc.o
: %.o
: %.c
$(LIBTCC_INC
)
189 $(CC
) -o
$@
-c
$< $(NATIVE_DEFINES
) $(CFLAGS
)
191 libtcc.a
: $(LIBTCC_OBJ
)
194 libtcc.so
: $(LIBTCC_OBJ
)
195 $(CC
) -shared
-Wl
,-soname
,$@
-o
$@
$^
$(LDFLAGS
)
197 libtcc.so
: CFLAGS
+=-fPIC
199 # windows : libtcc.dll
200 libtcc.dll
: $(LIBTCC_OBJ
) tiny_impdef
$(EXESUF
)
201 $(CC
) -shared
$(LIBTCC_OBJ
) -o
$@
$(LDFLAGS
)
204 libtcc.dll
: NATIVE_DEFINES
+= -DLIBTCC_AS_DLL
206 # windows : utilities
207 tiny_
%$(EXESUF
): $(TOPSRC
)/win32
/tools
/tiny_
%.c
208 $(CC
) -o
$@
$< $(CFLAGS
) $(LDFLAGS
) $(NATIVE_DEFINES
)
211 # TinyCC runtime libraries
212 $(LIBTCC1
) : FORCE
$(PROGS
)
213 $(MAKE
) -C lib native
216 lib
/%/libtcc1.a
: FORCE
$(PROGS_CROSS
)
217 $(MAKE
) -C lib cross TARGET
=$*
223 INSTALLBIN
= install $(STRIP_
$(STRIP_BINARIES
))
226 install-strip
: install
227 install-strip
: STRIP_BINARIES
= yes
232 $(INSTALLBIN
) -m755
$(PROGS
) "$(bindir)"
235 $(INSTALL
) -m644
$(LIBTCC1
) "$(tccdir)"
237 mkdir
-p
"$(tccdir)/include"
238 $(INSTALL
) -m644
$(TOPSRC
)/include/*.h
$(TOPSRC
)/tcclib.h
"$(tccdir)/include"
240 $(INSTALL
) -m644
$(LIBTCC
) "$(libdir)"
241 mkdir
-p
"$(includedir)"
242 $(INSTALL
) -m644
$(TOPSRC
)/libtcc.h
"$(includedir)"
244 mkdir
-p
"$(mandir)/man1"
245 -$(INSTALL
) -m644 tcc
.1 "$(mandir)/man1"
246 mkdir
-p
"$(infodir)"
247 -$(INSTALL
) -m644 tcc-doc.
info "$(infodir)"
249 -$(INSTALL
) -m644 tcc-doc.html
"$(docdir)"
251 mkdir
-p
"$(tccdir)/win32/lib/32"
252 mkdir
-p
"$(tccdir)/win32/lib/64"
253 $(INSTALL
) -m644
$(TOPSRC
)/win32
/lib
/*.def
"$(tccdir)/win32/lib"
254 -$(INSTALL
) -m644 lib
/i386-win32
/libtcc1.a
"$(tccdir)/win32/lib/32"
255 -$(INSTALL
) -m644 lib
/x86_64-win32
/libtcc1.a
"$(tccdir)/win32/lib/64"
256 cp
-r
$(TOPSRC
)/include/.
"$(tccdir)/win32/include"
257 cp
-r
$(TOPSRC
)/win32
/include/.
"$(tccdir)/win32/include"
261 rm -fv
$(foreach P
,$(PROGS
),"$(bindir)/$P")
262 rm -fv
"$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
263 rm -fv
"$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
264 rm -fv
"$(docdir)/tcc-doc.html"
270 mkdir
-p
"$(tccdir)/lib"
271 mkdir
-p
"$(tccdir)/include"
272 mkdir
-p
"$(tccdir)/examples"
273 mkdir
-p
"$(tccdir)/doc"
274 mkdir
-p
"$(tccdir)/libtcc"
275 $(INSTALLBIN
) -m755
$(PROGS
) "$(tccdir)"
276 $(INSTALL
) -m644 libtcc1.a
$(TOPSRC
)/win32
/lib
/*.def
"$(tccdir)/lib"
277 cp
-r
$(TOPSRC
)/win32
/include/.
"$(tccdir)/include"
278 cp
-r
$(TOPSRC
)/win32
/examples
/.
"$(tccdir)/examples"
279 cp
$(TOPSRC
)/tests
/libtcc_test.c
"$(tccdir)/examples"
280 $(INSTALL
) -m644
$(TOPSRC
)/include/*.h
$(TOPSRC
)/tcclib.h
"$(tccdir)/include"
281 $(INSTALL
) -m644 tcc-doc.html
$(TOPSRC
)/win32
/tcc-win32.txt
"$(tccdir)/doc"
282 $(INSTALL
) -m644
$(TOPSRC
)/libtcc.h libtcc.def
"$(tccdir)/libtcc"
284 mkdir
-p
"$(tccdir)/lib/32"
285 mkdir
-p
"$(tccdir)/lib/64"
286 -$(INSTALL
) -m644 lib
/i386-win32
/libtcc1.a
"$(tccdir)/lib/32"
287 -$(INSTALL
) -m644 lib
/x86_64-win32
/libtcc1.a
"$(tccdir)/lib/64"
291 rm -rfv
"$(tccdir)/"*
294 # documentation and man page
295 tcc-doc.html
: tcc-doc.texi
296 -makeinfo --no-split
--html
--number-sections
-o
$@
$<
299 -$(TOPSRC
)/texi2pod.pl
$< tcc.pod
300 -pod2man
--section
=1 --center
="Tiny C Compiler" --release
="$(VERSION)" tcc.pod
> $@
302 tcc-doc.
info: tcc-doc.texi
310 rm -f
$(PROGS
) tcc_p
$(EXESUF
) tcc.pod
*~
*.o
*.a
*.so
* *.out
*.log \
311 lib
*.def
*.exe
*.dll a.out
tags TAGS libtcc_test
$(EXESUF
) tcc
$(EXESUF
)
316 rm -f config.h config.mak config.texi tcc
.1 tcc-doc.
info tcc-doc.html
319 @echo
"Please run ./configure."
322 TAGFILES
= *.
[ch
] include/*.h lib
/*.
[chS
]
323 tags : ; ctags
$(TAGFILES
)
324 TAGS
: ; etags
$(TAGFILES
)
326 # create release tarball from *current* git branch (including tcc-doc.html
327 # and converting two files to CRLF)
328 TCC-VERSION
= $(VERSION
)
331 ( cd
$(TCC-VERSION
) && git
--git-dir ..
/.git checkout
-f
)
332 cp tcc-doc.html
$(TCC-VERSION
)
333 for f in tcc-win32.txt build-tcc.bat
; do \
334 cat win32
/$$f | sed
's,\(.*\),\1\r,g' > $(TCC-VERSION
)/win32
/$$f ; \
336 tar cjf
$(TCC-VERSION
).
tar.bz2
$(TCC-VERSION
)
337 rm -rf
$(TCC-VERSION
)
340 .PHONY
: all clean test tar tags TAGS
distclean install uninstall FORCE
342 endif # ifeq ($(TOP),.)