* Sync to trunk HEAD (r53298).
[reactos.git] / 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 set ARCH=i386
37 set BUILD_ENVIRONMENT=VS10
38 if not defined BUILD_ENVIRONMENT (
39 echo Error: Visual Studio version too old or version detection failed.
40 exit /b
41 )
42
43 echo Detected Visual Studio Environment %BUILD_ENVIRONMENT%-%ARCH%
44 if /I "%1" == "VSSolution" (
45 set CMAKE_GENERATOR="Visual Studio 10"
46 ) else (
47 set USE_NMAKE=1
48 echo This script defaults to nmake. To use Visual Studio GUI specify "VSSolution" as a parameter.
49 )
50
51 ) else if defined sdkdir (
52 echo Detected Windows SDK %TARGET_PLATFORM%-%TARGET_CPU%
53 if "%TARGET_CPU%" == "x86" (
54 set ARCH=i386
55 ) else if "%TARGET_CPU%" == "x64" (
56 set ARCH=amd64
57 )
58
59 set BUILD_ENVIRONMENT=SDK
60 set USE_NMAKE=1
61
62 ) else (
63 echo Error: Unable to detect build environment. Configure script failure.
64 exit /b
65 )
66
67 :: Checkpoint
68 if not defined ARCH (
69 echo unknown build architecture
70 exit /b
71 )
72
73 :: Detect nmake generator
74 if %USE_NMAKE% == 1 (
75 if /I "%1" == "CodeBlocks" (
76 set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
77 ) else if /I "%1" == "Eclipse" (
78 set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
79 ) else if /I "%1" == "JOM" (
80 set CMAKE_GENERATOR="NMake Makefiles JOM"
81 ) else (
82 set CMAKE_GENERATOR="NMake Makefiles"
83 )
84 )
85
86 :: Create directories
87 set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%
88 if "%REACTOS_SOURCE_DIR%" == "%CD%\" (
89 echo Creating directories in %REACTOS_OUTPUT_PATH%
90
91 if not exist %REACTOS_OUTPUT_PATH% (
92 mkdir %REACTOS_OUTPUT_PATH%
93 )
94 cd %REACTOS_OUTPUT_PATH%
95 )
96
97 if not exist host-tools (
98 mkdir host-tools
99 )
100 if not exist reactos (
101 mkdir reactos
102 )
103
104 echo Preparing host tools...
105 cd host-tools
106 if EXIST CMakeCache.txt (
107 del CMakeCache.txt /q
108 )
109 set REACTOS_BUILD_TOOLS_DIR=%CD%
110
111 cmake -G %CMAKE_GENERATOR% -DARCH=%ARCH% %REACTOS_SOURCE_DIR%
112 cd..
113
114 echo Preparing reactos...
115 cd reactos
116 if EXIST CMakeCache.txt (
117 del CMakeCache.txt /q
118 )
119
120 if "%BUILD_ENVIRONMENT%" == "MinGW" (
121 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%
122 ) else if "%BUILD_ENVIRONMENT%" == "WDK" (
123 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%
124 ) else (
125 cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE=toolchain-msvc.cmake -DARCH=%ARCH% -DREACTOS_BUILD_TOOLS_DIR:DIR="%REACTOS_BUILD_TOOLS_DIR%" %REACTOS_SOURCE_DIR%
126 )
127
128 cd..
129
130 echo Configure script complete! Enter directories and execute appropriate build commands(ex: make, nmake, jom, etc...).
131 exit /b
132
133 :cmake_notfound
134 echo Unable to find cmake, if it is installed, check your PATH variable.
135 exit /b