[KERNEL32] Partially sync profile.c with Wine Staging 1.7.55. Fixes 2 kernel32:profil...
[reactos.git] / reactos / 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 endlocal
19 exit /b
20 )
21
22 REM Special case %1 = arm_hosttools %2 = vcvarsall.bat %3 = %CMAKE_GENERATOR%
23 if /I "%1" == "arm_hosttools" (
24 echo Configuring x86 host tools for ARM cross build
25
26 REM This launches %VSINSTALLDIR%VS\vcvarsall.bat
27 call %2 x86
28
29 REM Configure host tools for x86
30 cmake -G %3 -DARCH:STRING=i386 %~dp0
31 exit
32 )
33
34 REM Get the source root directory
35 set REACTOS_SOURCE_DIR=%~dp0
36
37 REM Set default generator
38 set CMAKE_GENERATOR="Ninja"
39 set CMAKE_GENERATOR_HOST=!CMAKE_GENERATOR!
40
41 REM Detect presence of cmake
42 cmd /c cmake --version 2>&1 | find "cmake version" > NUL || goto cmake_notfound
43
44 REM Detect build environment (MinGW, VS, WDK, ...)
45 if defined ROS_ARCH (
46 echo Detected RosBE for %ROS_ARCH%
47 set BUILD_ENVIRONMENT=MinGW
48 set ARCH=%ROS_ARCH%
49 set MINGW_TOOCHAIN_FILE=toolchain-gcc.cmake
50
51 ) else if defined VCINSTALLDIR (
52 REM VS command prompt does not put this in environment vars
53 cl 2>&1 | find "x86" > NUL && set ARCH=i386
54 cl 2>&1 | find "x64" > NUL && set ARCH=amd64
55 cl 2>&1 | find "ARM" > NUL && set ARCH=arm
56 cl 2>&1 | find "15.00." > NUL && set VS_VERSION=9
57 cl 2>&1 | find "16.00." > NUL && set VS_VERSION=10
58 cl 2>&1 | find "17.00." > NUL && set VS_VERSION=11
59 cl 2>&1 | find "18.00." > NUL && set VS_VERSION=12
60 cl 2>&1 | find "19.00." > NUL && set VS_VERSION=14
61 if not defined VS_VERSION (
62 echo Error: Visual Studio version too old or version detection failed.
63 endlocal
64 exit /b
65 )
66 set BUILD_ENVIRONMENT=VS
67 set VS_SOLUTION=0
68 set VS_RUNTIME_CHECKS=0
69 echo Detected Visual Studio Environment !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
70 ) else (
71 echo Error: Unable to detect build environment. Configure script failure.
72 endlocal
73 exit /b
74 )
75
76 REM Checkpoint
77 if not defined ARCH (
78 echo Unknown build architecture
79 endlocal
80 exit /b
81 )
82
83 set NEW_STYLE_BUILD=1
84
85 REM Parse command line parameters
86 :repeat
87 if /I "%1%" == "-DNEW_STYLE_BUILD" (
88 set NEW_STYLE_BUILD=%2
89 ) else if "%BUILD_ENVIRONMENT%" == "MinGW" (
90 if /I "%1" == "Codeblocks" (
91 set CMAKE_GENERATOR="CodeBlocks - MinGW Makefiles"
92 ) else if /I "%1" == "Eclipse" (
93 set CMAKE_GENERATOR="Eclipse CDT4 - MinGW Makefiles"
94 ) else if /I "%1" == "Makefiles" (
95 set CMAKE_GENERATOR="MinGW Makefiles"
96 ) else if /I "%1" == "clang" (
97 set MINGW_TOOCHAIN_FILE=toolchain-clang.cmake
98 ) else (
99 goto continue
100 )
101 ) else (
102 if /I "%1" == "CodeBlocks" (
103 set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
104 ) else if /I "%1" == "Eclipse" (
105 set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
106 ) else if /I "%1" == "Makefiles" (
107 set CMAKE_GENERATOR="NMake Makefiles"
108 ) else if /I "%1" == "VSSolution" (
109 set VS_SOLUTION=1
110 if "!VS_VERSION!" == "9" (
111 if "!ARCH!" == "amd64" (
112 set CMAKE_GENERATOR="Visual Studio 9 2008 Win64"
113 ) else (
114 set CMAKE_GENERATOR="Visual Studio 9 2008"
115 )
116 ) else if "!VS_VERSION!" == "10" (
117 if "!ARCH!" == "amd64" (
118 set CMAKE_GENERATOR="Visual Studio 10 Win64"
119 ) else (
120 set CMAKE_GENERATOR="Visual Studio 10"
121 )
122 ) else if "!VS_VERSION!" == "11" (
123 if "!ARCH!" == "amd64" (
124 set CMAKE_GENERATOR="Visual Studio 11 Win64"
125 ) else if "!ARCH!" == "arm" (
126 set CMAKE_GENERATOR="Visual Studio 11 ARM"
127 set CMAKE_GENERATOR_HOST="Visual Studio 11"
128 ) else (
129 set CMAKE_GENERATOR="Visual Studio 11"
130 )
131 ) else if "!VS_VERSION!" == "12" (
132 if "!ARCH!" == "amd64" (
133 set CMAKE_GENERATOR="Visual Studio 12 Win64"
134 ) else if "!ARCH!" == "arm" (
135 set CMAKE_GENERATOR="Visual Studio 12 ARM"
136 set CMAKE_GENERATOR_HOST="Visual Studio 12"
137 ) else (
138 set CMAKE_GENERATOR="Visual Studio 12"
139 )
140 ) else if "!VS_VERSION!" == "14" (
141 if "!ARCH!" == "amd64" (
142 set CMAKE_GENERATOR="Visual Studio 14 Win64"
143 ) else if "!ARCH!" == "arm" (
144 set CMAKE_GENERATOR="Visual Studio 14 ARM"
145 set CMAKE_GENERATOR_HOST="Visual Studio 14"
146 ) else (
147 set CMAKE_GENERATOR="Visual Studio 14"
148 )
149 )
150 ) else if /I "%1" == "RTC" (
151 echo Runtime checks enabled
152 set VS_RUNTIME_CHECKS=1
153 ) else (
154 goto continue
155 )
156 )
157
158 REM Go to next parameter
159 SHIFT
160 goto repeat
161 :continue
162
163 REM Inform the user about the default build
164 if "!CMAKE_GENERATOR!" == "Ninja" (
165 echo This script defaults to Ninja. Type "configure help" for alternative options.
166 )
167
168 REM Create directories
169 set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%
170 if "%REACTOS_SOURCE_DIR%" == "%CD%\" (
171 echo Creating directories in %REACTOS_OUTPUT_PATH%
172
173 if not exist %REACTOS_OUTPUT_PATH% (
174 mkdir %REACTOS_OUTPUT_PATH%
175 )
176 cd %REACTOS_OUTPUT_PATH%
177 )
178
179 if "%NEW_STYLE_BUILD%"=="0" (
180
181 if not exist host-tools (
182 mkdir host-tools
183 )
184
185 if not exist reactos (
186 mkdir reactos
187 )
188
189 echo Preparing host tools...
190 cd host-tools
191 if EXIST CMakeCache.txt (
192 del CMakeCache.txt /q
193 )
194
195 set REACTOS_BUILD_TOOLS_DIR=!CD!
196
197 REM Use x86 for ARM host tools
198 if "%ARCH%" == "arm" (
199 REM Launch new script instance for x86 host tools configuration
200 start "Preparing host tools for ARM cross build..." /I /B /WAIT %~dp0configure.cmd arm_hosttools "%VSINSTALLDIR%VC\vcvarsall.bat" %CMAKE_GENERATOR_HOST%
201 ) else (
202 cmake -G %CMAKE_GENERATOR% -DARCH:STRING=%ARCH% "%REACTOS_SOURCE_DIR%"
203 )
204
205 cd..
206
207 )
208
209 echo Preparing reactos...
210
211 if "%NEW_STYLE_BUILD%"=="0" (
212 cd reactos
213 )
214
215 if EXIST CMakeCache.txt (
216 del CMakeCache.txt /q
217 )
218
219 if "%NEW_STYLE_BUILD%"=="0" (
220 set BUILD_TOOLS_FLAG=-DREACTOS_BUILD_TOOLS_DIR:PATH="%REACTOS_BUILD_TOOLS_DIR%"
221 )
222
223 if "%BUILD_ENVIRONMENT%" == "MinGW" (
224 cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE:BOOL=0 -DCMAKE_TOOLCHAIN_FILE:FILEPATH=%MINGW_TOOCHAIN_FILE% -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %* "%REACTOS_SOURCE_DIR%"
225 ) else (
226 cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% -DRUNTIME_CHECKS:BOOL=%VS_RUNTIME_CHECKS% %* "%REACTOS_SOURCE_DIR%"
227 )
228
229 if "%NEW_STYLE_BUILD%"=="0" (
230 cd..
231 )
232
233 echo Configure script complete^^! Execute appropriate build commands (ex: ninja, make, nmake, etc...).
234 endlocal
235 exit /b
236
237 :cmake_notfound
238 echo Unable to find cmake, if it is installed, check your PATH variable.
239 endlocal
240 exit /b