1 @rem ------------------------------------------------------
2 @rem batch file to build tcc using mingw, msvc or tcc itself
3 @rem ------------------------------------------------------
8 set VSCOMNTOOLS=%VS150COMNTOOLS%
9 if "%VSCOMNTOOLS%"=="" set VSCOMNTOOLS=%VS140COMNTOOLS%
10 if "%VSCOMNTOOLS%"=="" set VSCOMNTOOLS=%VS130COMNTOOLS%
11 if "%VSCOMNTOOLS%"=="" set VSCOMNTOOLS=%VS120COMNTOOLS%
13 set /p VERSION= < ..\VERSION
19 echo usage: build-tcc.bat [ options ... ]
21 echo -c prog use prog (gcc/tcc/cl) to compile tcc
22 echo -c "prog options" use prog with options to compile tcc
23 echo -t 32/64 force 32/64 bit default target
24 echo -v "version" set tcc version
25 echo -i dir install tcc into dir
26 echo -d create tcc-doc.html too (needs makeinfo)
34 set ARG=%ARG:.dll=.lib%
35 if (%1)==(-shared) set ARG=-LD
36 if (%1)==(-o) shift && set ARG=-Fe%2
39 if not (%1)==() goto :c0
41 %CMD% -O1 -W2 -Zi -MT -GS- -nologo -link -opt:ref,icf
49 if not (%1)==(-c) goto :a3
51 if (%2)==(cl) set CC=@call :cl
54 if not (%1)==(-t) goto :a4
58 if not (%1)==(-v) goto :a5
62 if not (%1)==(-i) goto :a6
66 if not (%1)==(-d) goto :a7
70 if not (%1)==() goto :usage
72 if not "%CC%"=="@call :cl" goto :p1
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
77 if not %T%_==_ goto :p2
79 if %PROCESSOR_ARCHITECTURE%_==AMD64_ set T=64
80 if %PROCESSOR_ARCHITEW6432%_==AMD64_ set T=64
83 set D32=-DTCC_TARGET_PE -DTCC_TARGET_I386
84 set D64=-DTCC_TARGET_PE -DTCC_TARGET_X86_64
100 @if %CLVARS%_==_ goto :config.h
104 echo>..\config.h #define TCC_VERSION "%VERSION%"
105 echo>> ..\config.h #ifdef TCC_TARGET_X86_64
106 echo>> ..\config.h #define CONFIG_TCC_LIBPATHS "{B}/lib/64;{B}/lib"
107 echo>> ..\config.h #else
108 echo>> ..\config.h #define CONFIG_TCC_LIBPATHS "{B}/lib/32;{B}/lib"
109 echo>> ..\config.h #endif
111 @del /q *tcc.exe tiny_*.exe *tcc.dll
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
120 %CC% -o tiny_impdef.exe tools\tiny_impdef.c %D%
121 %CC% -o tiny_libmaker.exe tools\tiny_libmaker.c %D%
123 @if (%TCC_FILES%)==(no) goto :files-done
125 if not exist libtcc mkdir libtcc
126 if not exist doc mkdir doc
127 if not exist lib\32 mkdir lib\32
128 if not exist lib\64 mkdir lib\64
129 copy>nul ..\include\*.h include
130 copy>nul ..\tcclib.h include
131 copy>nul ..\libtcc.h libtcc
132 tiny_impdef libtcc.dll -o libtcc\libtcc.def
133 copy>nul ..\tests\libtcc_test.c examples
134 copy>nul tcc-win32.txt doc
136 copy>nul tiny_libmaker.exe tiny_libmaker-m%T%.exe
137 %CC% -o tiny_libmaker-m%TX%.exe tools\tiny_libmaker.c %DX%
140 @set O1=libtcc1.o crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o bcheck.o
141 .\tcc -m32 %D32% -c ../lib/libtcc1.c
142 .\tcc -m32 %D32% -c lib/crt1.c
143 .\tcc -m32 %D32% -c lib/wincrt1.c
144 .\tcc -m32 %D32% -c lib/dllcrt1.c
145 .\tcc -m32 %D32% -c lib/dllmain.c
146 .\tcc -m32 %D32% -c lib/chkstk.S
147 .\tcc -m32 %D32% -w -c ../lib/bcheck.c
148 .\tcc -m32 %D32% -c ../lib/alloca86.S
149 .\tcc -m32 %D32% -c ../lib/alloca86-bt.S
150 tiny_libmaker-m32 lib/32/libtcc1.a %O1% alloca86.o alloca86-bt.o
151 @if errorlevel 1 goto :the_end
152 .\tcc -m64 %D64% -c ../lib/libtcc1.c
153 .\tcc -m64 %D64% -c lib/crt1.c
154 .\tcc -m64 %D64% -c lib/wincrt1.c
155 .\tcc -m64 %D64% -c lib/dllcrt1.c
156 .\tcc -m64 %D64% -c lib/dllmain.c
157 .\tcc -m64 %D64% -c lib/chkstk.S
158 .\tcc -m64 %D64% -w -c ../lib/bcheck.c
159 .\tcc -m64 %D64% -c ../lib/alloca86_64.S
160 .\tcc -m64 %D64% -c ../lib/alloca86_64-bt.S
161 tiny_libmaker-m64 lib/64/libtcc1.a %O1% alloca86_64.o alloca86_64-bt.o
162 @if errorlevel 1 goto :the_end
165 @if not (%DOC%)==(yes) goto :doc-done
166 echo>..\config.texi @set VERSION %VERSION%
167 cmd /c makeinfo --html --no-split ../tcc-doc.texi -o doc/tcc-doc.html
171 @del /q *.o *.def *-m??.exe
174 @if (%INST%)==() goto :the_end
175 if not exist %INST% mkdir %INST%
176 @for %%f in (*tcc.exe tiny_*.exe *tcc.dll) do copy>nul %%f %INST%
177 @for %%f in (include lib examples libtcc doc) do xcopy>nul /s/i/q/y %%f %INST%\%%f
178 del %INST%\lib\*.c %INST%\lib\*.S