[SHELL32]
[reactos.git] / reactos / configure.cmd
1 @echo off
2
3 :: Get the source root directory
4 set REACTOS_SOURCE_DIR=%~dp0
5 set USE_NMAKE=0
6
7 :: Detect presence of cmake
8 cmd /c cmake --version 2>&1 | find "cmake version" > NUL || goto cmake_notfound
9
10 :: Detect build environment (MinGW, VS, WDK, ...)
11 if defined ROS_ARCH (
12 echo Detected RosBE for %ROS_ARCH%
13 set BUILD_ENVIRONMENT=MinGW
14 set ARCH=%ROS_ARCH%
15 if /I "%1" == "Codeblocks" (
16 set CMAKE_GENERATOR="CodeBlocks - MinGW Makefiles"
17 ) else if /I "%1" == "Eclipse" (
18 set CMAKE_GENERATOR="Eclipse CDT4 - MinGW Makefiles"
19 ) else (
20 set CMAKE_GENERATOR="MinGW Makefiles"
21 )
22
23 ) else if defined DDK_TARGET_OS (
24 echo Detected DDK/WDK for %DDK_TARGET_OS%-%_BUILDARCH%%
25 set BUILD_ENVIRONMENT=WDK
26 if "%_BUILDARCH%" == "x86" (
27 set ARCH=i386
28 ) else if "%_BUILDARCH%" == "AMD64" (
29 set ARCH=amd64
30 )
31 set USE_NMAKE=1
32 set USE_WDK_HEADERS=0
33
34 ) else if defined VCINSTALLDIR (
35 :: VS command prompt does not put this in enviroment vars
36 cl 2>&1 | find "x86" > NUL && set ARCH=i386
37 cl 2>&1 | find "x64" > NUL && set ARCH=amd64
38 cl 2>&1 | find "14." > NUL && set BUILD_ENVIRONMENT=VS8
39 cl 2>&1 | find "15." > NUL && set BUILD_ENVIRONMENT=VS9
40 cl 2>&1 | find "16." > NUL && set BUILD_ENVIRONMENT=VS10
41 if not defined BUILD_ENVIRONMENT (
42 echo Error: Visual Studio version too old or version detection failed.
43 exit /b
44 )
45
46 echo Detected Visual Studio Environment %BUILD_ENVIRONMENT%-%ARCH%
47 if /I "%1" == "VSSolution" (
48 if "%BUILD_ENVIRONMENT%" == "VS8" (
49 if "%ARCH%" == "amd64" (
50 set CMAKE_GENERATOR="Visual Studio 8 2005 Win64"
51 ) else (
52 set CMAKE_GENERATOR="Visual Studio 8 2005"
53 )
54 ) else if "%BUILD_ENVIRONMENT%" == "VS9" (
55 if "%ARCH%" == "amd64" (
56 set CMAKE_GENERATOR="Visual Studio 9 2008 Win64"
57 ) else (
58 set CMAKE_GENERATOR="Visual Studio 9 2008"
59 )
60 ) else if "%BUILD_ENVIRONMENT%" == "VS10" (
61 if "%ARCH%" == "amd64" (
62 set CMAKE_GENERATOR="Visual Studio 10 Win64"
63 ) else (
64 set CMAKE_GENERATOR="Visual Studio 10"
65 )
66 )
67 ) else (
68 set USE_NMAKE=1
69 echo This script defaults to nmake. To use Visual Studio GUI specify "VSSolution" as a parameter.
70 )
71
72 ) else if defined sdkdir (
73 echo Detected Windows SDK %TARGET_PLATFORM%-%TARGET_CPU%
74 if "%TARGET_CPU%" == "x86" (
75 set ARCH=i386
76 ) else if "%TARGET_CPU%" == "x64" (
77 set ARCH=amd64
78 )
79
80 set BUILD_ENVIRONMENT=SDK
81 set USE_NMAKE=1
82
83 ) else (
84 echo Error: Unable to detect build environment. Configure script failure.
85 exit /b
86 )
87
88 :: Checkpoint
89 if not defined ARCH (
90 echo unknown build architecture
91 exit /b
92 )
93
94 :: Detect nmake generator
95 if %USE_NMAKE% == 1 (
96 if /I "%1" == "CodeBlocks" (
97 set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
98 ) else if /I "%1" == "Eclipse" (
99 set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
100 ) else if /I "%1" == "JOM" (
101 set CMAKE_GENERATOR="NMake Makefiles JOM"
102 ) else (
103 set CMAKE_GENERATOR="NMake Makefiles"
104 )
105 )
106
107 :: Create directories
108 set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%
109 if "%REACTOS_SOURCE_DIR%" == "%CD%\" (
110 echo Creating directories in %REACTOS_OUTPUT_PATH%
111
112 if not exist %REACTOS_OUTPUT_PATH% (
113 mkdir %REACTOS_OUTPUT_PATH%
114 )
115 cd %REACTOS_OUTPUT_PATH%
116 )
117
118 if not exist host-tools (
119 mkdir host-tools
120 )
121 if not exist reactos (
122 mkdir reactos
123 )
124
125 echo Preparing host tools...
126 cd host-tools
127 if EXIST CMakeCache.txt (
128 del CMakeCache.txt /q
129 )
130 set REACTOS_BUILD_TOOLS_DIR=%CD%
131
132 cmake -G %CMAKE_GENERATOR% -DARCH=%ARCH% %REACTOS_SOURCE_DIR%
133 cd..
134
135 echo Preparing reactos...
136 cd reactos
137 if EXIST CMakeCache.txt (
138 del CMakeCache.txt /q
139 )
140
141 if "%BUILD_ENVIRONMENT%" == "MinGW" (
142 cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE=0 -DPCH=0 -DCMAKE_TOOLCHAIN_FILE=toolchain-gcc.cmake -DARCH=%ARCH% -DREACTOS_BUILD_TOOLS_DIR:DIR="%REACTOS_BUILD_TOOLS_DIR%" %REACTOS_SOURCE_DIR%
143 ) else if "%BUILD_ENVIRONMENT%" == "WDK" (
144 cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE=toolchain-msvc.cmake -DUSE_WDK_HEADERS=%USE_WDK_HEADERS% -DARCH=%ARCH% -DREACTOS_BUILD_TOOLS_DIR:DIR="%REACTOS_BUILD_TOOLS_DIR%" %REACTOS_SOURCE_DIR%
145 ) else (
146 cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE=toolchain-msvc.cmake -DARCH=%ARCH% -DREACTOS_BUILD_TOOLS_DIR:DIR="%REACTOS_BUILD_TOOLS_DIR%" %REACTOS_SOURCE_DIR%
147 )
148
149 cd..
150
151 echo Configure script complete! Enter directories and execute appropriate build commands(ex: make, nmake, jom, etc...).
152 exit /b
153
154 :cmake_notfound
155 echo Unable to find cmake, if it is installed, check your PATH variable.
156 exit /b