Windows test Makefile target also test pp tests.
[tinycc.git] / win32 / Makefile
blobeb842073f0b0853fb59d5bc028bfd860181506da
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 -static -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 else
28 TFLAGS = -m$(TARGET) -DTCC_TARGET_I386
29 TARCH = i386
30 endif
32 all: pre bootstrap libs rebuild
33 @chmod 775 *.exe
34 @ls -ls *.exe
36 pre:
37 @echo ARCH=$(TARCH) 1> ../config.mak
38 @echo TARGETOS=Windows 1>> ../config.mak
39 @echo CONFIG_WIN32=yes 1>> ../config.mak
40 @echo TOPSRC=$$\(TOP\) 1>> ../config.mak
41 @echo "#define TCC_VERSION \"$(VERSION)\"" 1>../config.h
42 @echo "#ifdef TCC_TARGET_X86_64" 1>>../config.h
43 @echo "#define TCC_LIBTCC1 \"libtcc1-64.a\"" 1>>../config.h
44 @echo "#else" 1>>../config.h
45 @echo "#define TCC_LIBTCC1 \"libtcc1-32.a\"" 1>>../config.h
46 @echo "#endif" 1>>../config.h
47 @echo @set VERSION $(VERSION) 1>../config.texi
48 @rm -f *tcc.exe tiny_*.exe *tcc.dll lib/*.a
49 @rm -r -f libtcc doc
50 @mkdir libtcc
51 @mkdir doc
52 @cp ../include/*.h include
53 @cp ../tcclib.h include
54 @cp ../libtcc.h include
55 @cp tcc-win32.txt doc
56 @cp ../tests/libtcc_test.c examples
58 PHONY += pre
60 bootstrap:
61 @echo Bootstrapping 32bits and 64bits tools with $(BOOTCC) -m$(CPU)
62 @$(BOOTCC) $(CFLAGS) -DTCC_TARGET_I386 -o i386-win32-tcc.exe ../tcc.c
63 @$(BOOTCC) $(CFLAGS) -DTCC_TARGET_X86_64 -o x86_64-win32-tcc.exe ../tcc.c
64 @$(BOOTCC) $(CFLAGS) $(NATIVE) -o tcc.exe ../tcc.c
65 @$(BOOTCC) $(CFLAGS) $(NATIVE) -DLIBTCC_AS_DLL -o libtcc.dll -shared ../libtcc.c
67 PHONY += bootstrap
69 lib/libtcc1-32.a:
70 @echo Building $*.a with tcc -m32
71 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/libtcc1.c
72 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/alloca86.S
73 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/alloca86-bt.S
74 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/crt1.c
75 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/crt1w.c
76 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/wincrt1.c
77 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/wincrt1w.c
78 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/dllcrt1.c
79 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/dllmain.c
80 @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/chkstk.S
81 @./tcc -m32 -ar lib/libtcc1-32.a libtcc1.o alloca86.o alloca86-bt.o crt1.o wincrt1.o crt1w.o wincrt1w.o dllcrt1.o dllmain.o chkstk.o
82 @rm *.o
84 lib/libtcc1-64.a:
85 @echo Building $*.a with tcc -m64
86 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/libtcc1.c
87 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/alloca86_64.S
88 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/alloca86_64-bt.S
89 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/crt1.c
90 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/crt1w.c
91 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/wincrt1.c
92 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/wincrt1w.c
93 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/dllcrt1.c
94 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/dllmain.c
95 @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/chkstk.S
96 @./tcc -m64 -ar lib/libtcc1-64.a libtcc1.o alloca86_64.o alloca86_64-bt.o crt1.o wincrt1.o crt1w.o wincrt1w.o dllcrt1.o dllmain.o chkstk.o
97 @rm *.o
99 libs: lib/libtcc1-32.a lib/libtcc1-64.a
101 PHONY += libs
103 rebuild:
104 @echo Rebuild using tcc itself - default $(TARGET)bits
105 @./$(TARCH)-win32-tcc $(TFLAGS) -DTCC_TARGET_PE -DONE_SOURCE -o tcc.exe ../tcc.c
106 @./tcc $(TFLAGS) -DTCC_TARGET_PE -DONE_SOURCE -DLIBTCC_AS_DLL -o libtcc.dll -shared ../libtcc.c
107 @./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
108 @./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
110 PHONY += rebuild
112 test:
113 @(cd ../tests/tests2; $(MAKE) -k TCC=../../win32/tcc)
114 @(cd ../tests/pp; $(MAKE) -k TCC=../../win32/tcc)
116 PHONY += test
118 TARNAME = tcc-$(VERSION)-$(ARCH)-win32
120 tarball:
121 @rm -r -f $(TARNAME)
122 @mkdir $(TARNAME)
123 @cp -r doc $(TARNAME)
124 @cp -r examples $(TARNAME)
125 @cp -r include $(TARNAME)
126 @cp -r lib $(TARNAME)
127 @cp -r libtcc $(TARNAME)
128 @cp -r tools $(TARNAME)
129 @cp -r build-tcc.bat $(TARNAME)
130 @cp -r i386-win32-tcc.exe $(TARNAME)
131 @cp -r libtcc.def $(TARNAME)
132 @cp -r libtcc.dll $(TARNAME)
133 @cp -r Makefile $(TARNAME)
134 @cp -r tcc.exe $(TARNAME)
135 @cp -r tcc-win32.txt $(TARNAME)
136 @cp -r x86_64-win32-tcc.exe $(TARNAME)
137 @tar czf $(TARNAME).tar.gz $(TARNAME)
138 @rm -r -f $(TARNAME)
140 PHONY += tarball
142 clean:
143 rm -f *.o *.exe *.dll lib/*.a *.pdb *.obj *.exp *.def *.lib