Makefile for Windows native tcc handles recent UNICODE support
[tinycc.git] / win32 / Makefile
blobabb8b114905a6f743a9c64d7d876c820e10cf592
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 CPU = $(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 ($(CPU), 64)
15 NATIVE = -m$(CPU) -DTCC_TARGET_X86_64
16 ARCH = x86_64
17 else
18 NATIVE = -m$(CPU) -DTCC_TARGET_I386
19 ARCH = i386
20 endif
22 TARGET = $(CPU)
24 ifeq ($(TARGET), 64)
25 TFLAGS = -m$(TARGET) -DTCC_TARGET_X86_64
26 TARCH = x86_64
27 CARCH = x86-64
28 else
29 TFLAGS = -m$(TARGET) -DTCC_TARGET_I386
30 TARCH = i386
31 CARCH = i386
32 endif
34 all: pre bootstrap libs rebuild
35 @chmod 775 *.exe
36 @ls -ls *.exe
38 pre:
39 @echo ARCH=$(CARCH) 1> ../config.mak
40 @echo TARGETOS=Windows 1>> ../config.mak
41 @echo CONFIG_WIN32=yes 1>> ../config.mak
42 @echo TOPSRC=$$\(TOP\) 1>> ../config.mak
43 @echo "#define TCC_VERSION \"$(VERSION)\"" 1>../config.h
44 @echo "#ifdef TCC_TARGET_X86_64" 1>>../config.h
45 @echo "#define CONFIG_TCC_LIBPATHS \"{B}/lib/64;{B}/lib\"" 1>>../config.h
46 @echo "#else" 1>>../config.h
47 @echo "#define CONFIG_TCC_LIBPATHS \"{B}/lib/32;{B}/lib\"" 1>>../config.h
48 @echo "#endif" 1>>../config.h
49 @echo @set VERSION $(VERSION) 1>../config.texi
50 @rm -f *tcc.exe tiny_*.exe *tcc.dll
51 @rm -r -f libtcc
52 @rm -r -f libtcc doc lib/32 lib/64
53 @mkdir libtcc
54 @mkdir doc
55 @mkdir lib/32
56 @mkdir lib/64
57 @cp ../include/*.h include
58 @cp ../tcclib.h include
59 @cp ../libtcc.h include
60 @cp tcc-win32.txt doc
61 @cp ../tests/libtcc_test.c examples
63 PHONY += pre
65 bootstrap:
66 @echo Bootstrapping 32bits and 64bits tools with $(BOOTCC) -m$(CPU)
67 @$(BOOTCC) $(CFLAGS) -DTCC_TARGET_I386 -o i386-win32-tcc.exe ../tcc.c
68 @$(BOOTCC) $(CFLAGS) -DTCC_TARGET_I386 -o tiny_libmaker-m32.exe ./tools/tiny_libmaker.c
69 @$(BOOTCC) $(CFLAGS) -DTCC_TARGET_X86_64 -o x86_64-win32-tcc.exe ../tcc.c
70 @$(BOOTCC) $(CFLAGS) -DTCC_TARGET_X86_64 -o tiny_libmaker-m64.exe ./tools/tiny_libmaker.c
71 @$(BOOTCC) $(CFLAGS) $(NATIVE) -o tcc.exe ../tcc.c
72 @$(BOOTCC) $(CFLAGS) $(NATIVE) -DLIBTCC_AS_DLL -o libtcc.dll -shared ../libtcc.c
74 PHONY += bootstrap
76 lib/32/libtcc1.a: tiny_libmaker-m32.exe
77 @echo Building $*.a with tcc -m32
78 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/libtcc1.c
79 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/alloca86.S
80 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/alloca86-bt.S
81 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/crt1.c
82 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -D_UNICODE -DUNICODE -c lib/crt1.c -o crt1_w.o
83 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/wincrt1.c
84 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -D_UNICODE -DUNICODE -c lib/wincrt1.c -o wincrt1_w.o
85 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/dllcrt1.c
86 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/dllmain.c
87 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/chkstk.S
88 @./tiny_libmaker-m32 lib/32/libtcc1.a libtcc1.o alloca86.o alloca86-bt.o crt1.o wincrt1.o crt1_w.o wincrt1_w.o dllcrt1.o dllmain.o chkstk.o
89 @rm *.o
91 lib/64/libtcc1.a: tiny_libmaker-m64.exe
92 @echo Building $*.a with tcc -m64
93 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/libtcc1.c
94 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/alloca86_64.S
95 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/alloca86_64-bt.S
96 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/crt1.c
97 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -D_UNICODE -DUNICODE -c lib/crt1.c -o crt1_w.o
98 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/wincrt1.c
99 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -D_UNICODE -DUNICODE -c lib/wincrt1.c -o wincrt1_w.o
100 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/dllcrt1.c
101 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/dllmain.c
102 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/chkstk.S
103 @./tiny_libmaker-m64 lib/64/libtcc1.a libtcc1.o alloca86_64.o alloca86_64-bt.o crt1.o wincrt1.o crt1_w.o wincrt1_w.o dllcrt1.o dllmain.o chkstk.o
104 @rm *.o
106 libs: lib/32/libtcc1.a lib/64/libtcc1.a
108 PHONY += libs
110 rebuild:
111 @echo Rebuild using tcc itself - default $(TARGET)bits
112 @./$(TARCH)-win32-tcc $(TFLAGS) -DTCC_TARGET_PE -DONE_SOURCE -o tcc.exe ../tcc.c
113 @./$(TARCH)-win32-tcc $(TFLAGS) -DTCC_TARGET_PE -DONE_SOURCE -o tiny_libmaker.exe tools/tiny_libmaker.c
114 @./$(TARCH)-win32-tcc $(TFLAGS) -DTCC_TARGET_PE -DONE_SOURCE -o tiny_impdef.exe tools/tiny_impdef.c
115 @./tcc $(TFLAGS) -DTCC_TARGET_PE -DONE_SOURCE -DLIBTCC_AS_DLL -o libtcc.dll -shared ../libtcc.c
116 @./tcc -m$(TARGET) -DTCC_TARGET_PE -DONE_SOURCE -DTCC_TARGET_I386 -o tmp-tcc.exe ../tcc.c && mv tmp-tcc.exe i386-win32-tcc.exe
117 @./tcc -m$(TARGET) -DTCC_TARGET_PE -DONE_SOURCE -DTCC_TARGET_X86_64 -o tmp-tcc.exe ../tcc.c && mv tmp-tcc.exe x86_64-win32-tcc.exe
118 @./tcc -m$(TARGET) -DTCC_TARGET_PE -DONE_SOURCE -DTCC_TARGET_I386 -o tiny_libmaker-m32.exe tools/tiny_libmaker.c
119 @./tcc -m$(TARGET) -DTCC_TARGET_PE -DONE_SOURCE -DTCC_TARGET_X86_64 -o tiny_libmaker-m64.exe tools/tiny_libmaker.c
121 PHONY += rebuild
123 test:
124 @(cd ../tests/tests2; $(MAKE) -k TCC=../../win32/tcc)
126 PHONY += test
128 TARNAME = tcc-$(VERSION)-$(ARCH)-win32
130 tarball:
131 @rm -r -f $(TARNAME)
132 @mkdir $(TARNAME)
133 @cp -r doc $(TARNAME)
134 @cp -r examples $(TARNAME)
135 @cp -r include $(TARNAME)
136 @cp -r lib $(TARNAME)
137 @cp -r libtcc $(TARNAME)
138 @cp -r tools $(TARNAME)
139 @cp -r build-tcc.bat $(TARNAME)
140 @cp -r i386-win32-tcc.exe $(TARNAME)
141 @cp -r libtcc.def $(TARNAME)
142 @cp -r libtcc.dll $(TARNAME)
143 @cp -r Makefile $(TARNAME)
144 @cp -r tcc.exe $(TARNAME)
145 @cp -r tcc-win32.txt $(TARNAME)
146 @cp -r tiny_impdef.exe $(TARNAME)
147 @cp -r tiny_libmaker.exe $(TARNAME)
148 @cp -r tiny_libmaker-m32.exe $(TARNAME)
149 @cp -r tiny_libmaker-m64.exe $(TARNAME)
150 @cp -r x86_64-win32-tcc.exe $(TARNAME)
151 @tar czf $(TARNAME).tar.gz $(TARNAME)
152 @rm -r -f $(TARNAME)
154 PHONY += tarball
156 clean:
157 rm -f *.o *.exe *.dll lib/*/*.a *.pdb *.obj *.exp *.def *.lib