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