riscv64 elf flags should be configurable
[tinycc.git] / Makefile
blob98d65f67b7abaf614bfcf7f3f8e280b160a380a1
1 # --------------------------------------------------------------------------
3 # Tiny C Compiler Makefile
6 ifndef TOP
7 TOP = .
8 INCLUDED = no
9 endif
11 ifeq ($(findstring $(MAKECMDGOALS),clean distclean),)
12 include $(TOP)/config.mak
13 endif
15 ifeq (-$(GCC_MAJOR)-$(findstring $(GCC_MINOR),56789)-,-4--)
16 CFLAGS += -D_FORTIFY_SOURCE=0
17 endif
19 LIBTCC = libtcc.a
20 LIBTCC1 = libtcc1.a
21 LINK_LIBTCC =
22 LIBS =
23 CFLAGS += -I$(TOP)
24 CFLAGS += $(CPPFLAGS)
25 VPATH = $(TOPSRC)
27 ifdef CONFIG_WIN32
28 CFG = -win
29 ifneq ($(CONFIG_static),yes)
30 LIBTCC = libtcc$(DLLSUF)
31 LIBTCCDEF = libtcc.def
32 endif
33 ifneq ($(CONFIG_debug),yes)
34 LDFLAGS += -s
35 endif
36 NATIVE_TARGET = $(ARCH)-win$(if $(findstring arm,$(ARCH)),ce,32)
37 else
38 CFG = -unx
39 LIBS+=-lm
40 ifneq ($(CONFIG_ldl),no)
41 LIBS+=-ldl
42 endif
43 ifneq ($(CONFIG_pthread),no)
44 LIBS+=-lpthread
45 endif
46 # make libtcc as static or dynamic library?
47 ifeq ($(CONFIG_static),no)
48 LIBTCC=libtcc$(DLLSUF)
49 export LD_LIBRARY_PATH := $(CURDIR)/$(TOP)
50 ifneq ($(CONFIG_rpath),no)
51 ifndef CONFIG_OSX
52 LINK_LIBTCC += -Wl,-rpath,"$(libdir)"
53 else
54 # macOS doesn't support env-vars libdir out of the box - which we need for
55 # `make test' when libtcc.dylib is used (configure --disable-static), so
56 # we bake a relative path into the binary. $libdir is used after install.
57 LINK_LIBTCC += -Wl,-rpath,"@executable_path/$(TOP)" -Wl,-rpath,"$(libdir)"
58 DYLIBVER += -current_version $(MACOS_DYLIB_VERSION)
59 DYLIBVER += -compatibility_version $(MACOS_DYLIB_VERSION)
60 endif
61 endif
62 endif
63 NATIVE_TARGET = $(ARCH)
64 ifdef CONFIG_OSX
65 NATIVE_TARGET = $(ARCH)-osx
66 ifneq ($(CC_NAME),tcc)
67 LDFLAGS += -flat_namespace -undefined warning
68 endif
69 export MACOSX_DEPLOYMENT_TARGET := 10.6
70 endif
71 endif
73 # run local version of tcc with local libraries and includes
74 TCCFLAGS-unx = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP)
75 TCCFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP)
76 TCCFLAGS = $(TCCFLAGS$(CFG))
77 TCC_LOCAL = $(TOP)/tcc$(EXESUF)
78 TCC = $(TCC_LOCAL) $(TCCFLAGS)
80 CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC -DTCC_PROFILE
81 LIBS_P = $(LIBS)
82 LDFLAGS_P = $(LDFLAGS)
84 CONFIG_$(ARCH) = yes
85 NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
86 NATIVE_DEFINES_$(CONFIG_x86_64) += -DTCC_TARGET_X86_64
87 NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE
88 NATIVE_DEFINES_$(CONFIG_OSX) += -DTCC_TARGET_MACHO
89 NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC
90 NATIVE_DEFINES_$(CONFIG_musl) += -DTCC_MUSL
91 NATIVE_DEFINES_$(CONFIG_libgcc) += -DCONFIG_USE_LIBGCC
92 NATIVE_DEFINES_$(CONFIG_selinux) += -DHAVE_SELINUX
93 NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM
94 NATIVE_DEFINES_$(CONFIG_arm_eabihf) += -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT
95 NATIVE_DEFINES_$(CONFIG_arm_eabi) += -DTCC_ARM_EABI
96 NATIVE_DEFINES_$(CONFIG_arm_vfp) += -DTCC_ARM_VFP
97 NATIVE_DEFINES_$(CONFIG_arm64) += -DTCC_TARGET_ARM64
98 NATIVE_DEFINES_$(CONFIG_riscv64) += -DTCC_TARGET_RISCV64
99 NATIVE_DEFINES_$(CONFIG_BSD) += -DTARGETOS_$(TARGETOS)
100 NATIVE_DEFINES_$(CONFIG_Android) += -DTARGETOS_ANDROID
101 NATIVE_DEFINES_$(CONFIG_pie) += -DCONFIG_TCC_PIE
102 NATIVE_DEFINES_$(CONFIG_pic) += -DCONFIG_TCC_PIC
103 NATIVE_DEFINES_no_$(CONFIG_new_macho) += -DCONFIG_NEW_MACHO=0
104 NATIVE_DEFINES_$(CONFIG_codesign) += -DCONFIG_CODESIGN
105 NATIVE_DEFINES_$(CONFIG_new-dtags) += -DCONFIG_NEW_DTAGS
106 NATIVE_DEFINES_no_$(CONFIG_bcheck) += -DCONFIG_TCC_BCHECK=0
107 NATIVE_DEFINES_no_$(CONFIG_backtrace) += -DCONFIG_TCC_BACKTRACE=0
108 NATIVE_DEFINES += $(NATIVE_DEFINES_yes) $(NATIVE_DEFINES_no_no)
110 DEF-i386 = -DTCC_TARGET_I386
111 DEF-i386-win32 = -DTCC_TARGET_I386 -DTCC_TARGET_PE
112 DEF-i386-OpenBSD = $(DEF-i386) -DTARGETOS_OpenBSD
113 DEF-x86_64 = -DTCC_TARGET_X86_64
114 DEF-x86_64-win32 = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE
115 DEF-x86_64-osx = -DTCC_TARGET_X86_64 -DTCC_TARGET_MACHO
116 DEF-arm-fpa = -DTCC_TARGET_ARM
117 DEF-arm-fpa-ld = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
118 DEF-arm-vfp = -DTCC_TARGET_ARM -DTCC_ARM_VFP
119 DEF-arm-eabi = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DTCC_ARM_EABI
120 DEF-arm-eabihf = $(DEF-arm-eabi) -DTCC_ARM_HARDFLOAT
121 DEF-arm = $(DEF-arm-eabihf)
122 DEF-arm-NetBSD = $(DEF-arm-eabihf) -DTARGETOS_NetBSD
123 DEF-arm-wince = $(DEF-arm-eabihf) -DTCC_TARGET_PE
124 DEF-arm64 = -DTCC_TARGET_ARM64
125 DEF-arm64-osx = $(DEF-arm64) -DTCC_TARGET_MACHO
126 DEF-arm64-FreeBSD = $(DEF-arm64) -DTARGETOS_FreeBSD
127 DEF-arm64-NetBSD = $(DEF-arm64) -DTARGETOS_NetBSD
128 DEF-arm64-OpenBSD = $(DEF-arm64) -DTARGETOS_OpenBSD
129 DEF-riscv64 = -DTCC_TARGET_RISCV64
130 DEF-c67 = -DTCC_TARGET_C67 -w # disable warnigs
131 DEF-x86_64-FreeBSD = $(DEF-x86_64) -DTARGETOS_FreeBSD
132 DEF-x86_64-NetBSD = $(DEF-x86_64) -DTARGETOS_NetBSD
133 DEF-x86_64-OpenBSD = $(DEF-x86_64) -DTARGETOS_OpenBSD
135 DEF-$(NATIVE_TARGET) = $(NATIVE_DEFINES)
137 ifeq ($(INCLUDED),no)
138 # --------------------------------------------------------------------------
139 # running top Makefile
141 PROGS = tcc$(EXESUF)
142 TCCLIBS = $(LIBTCCDEF) $(LIBTCC) $(LIBTCC1)
143 TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info
145 all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
147 # cross compiler targets to build
148 TCC_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince c67
149 TCC_X += riscv64 arm64-osx
150 # TCC_X += arm-fpa arm-fpa-ld arm-vfp arm-eabi
152 # cross libtcc1.a targets to build
153 LIBTCC1_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince
154 LIBTCC1_X += riscv64 arm64-osx
156 PROGS_CROSS = $(foreach X,$(TCC_X),$X-tcc$(EXESUF))
157 LIBTCC1_CROSS = $(foreach X,$(LIBTCC1_X),$X-libtcc1.a)
159 # build cross compilers & libs
160 cross: $(LIBTCC1_CROSS) $(PROGS_CROSS)
162 # build specific cross compiler & lib
163 cross-%: %-tcc$(EXESUF) %-libtcc1.a ;
165 install: ; @$(MAKE) --no-print-directory install$(CFG)
166 install-strip: ; @$(MAKE) --no-print-directory install$(CFG) CONFIG_strip=yes
167 uninstall: ; @$(MAKE) --no-print-directory uninstall$(CFG)
169 ifdef CONFIG_cross
170 all : cross
171 endif
173 # --------------------------------------------
175 T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown)
176 X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-)
178 DEFINES += $(DEF-$T) $(DEF-all)
179 DEFINES += $(if $(ROOT-$T),-DCONFIG_SYSROOT="\"$(ROOT-$T)\"")
180 DEFINES += $(if $(CRT-$T),-DCONFIG_TCC_CRTPREFIX="\"$(CRT-$T)\"")
181 DEFINES += $(if $(LIB-$T),-DCONFIG_TCC_LIBPATHS="\"$(LIB-$T)\"")
182 DEFINES += $(if $(INC-$T),-DCONFIG_TCC_SYSINCLUDEPATHS="\"$(INC-$T)\"")
183 DEFINES += $(if $(ELF-$T),-DCONFIG_TCC_ELFINTERP="\"$(ELF-$T)\"")
184 DEFINES += $(DEF-$(or $(findstring win,$T),unx))
186 ifneq ($(X),)
187 DEF-all += -DCONFIG_TCC_CROSSPREFIX="\"$X\""
188 ifneq ($(CONFIG_WIN32),yes)
189 DEF-win += -DCONFIG_TCCDIR="\"$(tccdir)/win32\""
190 endif
191 endif
193 # include custom configuration (see make help)
194 -include config-extra.mak
196 ifneq ($(X),)
197 ifneq ($(T),$(NATIVE_TARGET))
198 # assume support files for cross-targets in "/usr/<triplet>" by default
199 TRIPLET-i386 ?= i686-linux-gnu
200 TRIPLET-x86_64 ?= x86_64-linux-gnu
201 TRIPLET-arm ?= arm-linux-gnueabi
202 TRIPLET-arm64 ?= aarch64-linux-gnu
203 TRIPLET-riscv64 ?= riscv64-linux-gnu
204 TR = $(if $(TRIPLET-$T),$T,ignored)
205 CRT-$(TR) ?= /usr/$(TRIPLET-$T)/lib
206 LIB-$(TR) ?= {B}:/usr/$(TRIPLET-$T)/lib
207 INC-$(TR) ?= {B}/include:/usr/$(TRIPLET-$T)/include
208 endif
209 endif
211 CORE_FILES = tcc.c tcctools.c libtcc.c tccpp.c tccgen.c tccdbg.c tccelf.c tccasm.c tccrun.c
212 CORE_FILES += tcc.h config.h libtcc.h tcctok.h
213 i386_FILES = $(CORE_FILES) i386-gen.c i386-link.c i386-asm.c i386-asm.h i386-tok.h
214 i386-win32_FILES = $(i386_FILES) tccpe.c
215 x86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h
216 x86_64-win32_FILES = $(x86_64_FILES) tccpe.c
217 x86_64-osx_FILES = $(x86_64_FILES) tccmacho.c
218 arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c arm-tok.h
219 arm-wince_FILES = $(arm_FILES) tccpe.c
220 arm-eabihf_FILES = $(arm_FILES)
221 arm-fpa_FILES = $(arm_FILES)
222 arm-fpa-ld_FILES = $(arm_FILES)
223 arm-vfp_FILES = $(arm_FILES)
224 arm-eabi_FILES = $(arm_FILES)
225 arm-eabihf_FILES = $(arm_FILES)
226 arm64_FILES = $(CORE_FILES) arm64-gen.c arm64-link.c arm64-asm.c
227 arm64-osx_FILES = $(arm64_FILES) tccmacho.c
228 c67_FILES = $(CORE_FILES) c67-gen.c c67-link.c tcccoff.c
229 riscv64_FILES = $(CORE_FILES) riscv64-gen.c riscv64-link.c riscv64-asm.c
231 TCCDEFS_H$(subst yes,,$(CONFIG_predefs)) = tccdefs_.h
233 # libtcc sources
234 LIBTCC_SRC = $(filter-out tcc.c tcctools.c,$(filter %.c,$($T_FILES)))
236 ifeq ($(ONE_SOURCE),yes)
237 LIBTCC_OBJ = $(X)libtcc.o
238 LIBTCC_INC = $($T_FILES)
239 TCC_FILES = $(X)tcc.o
240 tcc.o : DEFINES += -DONE_SOURCE=0
241 $(X)tcc.o $(X)libtcc.o : $(TCCDEFS_H)
242 else
243 LIBTCC_OBJ = $(patsubst %.c,$(X)%.o,$(LIBTCC_SRC))
244 LIBTCC_INC = $(filter %.h %-gen.c %-link.c,$($T_FILES))
245 TCC_FILES = $(X)tcc.o $(LIBTCC_OBJ)
246 $(TCC_FILES) : DEFINES += -DONE_SOURCE=0
247 $(X)tccpp.o : $(TCCDEFS_H)
248 endif
250 GITHASH:=$(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo no)
251 ifneq ($(GITHASH),no)
252 GITHASH:=$(shell git log -1 --date=short --pretty='format:%cd $(GITHASH)@%h')
253 GITMODF:=$(shell git diff --quiet || echo '*')
254 DEF_GITHASH:= -DTCC_GITHASH="\"$(GITHASH)$(GITMODF)\""
255 endif
257 ifeq ($(CONFIG_debug),yes)
258 CFLAGS += -g
259 LDFLAGS += -g
260 endif
262 # convert "include/tccdefs.h" to "tccdefs_.h"
263 %_.h : include/%.h conftest.c
264 $S$(CC) -DC2STR $(filter %.c,$^) -o c2str.exe && ./c2str.exe $< $@
266 # target specific object rule
267 $(X)%.o : %.c $(LIBTCC_INC)
268 $S$(CC) -o $@ -c $< $(DEFINES) $(CFLAGS)
270 # additional dependencies
271 $(X)tcc.o : tcctools.c
272 $(X)tcc.o : DEFINES += $(DEF_GITHASH)
274 # Host Tiny C Compiler
275 tcc$(EXESUF): tcc.o $(LIBTCC)
276 $S$(CC) -o $@ $^ $(LIBS) $(LDFLAGS) $(LINK_LIBTCC)
278 # Cross Tiny C Compilers
279 # (the TCCDEFS_H dependency is only necessary for parallel makes,
280 # ala 'make -j x86_64-tcc i386-tcc tcc', which would create multiple
281 # c2str.exe and tccdefs_.h files in parallel, leading to access errors.
282 # This forces it to be made only once. Make normally tracks multiple paths
283 # to the same goals and only remakes it once, but that doesn't work over
284 # sub-makes like in this target)
285 %-tcc$(EXESUF): $(TCCDEFS_H) FORCE
286 @$(MAKE) --no-print-directory $@ CROSS_TARGET=$* ONE_SOURCE=$(or $(ONE_SOURCE),yes)
288 $(CROSS_TARGET)-tcc$(EXESUF): $(TCC_FILES)
289 $S$(CC) -o $@ $^ $(LIBS) $(LDFLAGS)
291 # profiling version
292 tcc_p$(EXESUF): $($T_FILES)
293 $S$(CC) -o $@ $< $(DEFINES) $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P)
295 # static libtcc library
296 libtcc.a: $(LIBTCC_OBJ)
297 $S$(AR) rcs $@ $^
299 # dynamic libtcc library
300 libtcc.so: $(LIBTCC_OBJ)
301 $S$(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LIBS) $(LDFLAGS)
303 libtcc.so: CFLAGS+=-fPIC
304 libtcc.so: LDFLAGS+=-fPIC
306 # OSX dynamic libtcc library
307 libtcc.dylib: $(LIBTCC_OBJ)
308 $S$(CC) -dynamiclib $(DYLIBVER) -install_name @rpath/$@ -o $@ $^ $(LDFLAGS)
310 # OSX libtcc.dylib (without rpath/ prefix)
311 libtcc.osx: $(LIBTCC_OBJ)
312 $S$(CC) -shared -install_name libtcc.dylib -o libtcc.dylib $^ $(LDFLAGS)
314 # windows dynamic libtcc library
315 libtcc.dll : $(LIBTCC_OBJ)
316 $S$(CC) -shared -o $@ $^ $(LDFLAGS)
317 libtcc.dll : DEFINES += -DLIBTCC_AS_DLL
319 # import file for windows libtcc.dll
320 libtcc.def : libtcc.dll tcc$(EXESUF)
321 $S$(XTCC) -impdef $< -o $@
322 XTCC ?= ./tcc$(EXESUF)
324 # TinyCC runtime libraries
325 libtcc1.a : tcc$(EXESUF) FORCE
326 @$(MAKE) -C lib
328 # Cross libtcc1.a
329 %-libtcc1.a : %-tcc$(EXESUF) FORCE
330 @$(MAKE) -C lib CROSS_TARGET=$*
332 .PRECIOUS: %-libtcc1.a
333 FORCE:
335 # WHICH = which $1 2>/dev/null
336 # some versions of gnu-make do not recognize 'command' as a shell builtin
337 WHICH = sh -c 'command -v $1'
339 run-if = $(if $(shell $(call WHICH,$1)),$S $1 $2)
340 S = $(if $(findstring yes,$(SILENT)),@$(info * $@))
342 # --------------------------------------------------------------------------
343 # documentation and man page
344 tcc-doc.html: tcc-doc.texi
345 $(call run-if,makeinfo,--no-split --html --number-sections -o $@ $<)
347 tcc-doc.info: tcc-doc.texi
348 $(call run-if,makeinfo,$< || true)
350 tcc.1 : tcc-doc.pod
351 $(call run-if,pod2man,--section=1 --center="Tiny C Compiler" \
352 --release="$(VERSION)" $< >$@)
353 %.pod : %.texi
354 $(call run-if,perl,$(TOPSRC)/texi2pod.pl $< $@)
356 doc : $(TCCDOCS)
358 # --------------------------------------------------------------------------
359 # install
361 INSTALL = install -m644
362 INSTALLBIN = install -m755 $(STRIP_$(CONFIG_strip))
363 STRIP_yes = -s
365 LIBTCC1_W = $(filter %-win32-libtcc1.a %-wince-libtcc1.a,$(LIBTCC1_CROSS))
366 LIBTCC1_U = $(filter-out $(LIBTCC1_W),$(wildcard *-libtcc1.a))
367 IB = $(if $1,$(IM) mkdir -p $2 && $(INSTALLBIN) $1 $2)
368 IBw = $(call IB,$(wildcard $1),$2)
369 IF = $(if $1,$(IM) mkdir -p $2 && $(INSTALL) $1 $2)
370 IFw = $(call IF,$(wildcard $1),$2)
371 IR = $(IM) mkdir -p $2 && cp -r $1/. $2
372 IM = @echo "-> $2 : $1" ;
373 BINCHECK = $(if $(wildcard $(PROGS) *-tcc$(EXESUF)),,@echo "Makefile: nothing found to install" && exit 1)
375 B_O = bcheck.o bt-exe.o bt-log.o bt-dll.o
377 # install progs & libs
378 install-unx:
379 $(call BINCHECK)
380 $(call IBw,$(PROGS) *-tcc,"$(bindir)")
381 $(call IFw,$(LIBTCC1) $(B_O) $(LIBTCC1_U),"$(tccdir)")
382 $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/include")
383 $(call $(if $(findstring .so,$(LIBTCC)),IBw,IFw),$(LIBTCC),"$(libdir)")
384 $(call IF,$(TOPSRC)/libtcc.h,"$(includedir)")
385 $(call IFw,tcc.1,"$(mandir)/man1")
386 $(call IFw,tcc-doc.info,"$(infodir)")
387 $(call IFw,tcc-doc.html,"$(docdir)")
388 ifneq "$(wildcard $(LIBTCC1_W))" ""
389 $(call IFw,$(TOPSRC)/win32/lib/*.def $(LIBTCC1_W),"$(tccdir)/win32/lib")
390 $(call IR,$(TOPSRC)/win32/include,"$(tccdir)/win32/include")
391 $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/win32/include")
392 endif
394 # uninstall
395 uninstall-unx:
396 @rm -fv $(addprefix "$(bindir)/",$(PROGS) $(PROGS_CROSS))
397 @rm -fv $(addprefix "$(libdir)/", libtcc*.a libtcc*.so libtcc.dylib,$P)
398 @rm -fv $(addprefix "$(includedir)/", libtcc.h)
399 @rm -fv "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
400 @rm -fv "$(docdir)/tcc-doc.html"
401 @rm -frv "$(tccdir)"
403 # install progs & libs on windows
404 install-win:
405 $(call BINCHECK)
406 $(call IBw,$(PROGS) *-tcc.exe libtcc.dll,"$(bindir)")
407 $(call IF,$(TOPSRC)/win32/lib/*.def,"$(tccdir)/lib")
408 $(call IFw,libtcc1.a $(B_O) $(LIBTCC1_W),"$(tccdir)/lib")
409 $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/include")
410 $(call IR,$(TOPSRC)/win32/include,"$(tccdir)/include")
411 $(call IR,$(TOPSRC)/win32/examples,"$(tccdir)/examples")
412 $(call IF,$(TOPSRC)/tests/libtcc_test.c,"$(tccdir)/examples")
413 $(call IFw,$(TOPSRC)/libtcc.h libtcc.def,"$(libdir)")
414 $(call IFw,$(TOPSRC)/win32/tcc-win32.txt tcc-doc.html,"$(docdir)")
415 ifneq "$(wildcard $(LIBTCC1_U))" ""
416 $(call IFw,$(LIBTCC1_U),"$(tccdir)/lib")
417 $(call IF,$(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h,"$(tccdir)/lib/include")
418 endif
420 # uninstall on windows
421 uninstall-win:
422 @rm -fv $(addprefix "$(bindir)/", libtcc*.dll $(PROGS) *-tcc.exe)
423 @rm -fr $(foreach P,doc examples include lib libtcc,"$(tccdir)/$P/*")
424 @rm -frv $(addprefix "$(tccdir)/", doc examples include lib libtcc)
426 # the msys-git shell works to configure && make except it does not have install
427 ifeq ($(OS),Windows_NT)
428 ifeq ($(shell $(call WHICH,install) || echo no),no)
429 INSTALL = cp
430 INSTALLBIN = cp
431 endif
432 endif
434 # --------------------------------------------------------------------------
435 # other stuff
437 TAGFILES = *.[ch] include/*.h lib/*.[chS]
438 tags : ; ctags $(TAGFILES)
439 # cannot have both tags and TAGS on windows
440 ETAGS : ; etags $(TAGFILES)
442 # create release tarball from *current* git branch (including tcc-doc.html
443 # and converting two files to CRLF)
444 TCC-VERSION = tcc-$(VERSION)
445 TCC-VERSION = tinycc-mob-$(shell git rev-parse --short=7 HEAD)
446 tar: tcc-doc.html
447 mkdir -p $(TCC-VERSION)
448 ( cd $(TCC-VERSION) && git --git-dir ../.git checkout -f )
449 cp tcc-doc.html $(TCC-VERSION)
450 for f in tcc-win32.txt build-tcc.bat ; do \
451 cat win32/$$f | sed 's,\(.*\),\1\r,g' > $(TCC-VERSION)/win32/$$f ; \
452 done
453 tar cjf $(TCC-VERSION).tar.bz2 $(TCC-VERSION)
454 rm -rf $(TCC-VERSION)
455 git reset
457 config.mak:
458 $(if $(wildcard $@),,@echo "Please run ./configure." && exit 1)
460 # run all tests
461 test:
462 @$(MAKE) -C tests
463 # run test(s) from tests2 subdir (see make help)
464 tests2.%:
465 @$(MAKE) -C tests/tests2 $@
466 # run test(s) from testspp subdir (see make help)
467 testspp.%:
468 @$(MAKE) -C tests/pp $@
469 # run tests with code coverage
470 tcov-tes% : tcc_c$(EXESUF)
471 @rm -f $<.tcov
472 @$(MAKE) --no-print-directory TCC_LOCAL=$(CURDIR)/$< tes$*
473 tcc_c$(EXESUF): $($T_FILES)
474 $S$(TCC) tcc.c -o $@ -ftest-coverage $(DEFINES) $(LIBS)
476 clean:
477 @rm -f tcc$(EXESUF) tcc_c$(EXESUF) tcc_p$(EXESUF) *-tcc$(EXESUF)
478 @rm -f tags ETAGS *.o *.a *.so* *.out *.log lib*.def *.exe *.dll
479 @rm -f a.out *.dylib *_.h *.pod *.tcov
480 @$(MAKE) -s -C lib $@
481 @$(MAKE) -s -C tests $@
483 distclean: clean
484 @rm -vf config.h config.mak config.texi
485 @rm -vf $(TCCDOCS)
487 .PHONY: all clean test tar tags ETAGS doc distclean install uninstall FORCE
489 help:
490 @echo "make"
491 @echo " build native compiler (from separate objects)"
492 @echo "make cross"
493 @echo " build cross compilers (from one source)"
494 @echo "make ONE_SOURCE=no/yes SILENT=no/yes"
495 @echo " force building from separate/one object(s), less/more silently"
496 @echo "make cross-TARGET"
497 @echo " build one specific cross compiler for 'TARGET'. Currently supported:"
498 @echo " $(wordlist 1,8,$(TCC_X))"
499 @echo " $(wordlist 9,99,$(TCC_X))"
500 @echo "make test"
501 @echo " run all tests"
502 @echo "make tests2.all / make tests2.37 / make tests2.37+"
503 @echo " run all/single test(s) from tests2, optionally update .expect"
504 @echo "make testspp.all / make testspp.17"
505 @echo " run all/single test(s) from tests/pp"
506 @echo "make tcov-test / tcov-tests2... / tcov-testspp..."
507 @echo " run tests as above with code coverage. After test(s) see tcc_c$(EXESUF).tcov"
508 @echo "Other supported make targets:"
509 @echo " install install-strip doc clean tags ETAGS tar distclean help"
510 @echo "Custom configuration:"
511 @echo " The makefile includes a file 'config-extra.mak' if it is present."
512 @echo " This file may contain some custom configuration. For example:"
513 @echo " NATIVE_DEFINES += -D..."
514 @echo " Or for example to configure the search paths for a cross-compiler"
515 @echo " assuming the support files in /usr/i686-linux-gnu:"
516 @echo " ROOT-i386 = /usr/i686-linux-gnu"
517 @echo " CRT-i386 = {R}/lib"
518 @echo " LIB-i386 = {B}:{R}/lib"
519 @echo " INC-i386 = {B}/include:{R}/include (*)"
520 @echo " DEF-i386 += -D__linux__"
521 @echo " Or also, for the cross platform files in /usr/<triplet>"
522 @echo " TRIPLET-i386 = i686-linux-gnu"
523 @echo " (*) tcc replaces {B} by 'tccdir' and {R} by 'CONFIG_SYSROOT'"
525 # --------------------------------------------------------------------------
526 endif # ($(INCLUDED),no)