2017-02-16 09:01:44 +03:00
|
|
|
#
|
|
|
|
# This Makefile builds native Windows tcc for both 32 and 64 bits generator.
|
|
|
|
# It requires Cygwin 64 and gcc to bootstrap a first tcc version which is used
|
|
|
|
# by a second stage to compile tcc it self.
|
|
|
|
# Generated binaries do not require cygwin to run.
|
|
|
|
# You can launch 'tarball' target to build a tar.gz you can install on any
|
|
|
|
# Windows machines.
|
|
|
|
|
2017-02-18 10:00:58 +03:00
|
|
|
CPU = $(shell if `gcc -v 2>&1 | grep Target | grep -q x86_64`; then echo 64; else echo 32; fi)
|
2017-02-16 09:01:44 +03:00
|
|
|
VERSION = $(shell cat ../VERSION)
|
|
|
|
BOOTCC = gcc
|
|
|
|
CFLAGS = -s -fno-strict-aliasing -Wno-incompatible-pointer-types -DTCC_TARGET_PE -DONE_SOURCE
|
|
|
|
|
2017-02-18 10:00:58 +03:00
|
|
|
ifeq ($(CPU), 64)
|
|
|
|
NATIVE = -m$(CPU) -DTCC_TARGET_X86_64
|
|
|
|
ARCH = x86_64
|
2017-02-16 09:01:44 +03:00
|
|
|
else
|
2017-02-18 10:00:58 +03:00
|
|
|
NATIVE = -m$(CPU) -DTCC_TARGET_I386
|
|
|
|
ARCH = i386
|
2017-02-16 09:01:44 +03:00
|
|
|
endif
|
|
|
|
|
2017-02-18 10:00:58 +03:00
|
|
|
TARGET = $(CPU)
|
2017-02-16 09:01:44 +03:00
|
|
|
|
|
|
|
ifeq ($(TARGET), 64)
|
|
|
|
TFLAGS = -m$(TARGET) -DTCC_TARGET_X86_64
|
2017-02-18 10:00:58 +03:00
|
|
|
TARCH = x86_64
|
|
|
|
CARCH = x86-64
|
2017-02-16 09:01:44 +03:00
|
|
|
else
|
|
|
|
TFLAGS = -m$(TARGET) -DTCC_TARGET_I386
|
2017-02-18 10:00:58 +03:00
|
|
|
TARCH = i386
|
|
|
|
CARCH = i386
|
2017-02-16 09:01:44 +03:00
|
|
|
endif
|
|
|
|
|
|
|
|
all: pre bootstrap libs rebuild
|
|
|
|
@chmod 775 *.exe
|
|
|
|
@ls -ls *.exe
|
|
|
|
|
|
|
|
pre:
|
2017-02-18 10:00:58 +03:00
|
|
|
@echo ARCH=$(CARCH) 1> ../config.mak
|
2017-02-17 10:05:38 +03:00
|
|
|
@echo TARGETOS=Windows 1>> ../config.mak
|
|
|
|
@echo CONFIG_WIN32=yes 1>> ../config.mak
|
|
|
|
@echo TOPSRC=$$\(TOP\) 1>> ../config.mak
|
2017-02-16 09:01:44 +03:00
|
|
|
@echo "#define TCC_VERSION \"$(VERSION)\"" 1>../config.h
|
|
|
|
@echo "#ifdef TCC_TARGET_X86_64" 1>>../config.h
|
|
|
|
@echo "#define CONFIG_TCC_LIBPATHS \"{B}/lib/64;{B}/lib\"" 1>>../config.h
|
|
|
|
@echo "#else" 1>>../config.h
|
|
|
|
@echo "#define CONFIG_TCC_LIBPATHS \"{B}/lib/32;{B}/lib\"" 1>>../config.h
|
|
|
|
@echo "#endif" 1>>../config.h
|
|
|
|
@echo @set VERSION $(VERSION) 1>../config.texi
|
|
|
|
@rm -f *tcc.exe tiny_*.exe *tcc.dll
|
|
|
|
@rm -r -f libtcc
|
|
|
|
@rm -r -f libtcc doc lib/32 lib/64
|
|
|
|
@mkdir libtcc
|
|
|
|
@mkdir doc
|
|
|
|
@mkdir lib/32
|
|
|
|
@mkdir lib/64
|
|
|
|
@cp ../include/*.h include
|
|
|
|
@cp ../tcclib.h include
|
|
|
|
@cp ../libtcc.h include
|
|
|
|
@cp tcc-win32.txt doc
|
|
|
|
@cp ../tests/libtcc_test.c examples
|
|
|
|
|
|
|
|
PHONY += pre
|
|
|
|
|
|
|
|
bootstrap:
|
2017-02-18 10:00:58 +03:00
|
|
|
@echo Bootstrapping 32bits and 64bits tools with $(BOOTCC) -m$(CPU)
|
2017-02-16 09:01:44 +03:00
|
|
|
@$(BOOTCC) $(CFLAGS) -DTCC_TARGET_I386 -o i386-win32-tcc.exe ../tcc.c
|
2017-02-18 10:00:58 +03:00
|
|
|
@$(BOOTCC) $(CFLAGS) -DTCC_TARGET_I386 -o tiny_libmaker-m32.exe ./tools/tiny_libmaker.c
|
2017-02-16 09:01:44 +03:00
|
|
|
@$(BOOTCC) $(CFLAGS) -DTCC_TARGET_X86_64 -o x86_64-win32-tcc.exe ../tcc.c
|
2017-02-18 10:00:58 +03:00
|
|
|
@$(BOOTCC) $(CFLAGS) -DTCC_TARGET_X86_64 -o tiny_libmaker-m64.exe ./tools/tiny_libmaker.c
|
2017-02-16 09:01:44 +03:00
|
|
|
@$(BOOTCC) $(CFLAGS) $(NATIVE) -o tcc.exe ../tcc.c
|
|
|
|
@$(BOOTCC) $(CFLAGS) $(NATIVE) -DLIBTCC_AS_DLL -o libtcc.dll -shared ../libtcc.c
|
|
|
|
|
|
|
|
PHONY += bootstrap
|
|
|
|
|
2017-02-18 10:00:58 +03:00
|
|
|
lib/32/libtcc1.a: tiny_libmaker-m32.exe
|
2017-02-16 09:01:44 +03:00
|
|
|
@echo Building $*.a with tcc -m32
|
|
|
|
@./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/libtcc1.c
|
|
|
|
@./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/alloca86.S
|
|
|
|
@./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/alloca86-bt.S
|
|
|
|
@./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/crt1.c
|
2017-02-18 10:00:58 +03:00
|
|
|
@./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -D_UNICODE -DUNICODE -c lib/crt1.c -o crt1_w.o
|
2017-02-16 09:01:44 +03:00
|
|
|
@./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/wincrt1.c
|
2017-02-18 10:00:58 +03:00
|
|
|
@./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -D_UNICODE -DUNICODE -c lib/wincrt1.c -o wincrt1_w.o
|
2017-02-16 09:01:44 +03:00
|
|
|
@./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/dllcrt1.c
|
|
|
|
@./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/dllmain.c
|
2017-02-18 10:00:58 +03:00
|
|
|
@./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/chkstk.S
|
|
|
|
@./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
|
2017-02-16 09:01:44 +03:00
|
|
|
@rm *.o
|
|
|
|
|
2017-02-18 10:00:58 +03:00
|
|
|
lib/64/libtcc1.a: tiny_libmaker-m64.exe
|
2017-02-16 09:01:44 +03:00
|
|
|
@echo Building $*.a with tcc -m64
|
|
|
|
@./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/libtcc1.c
|
|
|
|
@./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/alloca86_64.S
|
|
|
|
@./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/alloca86_64-bt.S
|
|
|
|
@./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/crt1.c
|
2017-02-18 10:00:58 +03:00
|
|
|
@./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -D_UNICODE -DUNICODE -c lib/crt1.c -o crt1_w.o
|
2017-02-16 09:01:44 +03:00
|
|
|
@./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/wincrt1.c
|
2017-02-18 10:00:58 +03:00
|
|
|
@./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -D_UNICODE -DUNICODE -c lib/wincrt1.c -o wincrt1_w.o
|
2017-02-16 09:01:44 +03:00
|
|
|
@./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/dllcrt1.c
|
|
|
|
@./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/dllmain.c
|
|
|
|
@./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/chkstk.S
|
2017-02-18 10:00:58 +03:00
|
|
|
@./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
|
2017-02-16 09:01:44 +03:00
|
|
|
@rm *.o
|
|
|
|
|
|
|
|
libs: lib/32/libtcc1.a lib/64/libtcc1.a
|
|
|
|
|
|
|
|
PHONY += libs
|
|
|
|
|
|
|
|
rebuild:
|
|
|
|
@echo Rebuild using tcc itself - default $(TARGET)bits
|
2017-02-18 10:00:58 +03:00
|
|
|
@./$(TARCH)-win32-tcc $(TFLAGS) -DTCC_TARGET_PE -DONE_SOURCE -o tcc.exe ../tcc.c
|
|
|
|
@./$(TARCH)-win32-tcc $(TFLAGS) -DTCC_TARGET_PE -DONE_SOURCE -o tiny_libmaker.exe tools/tiny_libmaker.c
|
|
|
|
@./$(TARCH)-win32-tcc $(TFLAGS) -DTCC_TARGET_PE -DONE_SOURCE -o tiny_impdef.exe tools/tiny_impdef.c
|
2017-02-16 09:01:44 +03:00
|
|
|
@./tcc $(TFLAGS) -DTCC_TARGET_PE -DONE_SOURCE -DLIBTCC_AS_DLL -o libtcc.dll -shared ../libtcc.c
|
|
|
|
@./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
|
|
|
|
@./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
|
2017-02-18 10:00:58 +03:00
|
|
|
@./tcc -m$(TARGET) -DTCC_TARGET_PE -DONE_SOURCE -DTCC_TARGET_I386 -o tiny_libmaker-m32.exe tools/tiny_libmaker.c
|
|
|
|
@./tcc -m$(TARGET) -DTCC_TARGET_PE -DONE_SOURCE -DTCC_TARGET_X86_64 -o tiny_libmaker-m64.exe tools/tiny_libmaker.c
|
2017-02-16 09:01:44 +03:00
|
|
|
|
|
|
|
PHONY += rebuild
|
|
|
|
|
2017-02-17 10:05:38 +03:00
|
|
|
test:
|
|
|
|
@(cd ../tests/tests2; $(MAKE) -k TCC=../../win32/tcc)
|
|
|
|
|
|
|
|
PHONY += test
|
|
|
|
|
2017-02-18 10:00:58 +03:00
|
|
|
TARNAME = tcc-$(VERSION)-$(ARCH)-win32
|
2017-02-16 09:01:44 +03:00
|
|
|
|
|
|
|
tarball:
|
|
|
|
@rm -r -f $(TARNAME)
|
|
|
|
@mkdir $(TARNAME)
|
|
|
|
@cp -r doc $(TARNAME)
|
|
|
|
@cp -r examples $(TARNAME)
|
|
|
|
@cp -r include $(TARNAME)
|
|
|
|
@cp -r lib $(TARNAME)
|
|
|
|
@cp -r libtcc $(TARNAME)
|
|
|
|
@cp -r tools $(TARNAME)
|
|
|
|
@cp -r build-tcc.bat $(TARNAME)
|
|
|
|
@cp -r i386-win32-tcc.exe $(TARNAME)
|
|
|
|
@cp -r libtcc.def $(TARNAME)
|
|
|
|
@cp -r libtcc.dll $(TARNAME)
|
|
|
|
@cp -r Makefile $(TARNAME)
|
|
|
|
@cp -r tcc.exe $(TARNAME)
|
|
|
|
@cp -r tcc-win32.txt $(TARNAME)
|
|
|
|
@cp -r tiny_impdef.exe $(TARNAME)
|
|
|
|
@cp -r tiny_libmaker.exe $(TARNAME)
|
2017-02-18 10:00:58 +03:00
|
|
|
@cp -r tiny_libmaker-m32.exe $(TARNAME)
|
|
|
|
@cp -r tiny_libmaker-m64.exe $(TARNAME)
|
2017-02-16 09:01:44 +03:00
|
|
|
@cp -r x86_64-win32-tcc.exe $(TARNAME)
|
|
|
|
@tar czf $(TARNAME).tar.gz $(TARNAME)
|
|
|
|
@rm -r -f $(TARNAME)
|
|
|
|
|
|
|
|
PHONY += tarball
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -f *.o *.exe *.dll lib/*/*.a *.pdb *.obj *.exp *.def *.lib
|