1 @rem ------------------------------------------------------
2 @rem batch file to build tcc using mingw, msvc or tcc itself
3 @rem ------------------------------------------------------
8 set CC=gcc -Os -s -static
9 set /p VERSION= < ..\VERSION
15 echo usage: build-tcc.bat [ options ... ]
17 echo -c prog use prog (gcc/tcc/cl) to compile tcc
18 echo -c "prog options" use prog with options to compile tcc
19 echo -t 32/64 force 32/64 bit default target
20 echo -v "version" set tcc version
21 echo -i dir install tcc into dir
22 echo -d create tcc-doc.html too (needs makeinfo)
30 set ARG=%ARG:.dll=.lib%
31 if (%1)==(-shared) set ARG=-LD
32 if (%1)==(-o) shift && set ARG=-Fe%2
35 if not (%1)==() goto :c0
37 %CMD% -O1 -W2 -Zi -MT -GS- -nologo -link -opt:ref,icf
45 if not (%1)==(-c) goto :a3
47 if (%2)==(cl) set CC=@call :cl
50 if not (%1)==(-t) goto :a4
54 if not (%1)==(-v) goto :a5
58 if not (%1)==(-i) goto :a6
62 if not (%1)==(-d) goto :a7
66 if not (%1)==() goto :usage
68 if not "%CC%"=="@call :cl" goto :p1
69 set VSCOMNTOOLS=%VS150COMNTOOLS%
70 if "%VSCOMNTOOLS%"=="" set VSCOMNTOOLS=%VS140COMNTOOLS%
71 if "%VSCOMNTOOLS%"=="" set VSCOMNTOOLS=%VS130COMNTOOLS%
72 if "%VSCOMNTOOLS%"=="" set VSCOMNTOOLS=%VS120COMNTOOLS%
73 if %T%_==32_ set CLVARS="%VSCOMNTOOLS%..\..\VC\bin\vcvars32.bat"
74 if %T%_==64_ set CLVARS="%VSCOMNTOOLS%..\..\VC\bin\amd64\vcvars64.bat"
75 if %T%_==_ set T=32& if %Platform%_==X64_ set T=64
76 if %CLVARS%_==_ goto :p1
77 if exist %CLVARS% call %CLVARS%
80 if not %T%_==_ goto :p2
82 if %PROCESSOR_ARCHITECTURE%_==AMD64_ set T=64
83 if %PROCESSOR_ARCHITEW6432%_==AMD64_ set T=64
86 set D32=-DTCC_TARGET_PE -DTCC_TARGET_I386
87 set D64=-DTCC_TARGET_PE -DTCC_TARGET_X86_64
104 echo>..\config.h #define TCC_VERSION "%VERSION%"
105 echo>> ..\config.h #ifdef TCC_TARGET_X86_64
106 echo>> ..\config.h #define TCC_LIBTCC1 "libtcc1-64.a"
107 echo>> ..\config.h #else
108 echo>> ..\config.h #define TCC_LIBTCC1 "libtcc1-32.a"
109 echo>> ..\config.h #endif
111 for %%f in (*tcc.exe *tcc.dll) do @del %%f
114 %CC% -o libtcc.dll -shared ..\libtcc.c %D% -DONE_SOURCE -DLIBTCC_AS_DLL
115 @if errorlevel 1 goto :the_end
116 %CC% -o tcc.exe ..\tcc.c libtcc.dll %D%
117 %CC% -o %PX%-tcc.exe ..\tcc.c %DX% -DONE_SOURCE
119 @if (%TCC_FILES%)==(no) goto :files-done
121 if not exist libtcc mkdir libtcc
122 if not exist doc mkdir doc
123 copy>nul ..\include\*.h include
124 copy>nul ..\tcclib.h include
125 copy>nul ..\libtcc.h libtcc
126 copy>nul ..\tests\libtcc_test.c examples
127 copy>nul tcc-win32.txt doc
129 .\tcc -impdef libtcc.dll -o libtcc\libtcc.def
130 @if errorlevel 1 goto :the_end
133 @set O1=libtcc1.o crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o chkstk.o bcheck.o
134 .\tcc -m32 %D32% -c ../lib/libtcc1.c
135 .\tcc -m32 %D32% -c lib/crt1.c
136 .\tcc -m32 %D32% -c lib/crt1w.c
137 .\tcc -m32 %D32% -c lib/wincrt1.c
138 .\tcc -m32 %D32% -c lib/wincrt1w.c
139 .\tcc -m32 %D32% -c lib/dllcrt1.c
140 .\tcc -m32 %D32% -c lib/dllmain.c
141 .\tcc -m32 %D32% -c lib/chkstk.S
142 .\tcc -m32 %D32% -w -c ../lib/bcheck.c
143 .\tcc -m32 %D32% -c ../lib/alloca86.S
144 .\tcc -m32 %D32% -c ../lib/alloca86-bt.S
145 .\tcc -m32 -ar lib/libtcc1-32.a %O1% alloca86.o alloca86-bt.o
146 @if errorlevel 1 goto :the_end
147 .\tcc -m64 %D64% -c ../lib/libtcc1.c
148 .\tcc -m64 %D64% -c lib/crt1.c
149 .\tcc -m64 %D64% -c lib/crt1w.c
150 .\tcc -m64 %D64% -c lib/wincrt1.c
151 .\tcc -m64 %D64% -c lib/wincrt1w.c
152 .\tcc -m64 %D64% -c lib/dllcrt1.c
153 .\tcc -m64 %D64% -c lib/dllmain.c
154 .\tcc -m64 %D64% -c lib/chkstk.S
155 .\tcc -m64 %D64% -w -c ../lib/bcheck.c
156 .\tcc -m64 %D64% -c ../lib/alloca86_64.S
157 .\tcc -m64 %D64% -c ../lib/alloca86_64-bt.S
158 .\tcc -m64 -ar lib/libtcc1-64.a %O1% alloca86_64.o alloca86_64-bt.o
159 @if errorlevel 1 goto :the_end
162 @if not (%DOC%)==(yes) goto :doc-done
163 echo>..\config.texi @set VERSION %VERSION%
164 cmd /c makeinfo --html --no-split ../tcc-doc.texi -o doc/tcc-doc.html
168 for %%f in (*.o *.def) do @del %%f
171 @if (%INST%)==() goto :the_end
172 if not exist %INST% mkdir %INST%
173 @if not exist %INST%\lib mkdir %INST%\lib
174 for %%f in (*tcc.exe *tcc.dll lib\*.a lib\*.def) do @copy>nul %%f %INST%\%%f
175 for %%f in (include examples libtcc doc) do @xcopy>nul /s/i/q/y %%f %INST%\%%f