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 INST=%2&& goto :a2
28 if (%1)==(-b) set BIN=%2&& goto :a2
29 if (%1)==(-d) set DOC=yes&& goto :a3
30 if (%1)==(-x) set EXES_ONLY=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 optionally install binaries into bindir elsewhere
41 echo -d create tcc-doc.html too (needs makeinfo)
42 echo -x just create the executables
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 (*.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% -O1 -W2 -Zi -MT -GS- -nologo -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% -Os -s -static
93 set D32=-DTCC_TARGET_PE -DTCC_TARGET_I386
94 set D64=-DTCC_TARGET_PE -DTCC_TARGET_X86_64
112 echo>..\config.h #define TCC_VERSION "%VERSION%"
113 echo>> ..\config.h #ifdef TCC_TARGET_X86_64
114 echo>> ..\config.h #define TCC_LIBTCC1 "libtcc1-64.a"
115 echo>> ..\config.h #else
116 echo>> ..\config.h #define TCC_LIBTCC1 "libtcc1-32.a"
117 echo>> ..\config.h #endif
119 for %%f in (*tcc.exe *tcc.dll) do @del %%f
122 %CC% -o libtcc.dll -shared ..\libtcc.c %D% -DLIBTCC_AS_DLL
123 @if errorlevel 1 goto :the_end
124 %CC% -o tcc.exe ..\tcc.c libtcc.dll %D% -DONE_SOURCE"=0"
125 %CC% -o %PX%-tcc.exe ..\tcc.c %DX%
127 @if (%EXES_ONLY%)==(yes) goto :files-done
129 if not exist libtcc mkdir libtcc
130 if not exist doc mkdir doc
131 copy>nul ..\include\*.h include
132 copy>nul ..\tcclib.h include
133 copy>nul ..\libtcc.h libtcc
134 copy>nul ..\tests\libtcc_test.c examples
135 copy>nul tcc-win32.txt doc
137 .\tcc -impdef libtcc.dll -o libtcc\libtcc.def
138 @if errorlevel 1 goto :the_end
141 @set O1=libtcc1.o crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o chkstk.o bcheck.o
142 .\tcc -m32 -c ../lib/libtcc1.c
143 .\tcc -m32 -c lib/crt1.c
144 .\tcc -m32 -c lib/crt1w.c
145 .\tcc -m32 -c lib/wincrt1.c
146 .\tcc -m32 -c lib/wincrt1w.c
147 .\tcc -m32 -c lib/dllcrt1.c
148 .\tcc -m32 -c lib/dllmain.c
149 .\tcc -m32 -c lib/chkstk.S
150 .\tcc -m32 -w -c ../lib/bcheck.c
151 .\tcc -m32 -c ../lib/alloca86.S
152 .\tcc -m32 -c ../lib/alloca86-bt.S
153 .\tcc -m32 -ar lib/libtcc1-32.a %O1% alloca86.o alloca86-bt.o
154 @if errorlevel 1 goto :the_end
155 .\tcc -m64 -c ../lib/libtcc1.c
156 .\tcc -m64 -c lib/crt1.c
157 .\tcc -m64 -c lib/crt1w.c
158 .\tcc -m64 -c lib/wincrt1.c
159 .\tcc -m64 -c lib/wincrt1w.c
160 .\tcc -m64 -c lib/dllcrt1.c
161 .\tcc -m64 -c lib/dllmain.c
162 .\tcc -m64 -c lib/chkstk.S
163 .\tcc -m64 -w -c ../lib/bcheck.c
164 .\tcc -m64 -c ../lib/alloca86_64.S
165 .\tcc -m64 -c ../lib/alloca86_64-bt.S
166 .\tcc -m64 -ar lib/libtcc1-64.a %O1% alloca86_64.o alloca86_64-bt.o
167 @if errorlevel 1 goto :the_end
170 @if not (%DOC%)==(yes) goto :doc-done
171 echo>..\config.texi @set VERSION %VERSION%
172 cmd /c makeinfo --html --no-split ../tcc-doc.texi -o doc/tcc-doc.html
176 for %%f in (*.o *.def) do @del %%f
179 @if (%INST%)==() goto :the_end
180 if not exist %INST% mkdir %INST%
181 @if (%BIN%)==() set BIN=%INST%
182 if not exist %BIN% mkdir %BIN%
183 for %%f in (*tcc.exe *tcc.dll) do @copy>nul %%f %BIN%\%%f
184 @if not exist %INST%\lib mkdir %INST%\lib
185 for %%f in (lib\*.a lib\*.def) do @copy>nul %%f %INST%\%%f
186 for %%f in (include examples libtcc doc) do @xcopy>nul /s/i/q/y %%f %INST%\%%f