1 @rem ------------------------------------------------------
2 @rem batch file to build tcc using mingw, msvc or tcc itself
3 @rem ------------------------------------------------------
7 if (%1)==(-clean) goto :cleanup
9 set /p VERSION= < ..\VERSION
20 if not (%1)==(-c) goto :a1
22 if (%2)==(cl) set CC=@call :cl
25 if (%1)==(-t) set T=%2&& goto :a2
26 if (%1)==(-v) set VERSION=%~2&& goto :a2
27 if (%1)==(-i) set TCCDIR=%2&& goto :a2
28 if (%1)==(-b) set BINDIR=%2&& goto :a2
29 if (%1)==(-d) set DOC=yes&& goto :a3
30 if (%1)==(-x) set XCC=yes&& goto :a3
33 echo usage: build-tcc.bat [ options ... ]
35 echo -c prog use prog (gcc/tcc/cl) to compile tcc
36 echo -c "prog options" use prog with options to compile tcc
37 echo -t 32/64 force 32/64 bit default target
38 echo -v "version" set tcc version
39 echo -i tccdir install tcc into tccdir
40 echo -b bindir but install tcc.exe and libtcc.dll into bindir
41 echo -d create tcc-doc.html too (needs makeinfo)
42 echo -x build the cross compiler too
43 echo -clean delete all previously produced files and directories
46 @rem ------------------------------------------------------
52 for %%f in (*tcc.exe libtcc.dll lib\*.a) do call :del_file %%f
53 for %%f in (..\config.h ..\config.texi) do call :del_file %%f
54 for %%f in (include\*.h) do @if exist ..\%%f call :del_file %%f
55 for %%f in (include\tcclib.h examples\libtcc_test.c) do call :del_file %%f
56 for %%f in (lib\*.o *.o *.obj *.def *.pdb *.lib *.exp *.ilk) do call :del_file %%f
57 %LOG% removing directories:
58 for %%f in (doc libtcc) do call :del_dir %%f
62 if exist %1 del %1 && %LOG% %1
65 if exist %1 rmdir /Q/S %1 && %LOG% %1
73 set ARG=%ARG:.dll=.lib%
74 if (%1)==(-shared) set ARG=-LD
75 if (%1)==(-o) shift && set ARG=-Fe%2
78 if not (%1)==() goto :c0
80 %CMD% -O2 -W2 -Zi -MT -GS- -nologo %DEF_GITHASH% -link -opt:ref,icf
83 @rem ------------------------------------------------------
87 if not %T%_==_ goto :p2
89 if %PROCESSOR_ARCHITECTURE%_==AMD64_ set T=64
90 if %PROCESSOR_ARCHITEW6432%_==AMD64_ set T=64
92 if "%CC:~-3%"=="gcc" set CC=%CC% -O2 -s -static
93 if (%BINDIR%)==() set BINDIR=%TCCDIR%
95 set D32=-DTCC_TARGET_PE -DTCC_TARGET_I386
96 set D64=-DTCC_TARGET_PE -DTCC_TARGET_X86_64
117 git.exe --version 2>nul
118 if not %ERRORLEVEL%==0 goto :git_done
119 for /f %%b in ('git.exe rev-parse --abbrev-ref HEAD') do set GITHASH=%%b
120 for /f %%b in ('git.exe log -1 "--pretty=format:%%cs_%GITHASH%@%%h"') do set GITHASH=%%b
122 if %ERRORLEVEL%==1 set GITHASH=%GITHASH%*
127 echo>..\config.h #define TCC_VERSION "%VERSION%"
128 if not (%GITHASH%)==() echo>> ..\config.h #define TCC_GITHASH "%GITHASH%"
129 @if not (%BINDIR%)==(%TCCDIR%) echo>> ..\config.h #define CONFIG_TCCDIR "%TCCDIR:\=/%"
130 if %TX%==64 echo>> ..\config.h #ifdef TCC_TARGET_X86_64
131 if %TX%==32 echo>> ..\config.h #ifdef TCC_TARGET_I386
132 echo>> ..\config.h #define CONFIG_TCC_CROSSPREFIX "%PX%-"
133 echo>> ..\config.h #endif
135 for %%f in (*tcc.exe *tcc.dll) do @del %%f
137 @if _%TCC_C%_==__ goto compiler_2parts
138 @rem if TCC_C was defined then build only tcc.exe
139 %CC% -o tcc.exe %TCC_C% %D%
140 @if errorlevel 1 goto :the_end
144 @if _%LIBTCC_C%_==__ set LIBTCC_C=..\libtcc.c
145 %CC% -o libtcc.dll -shared %LIBTCC_C% %D% -DLIBTCC_AS_DLL
146 @if errorlevel 1 goto :the_end
147 %CC% -o tcc.exe ..\tcc.c libtcc.dll %D% -DONE_SOURCE"=0"
148 @if errorlevel 1 goto :the_end
149 if not _%XCC%_==_yes_ goto :compiler_done
150 %CC% -o %PX%-tcc.exe ..\tcc.c %DX%
151 @if errorlevel 1 goto :the_end
153 @if (%EXES_ONLY%)==(yes) goto :files_done
155 if not exist libtcc mkdir libtcc
156 if not exist doc mkdir doc
157 copy>nul ..\include\*.h include
158 copy>nul ..\tcclib.h include
159 copy>nul ..\libtcc.h libtcc
160 copy>nul ..\tests\libtcc_test.c examples
161 copy>nul tcc-win32.txt doc
163 if exist libtcc.dll .\tcc -impdef libtcc.dll -o libtcc\libtcc.def
164 @if errorlevel 1 goto :the_end
167 call :make_lib %T% || goto :the_end
168 @if exist %PX%-tcc.exe call :make_lib %TX% %PX%- || goto :the_end
171 @if not (%DOC%)==(yes) goto :doc-done
172 echo>..\config.texi @set VERSION %VERSION%
173 cmd /c makeinfo --html --no-split ../tcc-doc.texi -o doc/tcc-doc.html
177 for %%f in (*.o *.def) do @del %%f
180 @if (%TCCDIR%)==() goto :the_end
181 if not exist %BINDIR% mkdir %BINDIR%
182 for %%f in (*tcc.exe *tcc.dll) do @copy>nul %%f %BINDIR%\%%f
183 if not exist %TCCDIR% mkdir %TCCDIR%
184 @if not exist %TCCDIR%\lib mkdir %TCCDIR%\lib
185 for %%f in (lib\*.a lib\*.o lib\*.def) do @copy>nul %%f %TCCDIR%\%%f
186 for %%f in (include examples libtcc doc) do @xcopy>nul /s/i/q/y %%f %TCCDIR%\%%f
192 .\tcc -B. -m%1 -c ../lib/libtcc1.c
193 .\tcc -B. -m%1 -c lib/crt1.c
194 .\tcc -B. -m%1 -c lib/crt1w.c
195 .\tcc -B. -m%1 -c lib/wincrt1.c
196 .\tcc -B. -m%1 -c lib/wincrt1w.c
197 .\tcc -B. -m%1 -c lib/dllcrt1.c
198 .\tcc -B. -m%1 -c lib/dllmain.c
199 .\tcc -B. -m%1 -c lib/chkstk.S
200 .\tcc -B. -m%1 -c ../lib/alloca.S
201 .\tcc -B. -m%1 -c ../lib/alloca-bt.S
202 .\tcc -B. -m%1 -c ../lib/stdatomic.c
203 .\tcc -B. -m%1 -ar lib/%2libtcc1.a libtcc1.o crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o chkstk.o alloca.o alloca-bt.o stdatomic.o
204 .\tcc -B. -m%1 -c ../lib/bcheck.c -o lib/%2bcheck.o -bt
205 .\tcc -B. -m%1 -c ../lib/bt-exe.c -o lib/%2bt-exe.o
206 .\tcc -B. -m%1 -c ../lib/bt-log.c -o lib/%2bt-log.o
207 .\tcc -B. -m%1 -c ../lib/bt-dll.c -o lib/%2bt-dll.o
208 .\tcc -B. -m%1 -c ../lib/runmain.c -o lib/%2runmain.o