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
10 git.exe --version 2>nul
11 if not %ERRORLEVEL%==0 goto :git_done
12 for /f %%b in ('git.exe rev-parse --abbrev-ref HEAD') do set GITHASH=%%b
13 for /f %%h in ('git.exe rev-parse --short HEAD') do set GITHASH=%GITHASH%:%%h
15 if %ERRORLEVEL%==1 set GITHASH=%GITHASH%-mod
16 set DEF_GITHASH=-DTCC_GITHASH="""%GITHASH%"""
27 if not (%1)==(-c) goto :a1
29 if (%2)==(cl) set CC=@call :cl
32 if (%1)==(-t) set T=%2&& goto :a2
33 if (%1)==(-v) set VERSION=%~2&& goto :a2
34 if (%1)==(-i) set INST=%2&& goto :a2
35 if (%1)==(-d) set DOC=yes&& goto :a3
36 if (%1)==(-x) set EXES_ONLY=yes&& goto :a3
39 echo usage: build-tcc.bat [ options ... ]
41 echo -c prog use prog (gcc/tcc/cl) to compile tcc
42 echo -c "prog options" use prog with options to compile tcc
43 echo -t 32/64 force 32/64 bit default target
44 echo -v "version" set tcc version
45 echo -i tccdir install tcc into tccdir
46 echo -d create tcc-doc.html too (needs makeinfo)
47 echo -x just create the executables
48 echo -clean delete all previously produced files and directories
51 @rem ------------------------------------------------------
57 for %%f in (*tcc.exe libtcc.dll lib\*.a) do call :del_file %%f
58 for %%f in (..\config.h ..\config.texi) do call :del_file %%f
59 for %%f in (include\*.h) do @if exist ..\%%f call :del_file %%f
60 for %%f in (include\tcclib.h examples\libtcc_test.c) do call :del_file %%f
61 for %%f in (lib\*.o *.o *.obj *.def *.pdb *.lib *.exp *.ilk) do call :del_file %%f
62 %LOG% removing directories:
63 for %%f in (doc libtcc) do call :del_dir %%f
67 if exist %1 del %1 && %LOG% %1
70 if exist %1 rmdir /Q/S %1 && %LOG% %1
78 set ARG=%ARG:.dll=.lib%
79 if (%1)==(-shared) set ARG=-LD
80 if (%1)==(-o) shift && set ARG=-Fe%2
83 if not (%1)==() goto :c0
85 %CMD% -O2 -W2 -Zi -MT -GS- -nologo %DEF_GITHASH% -link -opt:ref,icf
88 @rem ------------------------------------------------------
92 if not %T%_==_ goto :p2
94 if %PROCESSOR_ARCHITECTURE%_==AMD64_ set T=64
95 if %PROCESSOR_ARCHITEW6432%_==AMD64_ set T=64
97 if "%CC:~-3%"=="gcc" set CC=%CC% -O2 -s -static %DEF_GITHASH%
98 set D32=-DTCC_TARGET_PE -DTCC_TARGET_I386
99 set D64=-DTCC_TARGET_PE -DTCC_TARGET_X86_64
119 echo>..\config.h #define TCC_VERSION "%VERSION%"
120 echo>> ..\config.h #ifdef TCC_TARGET_X86_64
121 echo>> ..\config.h #define TCC_LIBTCC1 "libtcc1-64.a"
122 echo>> ..\config.h #else
123 echo>> ..\config.h #define TCC_LIBTCC1 "libtcc1-32.a"
124 echo>> ..\config.h #endif
126 for %%f in (*tcc.exe *tcc.dll) do @del %%f
128 @if _%TCC_C%_==__ goto compiler_2parts
129 @rem if TCC_C was defined then build only tcc.exe
130 %CC% -o tcc.exe %TCC_C% %D%
134 @if _%LIBTCC_C%_==__ set LIBTCC_C=..\libtcc.c
135 %CC% -o libtcc.dll -shared %LIBTCC_C% %D% -DLIBTCC_AS_DLL
136 @if errorlevel 1 goto :the_end
137 %CC% -o tcc.exe ..\tcc.c libtcc.dll %D% -DONE_SOURCE"=0"
138 %CC% -o %PX%-tcc.exe ..\tcc.c %DX%
140 @if (%EXES_ONLY%)==(yes) goto :files_done
142 if not exist libtcc mkdir libtcc
143 if not exist doc mkdir doc
144 copy>nul ..\include\*.h include
145 copy>nul ..\tcclib.h include
146 copy>nul ..\libtcc.h libtcc
147 copy>nul ..\tests\libtcc_test.c examples
148 copy>nul tcc-win32.txt doc
150 if exist libtcc.dll .\tcc -impdef libtcc.dll -o libtcc\libtcc.def
151 @if errorlevel 1 goto :the_end
155 @if errorlevel 1 goto :the_end
156 @if exist %PX%-tcc.exe call :makelib %TX%
157 @if errorlevel 1 goto :the_end
158 .\tcc -m%T% -c ../lib/bcheck.c -o lib/bcheck.o -g
159 .\tcc -m%T% -c ../lib/bt-exe.c -o lib/bt-exe.o
160 .\tcc -m%T% -c ../lib/bt-log.c -o lib/bt-log.o
161 .\tcc -m%T% -c ../lib/bt-dll.c -o lib/bt-dll.o
164 @if not (%DOC%)==(yes) goto :doc-done
165 echo>..\config.texi @set VERSION %VERSION%
166 cmd /c makeinfo --html --no-split ../tcc-doc.texi -o doc/tcc-doc.html
170 for %%f in (*.o *.def) do @del %%f
173 @if (%INST%)==() goto :the_end
174 if not exist %INST% mkdir %INST%
175 for %%f in (*tcc.exe *tcc.dll) do @copy>nul %%f %INST%\%%f
176 @if not exist %INST%\lib mkdir %INST%\lib
177 for %%f in (lib\*.a lib\*.o lib\*.def) do @copy>nul %%f %INST%\%%f
178 for %%f in (include examples libtcc doc) do @xcopy>nul /s/i/q/y %%f %INST%\%%f
184 .\tcc -m%1 -c ../lib/libtcc1.c
185 .\tcc -m%1 -c lib/crt1.c
186 .\tcc -m%1 -c lib/crt1w.c
187 .\tcc -m%1 -c lib/wincrt1.c
188 .\tcc -m%1 -c lib/wincrt1w.c
189 .\tcc -m%1 -c lib/dllcrt1.c
190 .\tcc -m%1 -c lib/dllmain.c
191 .\tcc -m%1 -c lib/chkstk.S
192 .\tcc -m%1 -c ../lib/alloca.S
193 .\tcc -m%1 -c ../lib/alloca-bt.S
194 .\tcc -m%1 -c ../lib/stdatomic.c
195 .\tcc -m%1 -ar lib/libtcc1-%1.a libtcc1.o crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o chkstk.o alloca.o alloca-bt.o stdatomic.o