[SHELL][COMCTL32] pt_PT_Translation Improvements
[reactos.git] / configure.cmd
1 @echo off
2
3 REM This is needed so as to avoid static expansion of environment variables
4 REM inside if (...) conditionals.
5 REM See http://stackoverflow.com/questions/305605/weird-scope-issue-in-bat-file
6 REM for more explanation.
7 REM Precisely needed for configuring Visual Studio Environment.
8 setlocal enabledelayedexpansion
9
10 REM Does the user need help?
11 if /I "%1" == "help" goto help
12 if /I "%1" == "/?" (
13 :help
14 echo Help for configure script
15 echo Syntax: path\to\source\configure.cmd [script-options] [Cmake-options]
16 echo Available script-options: Codeblocks, Eclipse, Makefiles, clang, VSSolution, RTC
17 echo Cmake-options: -DVARIABLE:TYPE=VALUE
18 goto quit
19 )
20
21 REM Special case %1 = arm_hosttools %2 = vcvarsall.bat %3 = %CMAKE_GENERATOR%
22 if /I "%1" == "arm_hosttools" (
23 echo Configuring x86 host tools for ARM cross build
24
25 REM This launches %VSINSTALLDIR%VS\vcvarsall.bat
26 call %2 x86
27
28 REM Configure host tools for x86.
29 cmake -G %3 -A Win32 -DARCH:STRING=i386 %~dp0
30 exit
31 )
32
33 REM Get the source root directory
34 set REACTOS_SOURCE_DIR=%~dp0
35
36 REM Ensure there's no spaces in the source path
37 echo %REACTOS_SOURCE_DIR%| find " " > NUL
38 if %ERRORLEVEL% == 0 (
39 echo. && echo Your source path contains at least one space.
40 echo This will cause problems with building.
41 echo Please rename your folders so there are no spaces in the source path,
42 echo or move your source to a different folder.
43 goto quit
44 )
45
46 REM Set default generator
47 set CMAKE_GENERATOR="Ninja"
48 set CMAKE_ARCH=
49
50 REM Detect presence of cmake
51 cmd /c cmake --version 2>&1 | find "cmake version" > NUL || goto cmake_notfound
52
53 REM Detect build environment (MinGW, VS, WDK, ...)
54 if defined ROS_ARCH (
55 echo Detected RosBE for %ROS_ARCH%
56 set BUILD_ENVIRONMENT=MinGW
57 set ARCH=%ROS_ARCH%
58 set MINGW_TOOCHAIN_FILE=toolchain-gcc.cmake
59
60 ) else if defined VCINSTALLDIR (
61 REM VS command prompt does not put this in environment vars
62 cl 2>&1 | find "x86" > NUL && set ARCH=i386
63 cl 2>&1 | find "x64" > NUL && set ARCH=amd64
64 cl 2>&1 | find "ARM" > NUL && set ARCH=arm
65 cl 2>&1 | find "16.00." > NUL && set VS_VERSION=10
66 cl 2>&1 | find "17.00." > NUL && set VS_VERSION=11
67 cl 2>&1 | find "18.00." > NUL && set VS_VERSION=12
68 cl 2>&1 | find "19.00." > NUL && set VS_VERSION=14
69 cl 2>&1 | find "19.10." > NUL && set VS_VERSION=15
70 cl 2>&1 | find "19.11." > NUL && set VS_VERSION=15
71 cl 2>&1 | find "19.12." > NUL && set VS_VERSION=15
72 cl 2>&1 | find "19.13." > NUL && set VS_VERSION=15
73 cl 2>&1 | find "19.14." > NUL && set VS_VERSION=15
74 cl 2>&1 | find "19.15." > NUL && set VS_VERSION=15
75 cl 2>&1 | find "19.16." > NUL && set VS_VERSION=15
76 cl 2>&1 | find "19.20." > NUL && set VS_VERSION=16
77 cl 2>&1 | find "19.21." > NUL && set VS_VERSION=16
78 cl 2>&1 | find "19.22." > NUL && set VS_VERSION=16
79 if not defined VS_VERSION (
80 echo Error: Visual Studio version too old ^(before 10 ^(2010^)^) or version detection failed.
81 goto quit
82 )
83 set BUILD_ENVIRONMENT=VS
84 set VS_SOLUTION=0
85 set VS_RUNTIME_CHECKS=0
86 echo Detected Visual Studio Environment !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
87 ) else (
88 echo Error: Unable to detect build environment. Configure script failure.
89 goto quit
90 )
91
92 REM Checkpoint
93 if not defined ARCH (
94 echo Unknown build architecture
95 goto quit
96 )
97
98 set NEW_STYLE_BUILD=1
99 set USE_CLANG_CL=0
100
101 REM Parse command line parameters
102 :repeat
103 if /I "%1" == "-DNEW_STYLE_BUILD" (
104 set NEW_STYLE_BUILD=%2
105 ) else if "%BUILD_ENVIRONMENT%" == "MinGW" (
106 if /I "%1" == "Codeblocks" (
107 set CMAKE_GENERATOR="CodeBlocks - MinGW Makefiles"
108 ) else if /I "%1" == "Eclipse" (
109 set CMAKE_GENERATOR="Eclipse CDT4 - MinGW Makefiles"
110 ) else if /I "%1" == "Makefiles" (
111 set CMAKE_GENERATOR="MinGW Makefiles"
112 ) else if /I "%1" == "VSSolution" (
113 echo. && echo Error: Creation of VS Solution files is not supported in a MinGW environment.
114 echo Please run this command in a [Developer] Command Prompt for Visual Studio.
115 goto quit
116 ) else if /I "%1" == "RTC" (
117 echo. && echo Warning: RTC switch is ignored outside of a Visual Studio environment. && echo.
118 ) else if /I "%1" NEQ "" (
119 echo %1| find /I "-D" > NUL
120 if %ERRORLEVEL% == 0 (
121 REM User is passing a switch to CMake
122 REM Ignore it, and ignore the next parameter that follows
123 Shift
124 ) else (
125 echo. && echo Warning: Unrecognized switch "%1" && echo.
126 )
127 ) else (
128 goto continue
129 )
130 ) else (
131 if /I "%1" == "CodeBlocks" (
132 set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
133 ) else if /I "%1" == "Eclipse" (
134 set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
135 ) else if /I "%1" == "Makefiles" (
136 set CMAKE_GENERATOR="NMake Makefiles"
137 ) else if /I "%1" == "clang" (
138 set USE_CLANG_CL=1
139 ) else if /I "%1" == "VSSolution" (
140 set VS_SOLUTION=1
141 REM explicitly set VS version for project generator
142 if /I "%2" == "-VS_VER" (
143 set VS_VERSION=%3
144 echo Visual Studio Environment set to !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
145 )
146 set CMAKE_GENERATOR="Visual Studio !VS_VERSION!"
147 if "!ARCH!" == "i386" (
148 set CMAKE_ARCH=-A Win32
149 ) else if "!ARCH!" == "amd64" (
150 set CMAKE_ARCH=-A x64
151 ) else if "!ARCH!" == "arm" (
152 set CMAKE_ARCH=-A ARM
153 )
154 ) else if /I "%1" == "RTC" (
155 echo Runtime checks enabled
156 set VS_RUNTIME_CHECKS=1
157 ) else if /I "%1" NEQ "" (
158 echo %1| find /I "-D" > NUL
159 if %ERRORLEVEL% == 0 (
160 REM User is passing a switch to CMake
161 REM Ignore it, and ignore the next parameter that follows
162 Shift
163 ) else (
164 echo. && echo Warning: Unrecognized switch "%1" && echo.
165 )
166 ) else (
167 goto continue
168 )
169 )
170
171 REM Go to next parameter
172 SHIFT
173 goto repeat
174 :continue
175
176 REM Inform the user about the default build
177 if "!CMAKE_GENERATOR!" == "Ninja" (
178 echo This script defaults to Ninja. Type "configure help" for alternative options.
179 )
180
181 REM Create directories
182 set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%
183
184 if "%VS_SOLUTION%" == "1" (
185 set REACTOS_OUTPUT_PATH=%REACTOS_OUTPUT_PATH%-sln
186 )
187
188 if "%REACTOS_SOURCE_DIR%" == "%CD%\" (
189 set CD_SAME_AS_SOURCE=1
190 echo Creating directories in %REACTOS_OUTPUT_PATH%
191
192 if not exist %REACTOS_OUTPUT_PATH% (
193 mkdir %REACTOS_OUTPUT_PATH%
194 )
195 cd %REACTOS_OUTPUT_PATH%
196 )
197
198 if "%VS_SOLUTION%" == "1" (
199
200 if exist build.ninja (
201 echo. && echo Error: This directory has already been configured for ninja.
202 echo An output folder configured for ninja can't be reconfigured for VSSolution.
203 echo Use an empty folder or delete the contents of this folder, then try again.
204 goto quit
205 )
206 ) else if exist REACTOS.sln (
207 echo. && echo Error: This directory has already been configured for Visual Studio.
208 echo An output folder configured for VSSolution can't be reconfigured for ninja.
209 echo Use an empty folder or delete the contents of this folder, then try again. && echo.
210 goto quit
211 )
212
213 if "%NEW_STYLE_BUILD%"=="0" (
214
215 if not exist host-tools (
216 mkdir host-tools
217 )
218
219 if not exist reactos (
220 mkdir reactos
221 )
222
223 echo Preparing host tools...
224 cd host-tools
225 if EXIST CMakeCache.txt (
226 del CMakeCache.txt /q
227 )
228
229 set REACTOS_BUILD_TOOLS_DIR=!CD!
230
231 REM Use x86 for ARM host tools
232 if "%ARCH%" == "arm" (
233 REM Launch new script instance for x86 host tools configuration
234 start "Preparing host tools for ARM cross build..." /I /B /WAIT %~dp0configure.cmd arm_hosttools "%VSINSTALLDIR%VC\vcvarsall.bat" %CMAKE_GENERATOR%
235 ) else (
236 cmake -G %CMAKE_GENERATOR% %CMAKE_ARCH% -DARCH:STRING=%ARCH% "%REACTOS_SOURCE_DIR%"
237 )
238
239 cd..
240
241 )
242
243 echo Preparing reactos...
244
245 if "%NEW_STYLE_BUILD%"=="0" (
246 cd reactos
247 )
248
249 if EXIST CMakeCache.txt (
250 del CMakeCache.txt /q
251 del host-tools\CMakeCache.txt /q
252 )
253
254 if "%NEW_STYLE_BUILD%"=="0" (
255 set BUILD_TOOLS_FLAG=-DREACTOS_BUILD_TOOLS_DIR:PATH="%REACTOS_BUILD_TOOLS_DIR%"
256 )
257
258 if "%BUILD_ENVIRONMENT%" == "MinGW" (
259 cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE:BOOL=0 -DCMAKE_TOOLCHAIN_FILE:FILEPATH=%MINGW_TOOCHAIN_FILE% -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %* "%REACTOS_SOURCE_DIR%"
260 ) else if %USE_CLANG_CL% == 1 (
261 cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% -DUSE_CLANG_CL:BOOL=1 -DRUNTIME_CHECKS:BOOL=%VS_RUNTIME_CHECKS% %* "%REACTOS_SOURCE_DIR%"
262 ) else (
263 cmake -G %CMAKE_GENERATOR% %CMAKE_ARCH% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% -DRUNTIME_CHECKS:BOOL=%VS_RUNTIME_CHECKS% %* "%REACTOS_SOURCE_DIR%"
264 )
265
266 if "%NEW_STYLE_BUILD%"=="0" (
267 cd..
268 )
269
270 if %ERRORLEVEL% NEQ 0 (
271 goto quit
272 )
273
274 if "%CD_SAME_AS_SOURCE%" == "1" (
275 set ENDV= from %REACTOS_OUTPUT_PATH%
276 )
277
278 if "%VS_SOLUTION%" == "1" (
279 set ENDV= You can now use msbuild or open REACTOS.sln%ENDV%.
280 ) else (
281 set ENDV= Execute appropriate build commands ^(ex: ninja, make, nmake, etc...^)%ENDV%
282 )
283
284 echo. && echo Configure script complete^^!%ENDV%
285
286 goto quit
287
288 :cmake_notfound
289 echo Unable to find cmake, if it is installed, check your PATH variable.
290
291 :quit
292 endlocal
293 exit /b