'long' review
[tinycc.git] / win32 / build-tcc.bat
blob3c3a72675a00f9667a04be8594a0989e57abe4dc
1 @rem ------------------------------------------------------
2 @rem batch file to build tcc using mingw, msvc or tcc itself
3 @rem ------------------------------------------------------
5 @echo off
6 setlocal
8 set CC=gcc -Os -s -static
9 set /p VERSION= < ..\VERSION
10 set INST=
11 set DOC=no
12 goto :a0
14 :usage
15 echo usage: build-tcc.bat [ options ... ]
16 echo options:
17 echo   -c prog              use prog (gcc/tcc/cl) to compile tcc
18 echo   -c "prog options"    use prog with options to compile tcc
19 echo   -t 32/64             force 32/64 bit default target
20 echo   -v "version"         set tcc version
21 echo   -i dir               install tcc into dir
22 echo   -d                   create tcc-doc.html too (needs makeinfo)
23 exit /B 1
25 :cl
26 @echo off
27 set CMD=cl
28 :c0
29 set ARG=%1
30 set ARG=%ARG:.dll=.lib%
31 if (%1)==(-shared) set ARG=-LD
32 if (%1)==(-o) shift && set ARG=-Fe%2
33 set CMD=%CMD% %ARG%
34 shift
35 if not (%1)==() goto :c0
36 echo on
37 %CMD% -O1 -W2 -Zi -MT -GS- -nologo -link -opt:ref,icf
38 @exit /B %ERRORLEVEL%
40 :a2
41 shift
42 :a1
43 shift
44 :a0
45 if not (%1)==(-c) goto :a3
46 set CC=%~2
47 if (%2)==(cl) set CC=@call :cl
48 goto :a2
49 :a3
50 if not (%1)==(-t) goto :a4
51 set T=%2
52 goto :a2
53 :a4
54 if not (%1)==(-v) goto :a5
55 set VERSION=%~2
56 goto :a2
57 :a5
58 if not (%1)==(-i) goto :a6
59 set INST=%2
60 goto :a2
61 :a6
62 if not (%1)==(-d) goto :a7
63 set DOC=yes
64 goto :a1
65 :a7
66 if not (%1)==() goto :usage
68 if not "%CC%"=="@call :cl" goto :p1
69 set VSCOMNTOOLS=%VS150COMNTOOLS%
70 if "%VSCOMNTOOLS%"=="" set VSCOMNTOOLS=%VS140COMNTOOLS%
71 if "%VSCOMNTOOLS%"=="" set VSCOMNTOOLS=%VS130COMNTOOLS%
72 if "%VSCOMNTOOLS%"=="" set VSCOMNTOOLS=%VS120COMNTOOLS%
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
76 if %CLVARS%_==_ goto :p1
77 if exist %CLVARS% call %CLVARS%
78 :p1
80 if not %T%_==_ goto :p2
81 set T=32
82 if %PROCESSOR_ARCHITECTURE%_==AMD64_ set T=64
83 if %PROCESSOR_ARCHITEW6432%_==AMD64_ set T=64
84 :p2
86 set D32=-DTCC_TARGET_PE -DTCC_TARGET_I386
87 set D64=-DTCC_TARGET_PE -DTCC_TARGET_X86_64
88 set P32=i386-win32
89 set P64=x86_64-win32
90 if %T%==64 goto :t64
91 set D=%D32%
92 set DX=%D64%
93 set PX=%P64%
94 goto :t96
95 :t64
96 set D=%D64%
97 set DX=%D32%
98 set PX=%P32%
99 :t96
101 @echo on
103 :config.h
104 echo>..\config.h #define TCC_VERSION "%VERSION%"
105 echo>> ..\config.h #ifdef TCC_TARGET_X86_64
106 echo>> ..\config.h #define TCC_LIBTCC1 "libtcc1-64.a"
107 echo>> ..\config.h #else
108 echo>> ..\config.h #define TCC_LIBTCC1 "libtcc1-32.a"
109 echo>> ..\config.h #endif
111 for %%f in (*tcc.exe *tcc.dll) do @del %%f
113 :compiler
114 %CC% -o libtcc.dll -shared ..\libtcc.c %D% -DLIBTCC_AS_DLL
115 @if errorlevel 1 goto :the_end
116 %CC% -o tcc.exe ..\tcc.c libtcc.dll %D% -DONE_SOURCE"=0"
117 %CC% -o %PX%-tcc.exe ..\tcc.c %DX%
119 @if (%TCC_FILES%)==(no) goto :files-done
121 if not exist libtcc mkdir libtcc
122 if not exist doc mkdir doc
123 copy>nul ..\include\*.h include
124 copy>nul ..\tcclib.h include
125 copy>nul ..\libtcc.h libtcc
126 copy>nul ..\tests\libtcc_test.c examples
127 copy>nul tcc-win32.txt doc
129 .\tcc -impdef libtcc.dll -o libtcc\libtcc.def
130 @if errorlevel 1 goto :the_end
132 :libtcc1.a
133 @set O1=libtcc1.o crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o chkstk.o bcheck.o
134 .\tcc -m32 -c ../lib/libtcc1.c
135 .\tcc -m32 -c lib/crt1.c
136 .\tcc -m32 -c lib/crt1w.c
137 .\tcc -m32 -c lib/wincrt1.c
138 .\tcc -m32 -c lib/wincrt1w.c
139 .\tcc -m32 -c lib/dllcrt1.c
140 .\tcc -m32 -c lib/dllmain.c
141 .\tcc -m32 -c lib/chkstk.S
142 .\tcc -m32 -w -c ../lib/bcheck.c
143 .\tcc -m32 -c ../lib/alloca86.S
144 .\tcc -m32 -c ../lib/alloca86-bt.S
145 .\tcc -m32 -ar lib/libtcc1-32.a %O1% alloca86.o alloca86-bt.o
146 @if errorlevel 1 goto :the_end
147 .\tcc -m64 -c ../lib/libtcc1.c
148 .\tcc -m64 -c lib/crt1.c
149 .\tcc -m64 -c lib/crt1w.c
150 .\tcc -m64 -c lib/wincrt1.c
151 .\tcc -m64 -c lib/wincrt1w.c
152 .\tcc -m64 -c lib/dllcrt1.c
153 .\tcc -m64 -c lib/dllmain.c
154 .\tcc -m64 -c lib/chkstk.S
155 .\tcc -m64 -w -c ../lib/bcheck.c
156 .\tcc -m64 -c ../lib/alloca86_64.S
157 .\tcc -m64 -c ../lib/alloca86_64-bt.S
158 .\tcc -m64 -ar lib/libtcc1-64.a %O1% alloca86_64.o alloca86_64-bt.o
159 @if errorlevel 1 goto :the_end
161 :tcc-doc.html
162 @if not (%DOC%)==(yes) goto :doc-done
163 echo>..\config.texi @set VERSION %VERSION%
164 cmd /c makeinfo --html --no-split ../tcc-doc.texi -o doc/tcc-doc.html
165 :doc-done
167 :files-done
168 for %%f in (*.o *.def) do @del %%f
170 :copy-install
171 @if (%INST%)==() goto :the_end
172 if not exist %INST% mkdir %INST%
173 @if not exist %INST%\lib mkdir %INST%\lib
174 for %%f in (*tcc.exe *tcc.dll lib\*.a lib\*.def) do @copy>nul %%f %INST%\%%f
175 for %%f in (include examples libtcc doc) do @xcopy>nul /s/i/q/y %%f %INST%\%%f
177 :the_end
178 exit /B %ERRORLEVEL%