Remove debug echo in Cygwin Makefile
[tinycc.git] / win32 / Makefile
blob02f3de599ce4ae9aa8a1b243e63e90b6d2dd6448
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
13 #WINPWD = `cygpath --mixed $(PWD)`
14 #@echo "#define CONFIG_TCCDIR \"$(WINPWD)\""
16 ifeq ($(CPU), 64)
17 NATIVE = -m$(CPU) -DTCC_TARGET_X86_64
18 ARCH = x86_64
19 else
20 NATIVE = -m$(CPU) -DTCC_TARGET_I386
21 ARCH = i386
22 endif
24 TARGET = $(CPU)
26 ifeq ($(TARGET), 64)
27 TFLAGS = -m$(TARGET) -DTCC_TARGET_X86_64
28 TARCH = x86_64
29 else
30 TFLAGS = -m$(TARGET) -DTCC_TARGET_I386
31 TARCH = i386
32 endif
34 all: pre bootstrap libs rebuild
35 @chmod 775 *.exe
36 @ls -ls *.exe
38 pre:
39 @echo ARCH=$(TARCH) 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 TCC_LIBTCC1 \"libtcc1-64.a\"" 1>>../config.h
46 @echo "#else" 1>>../config.h
47 @echo "#define TCC_LIBTCC1 \"libtcc1-32.a\"" 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 lib/*.a
51 @rm -r -f libtcc doc
52 @mkdir libtcc
53 @mkdir doc
54 @cp ../include/*.h include
55 @cp ../tcclib.h include
56 @cp ../libtcc.h include
57 @cp tcc-win32.txt doc
58 @cp ../tests/libtcc_test.c examples
60 PHONY += pre
62 bootstrap:
63 @echo Bootstrapping 32bits and 64bits tools with $(BOOTCC) -m$(CPU)
64 @$(BOOTCC) $(CFLAGS) -DTCC_TARGET_I386 -o i386-win32-tcc.exe ../tcc.c
65 @$(BOOTCC) $(CFLAGS) -DTCC_TARGET_X86_64 -o x86_64-win32-tcc.exe ../tcc.c
66 @$(BOOTCC) $(CFLAGS) $(NATIVE) -o tcc.exe ../tcc.c
67 @$(BOOTCC) $(CFLAGS) $(NATIVE) -DLIBTCC_AS_DLL -o libtcc.dll -shared ../libtcc.c
69 PHONY += bootstrap
71 lib/libtcc1-32.a:
72 @echo Building $*.a with tcc -m32
73 @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/libtcc1.c
74 @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/alloca86.S
75 @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/alloca86-bt.S
76 @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/crt1.c
77 @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/crt1w.c
78 @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/wincrt1.c
79 @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/wincrt1w.c
80 @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/dllcrt1.c
81 @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/dllmain.c
82 @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/chkstk.S
83 @./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
84 @rm *.o
86 lib/libtcc1-64.a:
87 @echo Building $*.a with tcc -m64
88 @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/libtcc1.c
89 @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/alloca86_64.S
90 @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/alloca86_64-bt.S
91 @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/crt1.c
92 @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/crt1w.c
93 @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/wincrt1.c
94 @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/wincrt1w.c
95 @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/dllcrt1.c
96 @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/dllmain.c
97 @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/chkstk.S
98 @./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
99 @rm *.o
101 libs: lib/libtcc1-32.a lib/libtcc1-64.a
103 PHONY += libs
105 rebuild:
106 @echo Rebuild using tcc itself - default $(TARGET)bits
107 @./$(TARCH)-win32-tcc -O2 -B. $(TFLAGS) -DTCC_TARGET_PE -o tcc.exe ../tcc.c
108 @./tcc -O2 -B. $(TFLAGS) -DTCC_TARGET_PE -DLIBTCC_AS_DLL -o libtcc.dll -shared ../libtcc.c
109 @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -o tmp-tcc.exe ../tcc.c && mv tmp-tcc.exe i386-win32-tcc.exe
110 @./tcc -O2 -B. -m$(TARGET) -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -o tmp-tcc.exe ../tcc.c && mv tmp-tcc.exe x86_64-win32-tcc.exe
112 PHONY += rebuild
114 test:
115 @(cd ../tests; $(MAKE) -k TCC=$(PWD)/tcc hello-exe hello-run)
116 @(cd ../tests; $(MAKE) -k TCC=$(PWD)/tcc vla_test-run tests2-dir pp-dir)
117 ifeq ($(CPU), 64)
118 @(cd ../tests; $(MAKE) -k TCC=$(PWD)/i386-win32-tcc hello-exe hello-run)
119 @(cd ../tests; $(MAKE) -k TCC=$(PWD)/i386-win32-tcc vla_test-run tests2-dir pp-dir)
120 endif
122 PHONY += test
124 TARNAME = tcc-$(VERSION)-$(ARCH)-win32
126 tarball:
127 @rm -r -f $(TARNAME)
128 @mkdir $(TARNAME)
129 @cp -r doc $(TARNAME)
130 @cp -r examples $(TARNAME)
131 @cp -r include $(TARNAME)
132 @cp -r lib $(TARNAME)
133 @cp -r libtcc $(TARNAME)
134 @cp -r tools $(TARNAME)
135 @cp -r build-tcc.bat $(TARNAME)
136 @cp -r i386-win32-tcc.exe $(TARNAME)
137 @cp -r libtcc.def $(TARNAME)
138 @cp -r libtcc.dll $(TARNAME)
139 @cp -r Makefile $(TARNAME)
140 @cp -r tcc.exe $(TARNAME)
141 @cp -r tcc-win32.txt $(TARNAME)
142 @cp -r x86_64-win32-tcc.exe $(TARNAME)
143 @tar czf $(TARNAME).tar.gz $(TARNAME)
144 @rm -r -f $(TARNAME)
146 PHONY += tarball
148 clean:
149 rm -f *.o *.exe *.dll lib/*.a *.pdb *.obj *.exp *.def *.lib