aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
Diffstat (limited to 'win32')
-rw-r--r--win32/Makefile148
-rw-r--r--win32/build-tcc.bat105
-rw-r--r--win32/lib/crt1.c21
-rw-r--r--win32/lib/wincrt1.c76
-rw-r--r--win32/tcc-win32.txt19
5 files changed, 100 insertions, 269 deletions
diff --git a/win32/Makefile b/win32/Makefile
deleted file mode 100644
index 5bd60bd..0000000
--- a/win32/Makefile
+++ /dev/null
@@ -1,148 +0,0 @@
-#
-# 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.
-
-CPU = $(shell if `gcc -v 2>&1 | grep Target | grep -q x86_64`; then echo 64; else echo 32; fi)
-VERSION = $(shell cat ../VERSION)
-BOOTCC = gcc
-CFLAGS = -s -static -fno-strict-aliasing -Wno-incompatible-pointer-types -DTCC_TARGET_PE
-#WINPWD = `cygpath --mixed $(PWD)`
-#@echo "#define CONFIG_TCCDIR \"$(WINPWD)\""
-
-ifeq ($(CPU), 64)
-NATIVE = -m$(CPU) -DTCC_TARGET_X86_64
-ARCH = x86_64
-else
-NATIVE = -m$(CPU) -DTCC_TARGET_I386
-ARCH = i386
-endif
-
-TARGET = $(CPU)
-
-ifeq ($(TARGET), 64)
-TFLAGS = -m$(TARGET) -DTCC_TARGET_X86_64
-TARCH = x86_64
-else
-TFLAGS = -m$(TARGET) -DTCC_TARGET_I386
-TARCH = i386
-endif
-
-all: pre bootstrap libs rebuild
- @chmod 775 *.exe
- @ls -ls *.exe
-
-pre:
- @echo ARCH=$(TARCH) 1> ../config.mak
- @echo TARGETOS=Windows 1>> ../config.mak
- @echo CONFIG_WIN32=yes 1>> ../config.mak
- @echo TOPSRC=$$\(TOP\) 1>> ../config.mak
- @echo "#define TCC_VERSION \"$(VERSION)\"" 1>../config.h
- @echo "#ifdef TCC_TARGET_X86_64" 1>>../config.h
- @echo "#define TCC_LIBTCC1 \"libtcc1-64.a\"" 1>>../config.h
- @echo "#else" 1>>../config.h
- @echo "#define TCC_LIBTCC1 \"libtcc1-32.a\"" 1>>../config.h
- @echo "#endif" 1>>../config.h
- @echo @set VERSION $(VERSION) 1>../config.texi
- @rm -f *tcc.exe tiny_*.exe *tcc.dll lib/*.a
- @rm -r -f libtcc doc
- @mkdir libtcc
- @mkdir doc
- @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:
- @echo Bootstrapping 32bits and 64bits tools with $(BOOTCC) -m$(CPU)
- @$(BOOTCC) $(CFLAGS) -DTCC_TARGET_I386 -o i386-win32-tcc.exe ../tcc.c
- @$(BOOTCC) $(CFLAGS) -DTCC_TARGET_X86_64 -o x86_64-win32-tcc.exe ../tcc.c
- @$(BOOTCC) $(CFLAGS) $(NATIVE) -o tcc.exe ../tcc.c
- @$(BOOTCC) $(CFLAGS) $(NATIVE) -DLIBTCC_AS_DLL -o libtcc.dll -shared ../libtcc.c
-
-PHONY += bootstrap
-
-lib/libtcc1-32.a:
- @echo Building $*.a with tcc -m32
- @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/libtcc1.c
- @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/alloca86.S
- @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/alloca86-bt.S
- @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/crt1.c
- @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/crt1w.c
- @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/wincrt1.c
- @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/wincrt1w.c
- @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/dllcrt1.c
- @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/dllmain.c
- @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/chkstk.S
- @./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
- @rm *.o
-
-lib/libtcc1-64.a:
- @echo Building $*.a with tcc -m64
- @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/libtcc1.c
- @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/alloca86_64.S
- @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/alloca86_64-bt.S
- @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/crt1.c
- @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/crt1w.c
- @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/wincrt1.c
- @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/wincrt1w.c
- @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/dllcrt1.c
- @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/dllmain.c
- @./tcc -O2 -B. -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/chkstk.S
- @./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
- @rm *.o
-
-libs: lib/libtcc1-32.a lib/libtcc1-64.a
-
-PHONY += libs
-
-rebuild:
- @echo Rebuild using tcc itself - default $(TARGET)bits
- @./$(TARCH)-win32-tcc -O2 -B. $(TFLAGS) -DTCC_TARGET_PE -o tcc.exe ../tcc.c
- @./tcc -O2 -B. $(TFLAGS) -DTCC_TARGET_PE -DLIBTCC_AS_DLL -o libtcc.dll -shared ../libtcc.c
- @./tcc -O2 -B. -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -o tmp-tcc.exe ../tcc.c && mv tmp-tcc.exe i386-win32-tcc.exe
- @./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
-
-PHONY += rebuild
-
-test:
- @(cd ../tests; $(MAKE) -k TCC=$(PWD)/tcc hello-exe hello-run)
- @(cd ../tests; $(MAKE) -k TCC=$(PWD)/tcc vla_test-run tests2-dir pp-dir)
-ifeq ($(CPU), 64)
- @(cd ../tests; $(MAKE) -k TCC=$(PWD)/i386-win32-tcc hello-exe hello-run)
- @(cd ../tests; $(MAKE) -k TCC=$(PWD)/i386-win32-tcc vla_test-run tests2-dir pp-dir)
-endif
-
-PHONY += test
-
-TARNAME = tcc-$(VERSION)-$(ARCH)-win32
-
-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 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 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
diff --git a/win32/build-tcc.bat b/win32/build-tcc.bat
index 3c3a726..ceb4411 100644
--- a/win32/build-tcc.bat
+++ b/win32/build-tcc.bat
@@ -4,13 +4,31 @@
@echo off
setlocal
-
-set CC=gcc -Os -s -static
+if (%1)==(-clean) goto :cleanup
+set CC=gcc
set /p VERSION= < ..\VERSION
set INST=
+set BIN=
set DOC=no
+set EXES_ONLY=no
goto :a0
-
+:a2
+shift
+:a3
+shift
+:a0
+if not (%1)==(-c) goto :a1
+set CC=%~2
+if (%2)==(cl) set CC=@call :cl
+goto :a2
+:a1
+if (%1)==(-t) set T=%2&& goto :a2
+if (%1)==(-v) set VERSION=%~2&& goto :a2
+if (%1)==(-i) set INST=%2&& goto :a2
+if (%1)==(-b) set BIN=%2&& goto :a2
+if (%1)==(-d) set DOC=yes&& goto :a3
+if (%1)==(-x) set EXES_ONLY=yes&& goto :a3
+if (%1)==() goto :p1
:usage
echo usage: build-tcc.bat [ options ... ]
echo options:
@@ -18,10 +36,35 @@ echo -c prog use prog (gcc/tcc/cl) to compile tcc
echo -c "prog options" use prog with options to compile tcc
echo -t 32/64 force 32/64 bit default target
echo -v "version" set tcc version
-echo -i dir install tcc into dir
+echo -i tccdir install tcc into tccdir
+echo -b bindir optionally install binaries into bindir elsewhere
echo -d create tcc-doc.html too (needs makeinfo)
+echo -x just create the executables
+echo -clean delete all previously produced files and directories
exit /B 1
+@rem ------------------------------------------------------
+@rem sub-routines
+
+:cleanup
+set LOG=echo
+%LOG% removing files:
+for %%f in (*tcc.exe libtcc.dll lib\*.a) do call :del_file %%f
+for %%f in (..\config.h ..\config.texi) do call :del_file %%f
+for %%f in (include\*.h) do @if exist ..\%%f call :del_file %%f
+for %%f in (include\tcclib.h examples\libtcc_test.c) do call :del_file %%f
+for %%f in (*.o *.obj *.def *.pdb *.lib *.exp *.ilk) do call :del_file %%f
+%LOG% removing directories:
+for %%f in (doc libtcc) do call :del_dir %%f
+%LOG% done.
+exit /B 0
+:del_file
+if exist %1 del %1 && %LOG% %1
+exit /B 0
+:del_dir
+if exist %1 rmdir /Q/S %1 && %LOG% %1
+exit /B 0
+
:cl
@echo off
set CMD=cl
@@ -37,52 +80,16 @@ echo on
%CMD% -O1 -W2 -Zi -MT -GS- -nologo -link -opt:ref,icf
@exit /B %ERRORLEVEL%
-:a2
-shift
-:a1
-shift
-:a0
-if not (%1)==(-c) goto :a3
-set CC=%~2
-if (%2)==(cl) set CC=@call :cl
-goto :a2
-:a3
-if not (%1)==(-t) goto :a4
-set T=%2
-goto :a2
-:a4
-if not (%1)==(-v) goto :a5
-set VERSION=%~2
-goto :a2
-:a5
-if not (%1)==(-i) goto :a6
-set INST=%2
-goto :a2
-:a6
-if not (%1)==(-d) goto :a7
-set DOC=yes
-goto :a1
-:a7
-if not (%1)==() goto :usage
+@rem ------------------------------------------------------
+@rem main program
-if not "%CC%"=="@call :cl" goto :p1
-set VSCOMNTOOLS=%VS150COMNTOOLS%
-if "%VSCOMNTOOLS%"=="" set VSCOMNTOOLS=%VS140COMNTOOLS%
-if "%VSCOMNTOOLS%"=="" set VSCOMNTOOLS=%VS130COMNTOOLS%
-if "%VSCOMNTOOLS%"=="" set VSCOMNTOOLS=%VS120COMNTOOLS%
-if %T%_==32_ set CLVARS="%VSCOMNTOOLS%..\..\VC\bin\vcvars32.bat"
-if %T%_==64_ set CLVARS="%VSCOMNTOOLS%..\..\VC\bin\amd64\vcvars64.bat"
-if %T%_==_ set T=32& if %Platform%_==X64_ set T=64
-if %CLVARS%_==_ goto :p1
-if exist %CLVARS% call %CLVARS%
:p1
-
if not %T%_==_ goto :p2
set T=32
if %PROCESSOR_ARCHITECTURE%_==AMD64_ set T=64
if %PROCESSOR_ARCHITEW6432%_==AMD64_ set T=64
:p2
-
+if "%CC:~-3%"=="gcc" set CC=%CC% -Os -s -static
set D32=-DTCC_TARGET_PE -DTCC_TARGET_I386
set D64=-DTCC_TARGET_PE -DTCC_TARGET_X86_64
set P32=i386-win32
@@ -91,13 +98,14 @@ if %T%==64 goto :t64
set D=%D32%
set DX=%D64%
set PX=%P64%
-goto :t96
+goto :p3
:t64
set D=%D64%
set DX=%D32%
set PX=%P32%
-:t96
+goto :p3
+:p3
@echo on
:config.h
@@ -116,7 +124,7 @@ for %%f in (*tcc.exe *tcc.dll) do @del %%f
%CC% -o tcc.exe ..\tcc.c libtcc.dll %D% -DONE_SOURCE"=0"
%CC% -o %PX%-tcc.exe ..\tcc.c %DX%
-@if (%TCC_FILES%)==(no) goto :files-done
+@if (%EXES_ONLY%)==(yes) goto :files-done
if not exist libtcc mkdir libtcc
if not exist doc mkdir doc
@@ -170,8 +178,11 @@ for %%f in (*.o *.def) do @del %%f
:copy-install
@if (%INST%)==() goto :the_end
if not exist %INST% mkdir %INST%
+@if (%BIN%)==() set BIN=%INST%
+if not exist %BIN% mkdir %BIN%
+for %%f in (*tcc.exe *tcc.dll) do @copy>nul %%f %BIN%\%%f
@if not exist %INST%\lib mkdir %INST%\lib
-for %%f in (*tcc.exe *tcc.dll lib\*.a lib\*.def) do @copy>nul %%f %INST%\%%f
+for %%f in (lib\*.a lib\*.def) do @copy>nul %%f %INST%\%%f
for %%f in (include examples libtcc doc) do @xcopy>nul /s/i/q/y %%f %INST%\%%f
:the_end
diff --git a/win32/lib/crt1.c b/win32/lib/crt1.c
index 53e5545..0e04fc0 100644
--- a/win32/lib/crt1.c
+++ b/win32/lib/crt1.c
@@ -16,11 +16,6 @@
#define _PC_53 0x00010000 // 53 bits
#define _PC_64 0x00000000 // 64 bits
-typedef struct
-{
- int newmode;
-} _startupinfo;
-
#ifdef _UNICODE
#define __tgetmainargs __wgetmainargs
#define _tstart _wstart
@@ -33,6 +28,7 @@ typedef struct
#define _runtmain _runmain
#endif
+typedef struct { int newmode; } _startupinfo;
int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*);
void __cdecl __set_app_type(int apptype);
unsigned int __cdecl _controlfp(unsigned int new_value, unsigned int mask);
@@ -44,23 +40,19 @@ int _dowildcard;
void _tstart(void)
{
__TRY__
- int ret;
- _startupinfo start_info;
+ _startupinfo start_info = {0};
// Sets the current application type
__set_app_type(_CONSOLE_APP);
// Set default FP precision to 53 bits (8-byte double)
- // _MCW_PC (Precision control) is not supported on
- // the ARM and x64 architectures
-#ifdef __i386
+ // _MCW_PC (Precision control) is not supported on ARM
+#if defined __i386__ || defined __x86_64__
_controlfp(_PC_53, _MCW_PC);
#endif
- start_info.newmode = 0;
__tgetmainargs( &__argc, &__targv, &_tenviron, _dowildcard, &start_info);
- ret = _tmain(__argc, __targv, _tenviron);
- exit(ret);
+ exit(_tmain(__argc, __targv, _tenviron));
}
int _runtmain(int argc, /* as tcc passed in */ char **argv)
@@ -78,8 +70,7 @@ int _runtmain(int argc, /* as tcc passed in */ char **argv)
__argc = argc;
__targv = argv;
#endif
-
-#ifdef __i386
+#if defined __i386__ || defined __x86_64__
_controlfp(_PC_53, _MCW_PC);
#endif
return _tmain(__argc, __targv, _tenviron);
diff --git a/win32/lib/wincrt1.c b/win32/lib/wincrt1.c
index 83e2f74..ce3a63f 100644
--- a/win32/lib/wincrt1.c
+++ b/win32/lib/wincrt1.c
@@ -23,71 +23,53 @@ int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int);
#define _runtwinmain _runwinmain
#endif
-typedef struct
-{
- int newmode;
-} _startupinfo; // CLI Vs GUI
-
+typedef struct { int newmode; } _startupinfo;
int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*);
-int _twinstart(void)
+static int go_winmain(TCHAR *arg1)
{
- __TRY__
+ STARTUPINFO si;
_TCHAR *szCmd, *p;
- STARTUPINFO startinfo;
- _startupinfo start_info_con = {0};
int fShow;
- int ret;
-
- __set_app_type(__GUI_APP);
- _controlfp(0x10000, 0x30000);
- start_info_con.newmode = 0;
- __tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info_con);
+ GetStartupInfo(&si);
+ if (si.dwFlags & STARTF_USESHOWWINDOW)
+ fShow = si.wShowWindow;
+ else
+ fShow = SW_SHOWDEFAULT;
- p = GetCommandLine();
- if (__argc > 1)
- szCmd = _tcsstr(p, __targv[1]);
+ szCmd = NULL, p = GetCommandLine();
+ if (arg1)
+ szCmd = _tcsstr(p, arg1);
if (NULL == szCmd)
- szCmd = __T("");
- else if (szCmd > p && szCmd[-1] == __T('\"'))
+ szCmd = _tcsdup(__T(""));
+ else if (szCmd > p && szCmd[-1] == __T('"'))
--szCmd;
+#if defined __i386__ || defined __x86_64__
+ _controlfp(0x10000, 0x30000);
+#endif
+ return _tWinMain(GetModuleHandle(NULL), NULL, szCmd, fShow);
+}
- GetStartupInfo(&startinfo);
- fShow = startinfo.wShowWindow;
- if (0 == (startinfo.dwFlags & STARTF_USESHOWWINDOW))
- fShow = SW_SHOWDEFAULT;
-
- ret = _tWinMain(GetModuleHandle(NULL), NULL, szCmd, fShow);
- exit(ret);
+int _twinstart(void)
+{
+ __TRY__
+ _startupinfo start_info_con = {0};
+ __set_app_type(__GUI_APP);
+ __tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info_con);
+ exit(go_winmain(__argc > 1 ? __targv[1] : NULL));
}
int _runtwinmain(int argc, /* as tcc passed in */ char **argv)
{
- _TCHAR *szCmd, *p;
-
#ifdef UNICODE
_startupinfo start_info = {0};
-
__tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info);
/* may be wrong when tcc has received wildcards (*.c) */
- if (argc < __argc) {
- __targv += __argc - argc;
- __argc = argc;
- }
+ if (argc < __argc)
+ __targv += __argc - argc, __argc = argc;
#else
- __argc = argc;
- __targv = argv;
+ __argc = argc, __targv = argv;
#endif
-
- p = GetCommandLine();
- szCmd = NULL;
- if (argc > 1)
- szCmd = _tcsstr(p, __targv[1]);
- if (NULL == szCmd)
- szCmd = __T("");
- else if (szCmd > p && szCmd[-1] == __T('\"'))
- --szCmd;
- _controlfp(0x10000, 0x30000);
- return _tWinMain(GetModuleHandle(NULL), NULL, szCmd, SW_SHOWDEFAULT);
+ return go_winmain(__argc > 1 ? __targv[1] : NULL);
}
diff --git a/win32/tcc-win32.txt b/win32/tcc-win32.txt
index 3609684..751a8e0 100644
--- a/win32/tcc-win32.txt
+++ b/win32/tcc-win32.txt
@@ -108,6 +108,8 @@
------------------------
* You can use the MinGW and MSYS tools available at
http://www.mingw.org
+ http://www.mingw-w64.org
+ http://www.msys2.org
Untar the TCC archive and type in the MSYS shell:
./configure [--prefix installpath]
@@ -116,29 +118,22 @@
The default install location is c:\Program Files\tcc
+ Cygwin can be used too with its mingw cross-compiler installed:
+ ./configure --cross-prefix=i686-w64-mingw32-
+ (the prefix may vary)
+
* Alternatively you can compile TCC with just GCC from MinGW using
> build-tcc.bat (from the win32 directory)
Also MSVC can be used with the "VSTools Developer Command Prompt":
> build-tcc.bat -c cl
- or with a tcc (needs to be in a different directory)
+ or with an existing tcc (needs to be in a different directory)
> build-tcc.bat -c some-tcc-dir\tcc.exe
Also you can copy/install everything into another directory:
> build-tcc.bat -i <dir>
- * You can also bootstrap a native tcc Windows toolchain with cygwin.
- https://www.cygwin.com/
-
- Install Base, gcc, make
- Launch Cygwin Terminal
- > make
- or to force 32bit executables (including 64bit backend)
- > make TARGET=32
- or to force 64bit executables (including 32bit backend)
- > make TARGET=64
-
Limitations:
------------
- On the object file level, currently TCC supports only the ELF format,