win32/include/math.h: rint/trunc: pop fp stack
[tinycc.git] / win32 / build-tcc.bat
blobe3ec5b7fbe6176fa05af93e36bc46bf90d758db8
1 @rem ------------------------------------------------------
2 @rem batch file to build tcc using mingw, msvc or tcc itself
3 @rem ------------------------------------------------------
5 @echo off
6 setlocal
7 if (%1)==(-clean) goto :cleanup
8 set CC=gcc
9 set /p VERSION= < ..\VERSION
10 set INST=
11 set BIN=
12 set DOC=no
13 set EXES_ONLY=no
14 goto :a0
15 :a2
16 shift
17 :a3
18 shift
19 :a0
20 if not (%1)==(-c) goto :a1
21 set CC=%~2
22 if (%2)==(cl) set CC=@call :cl
23 goto :a2
24 :a1
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
31 if (%1)==() goto :p1
32 :usage
33 echo usage: build-tcc.bat [ options ... ]
34 echo 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
44 exit /B 1
46 @rem ------------------------------------------------------
47 @rem sub-routines
49 :cleanup
50 set LOG=echo
51 %LOG% removing files:
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
59 %LOG% done.
60 exit /B 0
61 :del_file
62 if exist %1 del %1 && %LOG%   %1
63 exit /B 0
64 :del_dir
65 if exist %1 rmdir /Q/S %1 && %LOG%   %1
66 exit /B 0
68 :cl
69 @echo off
70 set CMD=cl
71 :c0
72 set ARG=%1
73 set ARG=%ARG:.dll=.lib%
74 if (%1)==(-shared) set ARG=-LD
75 if (%1)==(-o) shift && set ARG=-Fe%2
76 set CMD=%CMD% %ARG%
77 shift
78 if not (%1)==() goto :c0
79 echo on
80 %CMD% -O1 -W2 -Zi -MT -GS- -nologo -link -opt:ref,icf
81 @exit /B %ERRORLEVEL%
83 @rem ------------------------------------------------------
84 @rem main program
86 :p1
87 if not %T%_==_ goto :p2
88 set T=32
89 if %PROCESSOR_ARCHITECTURE%_==AMD64_ set T=64
90 if %PROCESSOR_ARCHITEW6432%_==AMD64_ set T=64
91 :p2
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
95 set P32=i386-win32
96 set P64=x86_64-win32
97 if %T%==64 goto :t64
98 set D=%D32%
99 set DX=%D64%
100 set PX=%P64%
101 goto :p3
102 :t64
103 set D=%D64%
104 set DX=%D32%
105 set PX=%P32%
106 goto :p3
109 @echo on
111 :config.h
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
121 :compiler
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
140 :libtcc1.a
141 @set O1=libtcc1.o crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o chkstk.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 -c ../lib/alloca86.S
151 .\tcc -m32 -c ../lib/alloca86-bt.S
152 .\tcc -m32 -ar lib/libtcc1-32.a %O1% alloca86.o alloca86-bt.o
153 @if errorlevel 1 goto :the_end
154 .\tcc -m64 -c ../lib/libtcc1.c
155 .\tcc -m64 -c lib/crt1.c
156 .\tcc -m64 -c lib/crt1w.c
157 .\tcc -m64 -c lib/wincrt1.c
158 .\tcc -m64 -c lib/wincrt1w.c
159 .\tcc -m64 -c lib/dllcrt1.c
160 .\tcc -m64 -c lib/dllmain.c
161 .\tcc -m64 -c lib/chkstk.S
162 .\tcc -m64 -c ../lib/alloca86_64.S
163 .\tcc -m64 -c ../lib/alloca86_64-bt.S
164 .\tcc -m64 -ar lib/libtcc1-64.a %O1% alloca86_64.o alloca86_64-bt.o
165 @if errorlevel 1 goto :the_end
166 .\tcc -m%T% -c ../lib/bcheck.c -o lib/bcheck.o -g
167 .\tcc -m%T% -c ../lib/bt-exe.c -o lib/bt-exe.o
168 .\tcc -m%T% -c ../lib/bt-log.c -o lib/bt-log.o
169 .\tcc -m%T% -c ../lib/bt-dll.c -o lib/bt-dll.o
171 :tcc-doc.html
172 @if not (%DOC%)==(yes) goto :doc-done
173 echo>..\config.texi @set VERSION %VERSION%
174 cmd /c makeinfo --html --no-split ../tcc-doc.texi -o doc/tcc-doc.html
175 :doc-done
177 :files-done
178 for %%f in (*.o *.def) do @del %%f
180 :copy-install
181 @if (%INST%)==() goto :the_end
182 if not exist %INST% mkdir %INST%
183 @if (%BIN%)==() set BIN=%INST%
184 if not exist %BIN% mkdir %BIN%
185 for %%f in (*tcc.exe *tcc.dll) do @copy>nul %%f %BIN%\%%f
186 @if not exist %INST%\lib mkdir %INST%\lib
187 for %%f in (lib\*.a lib\*.o lib\*.def) do @copy>nul %%f %INST%\%%f
188 for %%f in (include examples libtcc doc) do @xcopy>nul /s/i/q/y %%f %INST%\%%f
190 :the_end
191 exit /B %ERRORLEVEL%