Detect native version from default gcc target.
[tinycc.git] / win32 / Makefile
blob0b0c5b521cca3765cb55e56f21f0ef7fc6b0d279
2 # This Makefile builds native Windows tcc for both 32 and 64 bits generator.
3 # It requires Cygwin 64 and gcc to bootstrap a first tcc version which is used
4 # by a second stage to compile tcc it self.
5 # Generated binaries do not require cygwin to run.
6 # You can launch 'tarball' target to build a tar.gz you can install on any
7 # Windows machines.
9 ARCH = $(shell if `gcc -v 2>&1 | grep Target | grep -q x86_64`; then echo 64; else echo 32; fi)
10 VERSION = $(shell cat ../VERSION)
11 BOOTCC = gcc
12 CFLAGS = -s -fno-strict-aliasing -Wno-incompatible-pointer-types -DTCC_TARGET_PE -DONE_SOURCE
14 ifeq ($(ARCH), 64)
15 NATIVE = -m$(ARCH) -DTCC_TARGET_X86_64
16 PREFIX = x86_64
17 else
18 NATIVE = -m$(ARCH) -DTCC_TARGET_I386
19 PREFIX = i386
20 endif
22 all: pre bootstrap libs rebuild
23 @chmod 775 *.exe
24 @ls -ls *.exe
26 pre:
27 @echo "#define TCC_VERSION \"$(VERSION)\"" 1>../config.h
28 @echo "#ifdef TCC_TARGET_X86_64" 1>>../config.h
29 @echo "#define CONFIG_TCC_LIBPATHS \"{B}/lib/64;{B}/lib\"" 1>>../config.h
30 @echo "#else" 1>>../config.h
31 @echo "#define CONFIG_TCC_LIBPATHS \"{B}/lib/32;{B}/lib\"" 1>>../config.h
32 @echo "#endif" 1>>../config.h
33 @echo @set VERSION $(VERSION) 1>../config.texi
34 @rm -f *tcc.exe tiny_*.exe *tcc.dll
35 @rm -r -f libtcc
36 @rm -r -f libtcc doc lib/32 lib/64
37 @mkdir libtcc
38 @mkdir doc
39 @mkdir lib/32
40 @mkdir lib/64
41 @cp ../include/*.h include
42 @cp ../tcclib.h include
43 @cp ../libtcc.h include
44 @cp tcc-win32.txt doc
45 @cp ../tests/libtcc_test.c examples
47 PHONY += pre
49 bootstrap:
50 @echo Bootstrapping 32bits and 64bits tools with $(BOOTCC) -m$(ARCH)
51 @$(BOOTCC) $(CFLAGS) -DTCC_TARGET_I386 -o i386-win32-tcc.exe ../tcc.c
52 @$(BOOTCC) $(CFLAGS) -DTCC_TARGET_I386 -o tiny_libmaker32.exe ./tools/tiny_libmaker.c
53 @$(BOOTCC) $(CFLAGS) -DTCC_TARGET_X86_64 -o x86_64-win32-tcc.exe ../tcc.c
54 @$(BOOTCC) $(CFLAGS) -DTCC_TARGET_X86_64 -o tiny_libmaker64.exe ./tools/tiny_libmaker.c
55 @$(BOOTCC) $(CFLAGS) $(NATIVE) -o tcc.exe ../tcc.c
56 @$(BOOTCC) $(CFLAGS) $(NATIVE) -DLIBTCC_AS_DLL -o libtcc.dll -shared ../libtcc.c
58 PHONY += bootstrap
60 lib/32/libtcc1.a: tiny_libmaker32.exe
61 @echo Building $*.a with tcc -m32
62 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/libtcc1.c
63 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/alloca86.S
64 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/alloca86-bt.S
65 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/crt1.c
66 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/wincrt1.c
67 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/dllcrt1.c
68 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/dllmain.c
69 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/chkstk.S
70 @./tiny_libmaker32 lib/32/libtcc1.a libtcc1.o alloca86.o alloca86-bt.o crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o
71 @rm *.o
73 lib/64/libtcc1.a: tcc.exe tiny_libmaker64.exe
74 @echo Building $*.a with tcc -m64
75 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/libtcc1.c
76 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/alloca86_64.S
77 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/alloca86_64-bt.S
78 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/crt1.c
79 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/wincrt1.c
80 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/dllcrt1.c
81 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/dllmain.c
82 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/chkstk.S
83 @./tiny_libmaker64 lib/64/libtcc1.a libtcc1.o alloca86_64.o alloca86_64-bt.o crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o
84 @rm *.o
86 libs: lib/32/libtcc1.a lib/64/libtcc1.a
88 PHONY += libs
90 rebuild:
91 @echo Rebuild using tcc itself - default $(ARCH)bits
92 @./$(PREFIX)-win32-tcc $(NATIVE) -DTCC_TARGET_PE -DONE_SOURCE -o tcc.exe ../tcc.c libtcc.dll
93 @./$(PREFIX)-win32-tcc $(NATIVE) -DTCC_TARGET_PE -DONE_SOURCE -o tiny_libmaker.exe tools/tiny_libmaker.c
94 @./tcc $(NATIVE) -DTCC_TARGET_PE -DONE_SOURCE -DLIBTCC_AS_DLL -o libtcc.dll -shared ../libtcc.c
95 @./tcc -m$(ARCH) -DTCC_TARGET_PE -DONE_SOURCE -DTCC_TARGET_I386 -o tmp-tcc.exe ../tcc.c && mv tmp-tcc.exe i386-win32-tcc.exe
96 @./tcc -m$(ARCH) -DTCC_TARGET_PE -DONE_SOURCE -DTCC_TARGET_X86_64 -o tmp-tcc.exe ../tcc.c && mv tmp-tcc.exe x86_64-win32-tcc.exe
97 @./tcc -m$(ARCH) -DTCC_TARGET_PE -DONE_SOURCE -DTCC_TARGET_I386 -o tiny_libmaker32.exe tools/tiny_libmaker.c
98 @./tcc -m$(ARCH) -DTCC_TARGET_PE -DONE_SOURCE -DTCC_TARGET_X86_64 -o tiny_libmaker64.exe tools/tiny_libmaker.c
100 PHONY += rebuild
102 TARNAME = tcc-$(VERSION)-$(PREFIX)-win32
104 tarball:
105 @rm -r -f $(TARNAME)
106 @mkdir $(TARNAME)
107 @cp -r doc $(TARNAME)
108 @cp -r examples $(TARNAME)
109 @cp -r include $(TARNAME)
110 @cp -r lib $(TARNAME)
111 @cp -r libtcc $(TARNAME)
112 @cp -r tools $(TARNAME)
113 @cp -r vs2015 $(TARNAME)
114 @cp -r build-tcc.bat $(TARNAME)
115 @cp -r i386-win32-tcc.exe $(TARNAME)
116 @cp -r libtcc.def $(TARNAME)
117 @cp -r libtcc.dll $(TARNAME)
118 @cp -r Makefile $(TARNAME)
119 @cp -r tcc.exe $(TARNAME)
120 @cp -r tcc-win32.txt $(TARNAME)
121 @cp -r tiny_libmaker.exe $(TARNAME)
122 @cp -r tiny_libmaker32.exe $(TARNAME)
123 @cp -r tiny_libmaker64.exe $(TARNAME)
124 @cp -r x86_64-win32-tcc.exe $(TARNAME)
125 @tar czf $(TARNAME).tar.gz $(TARNAME)
126 @rm -r -f $(TARNAME)
128 PHONY += tarball
130 clean:
131 rm -f *.o *.exe *.dll lib/*/*.a