Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers...
[reactos.git] / configure.cmd
diff --git a/configure.cmd b/configure.cmd
new file mode 100755 (executable)
index 0000000..270c253
--- /dev/null
@@ -0,0 +1,252 @@
+@echo off\r
+\r
+REM This is needed so as to avoid static expansion of environment variables\r
+REM inside if (...) conditionals.\r
+REM See http://stackoverflow.com/questions/305605/weird-scope-issue-in-bat-file\r
+REM for more explanation.\r
+REM Precisely needed for configuring Visual Studio Environment.\r
+setlocal enabledelayedexpansion\r
+\r
+REM Does the user need help?\r
+if /I "%1" == "help" goto help\r
+if /I "%1" == "/?" (\r
+:help\r
+    echo Help for configure script\r
+    echo Syntax: path\to\source\configure.cmd [script-options] [Cmake-options]\r
+    echo Available script-options: Codeblocks, Eclipse, Makefiles, clang, VSSolution, RTC\r
+    echo Cmake-options: -DVARIABLE:TYPE=VALUE\r
+    endlocal\r
+    exit /b\r
+)\r
+\r
+REM Special case %1 = arm_hosttools %2 = vcvarsall.bat %3 = %CMAKE_GENERATOR%\r
+if /I "%1" == "arm_hosttools" (\r
+    echo Configuring x86 host tools for ARM cross build\r
+\r
+    REM This launches %VSINSTALLDIR%VS\vcvarsall.bat\r
+    call %2 x86\r
+\r
+    REM Configure host tools for x86.\r
+    cmake -G %3 -DARCH:STRING=i386 %~dp0\r
+    exit\r
+)\r
+\r
+REM Get the source root directory\r
+set REACTOS_SOURCE_DIR=%~dp0\r
+\r
+REM Set default generator\r
+set CMAKE_GENERATOR="Ninja"\r
+set CMAKE_GENERATOR_HOST=!CMAKE_GENERATOR!\r
+\r
+REM Detect presence of cmake\r
+cmd /c cmake --version 2>&1 | find "cmake version" > NUL || goto cmake_notfound\r
+\r
+REM Detect build environment (MinGW, VS, WDK, ...)\r
+if defined ROS_ARCH (\r
+    echo Detected RosBE for %ROS_ARCH%\r
+    set BUILD_ENVIRONMENT=MinGW\r
+    set ARCH=%ROS_ARCH%\r
+    set MINGW_TOOCHAIN_FILE=toolchain-gcc.cmake\r
+\r
+) else if defined VCINSTALLDIR (\r
+    REM VS command prompt does not put this in environment vars\r
+    cl 2>&1 | find "x86" > NUL && set ARCH=i386\r
+    cl 2>&1 | find "x64" > NUL && set ARCH=amd64\r
+    cl 2>&1 | find "ARM" > NUL && set ARCH=arm\r
+    cl 2>&1 | find "15.00." > NUL && set VS_VERSION=9\r
+    cl 2>&1 | find "16.00." > NUL && set VS_VERSION=10\r
+    cl 2>&1 | find "17.00." > NUL && set VS_VERSION=11\r
+    cl 2>&1 | find "18.00." > NUL && set VS_VERSION=12\r
+    cl 2>&1 | find "19.00." > NUL && set VS_VERSION=14\r
+    cl 2>&1 | find "19.10." > NUL && set VS_VERSION=15\r
+    cl 2>&1 | find "19.11." > NUL && set VS_VERSION=15\r
+    if not defined VS_VERSION (\r
+        echo Error: Visual Studio version too old or version detection failed.\r
+        endlocal\r
+        exit /b\r
+    )\r
+    set BUILD_ENVIRONMENT=VS\r
+    set VS_SOLUTION=0\r
+    set VS_RUNTIME_CHECKS=0\r
+    echo Detected Visual Studio Environment !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!\r
+) else (\r
+    echo Error: Unable to detect build environment. Configure script failure.\r
+    endlocal\r
+    exit /b\r
+)\r
+\r
+REM Checkpoint\r
+if not defined ARCH (\r
+    echo Unknown build architecture\r
+    endlocal\r
+    exit /b\r
+)\r
+\r
+set NEW_STYLE_BUILD=1\r
+\r
+REM Parse command line parameters\r
+:repeat\r
+    if /I "%1%" == "-DNEW_STYLE_BUILD" (\r
+        set NEW_STYLE_BUILD=%2\r
+    ) else if "%BUILD_ENVIRONMENT%" == "MinGW" (\r
+        if /I "%1" == "Codeblocks" (\r
+            set CMAKE_GENERATOR="CodeBlocks - MinGW Makefiles"\r
+        ) else if /I "%1" == "Eclipse" (\r
+            set CMAKE_GENERATOR="Eclipse CDT4 - MinGW Makefiles"\r
+        ) else if /I "%1" == "Makefiles" (\r
+            set CMAKE_GENERATOR="MinGW Makefiles"\r
+        ) else if /I "%1" == "clang" (\r
+            set MINGW_TOOCHAIN_FILE=toolchain-clang.cmake\r
+        ) else (\r
+            goto continue\r
+        )\r
+    ) else (\r
+        if /I "%1" == "CodeBlocks" (\r
+            set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"\r
+        ) else if /I "%1" == "Eclipse" (\r
+            set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"\r
+        ) else if /I "%1" == "Makefiles" (\r
+            set CMAKE_GENERATOR="NMake Makefiles"\r
+        ) else if /I "%1" == "VSSolution" (\r
+            set VS_SOLUTION=1\r
+            if "!VS_VERSION!" == "9" (\r
+                if "!ARCH!" == "amd64" (\r
+                    set CMAKE_GENERATOR="Visual Studio 9 2008 Win64"\r
+                ) else (\r
+                    set CMAKE_GENERATOR="Visual Studio 9 2008"\r
+                )\r
+            ) else if "!VS_VERSION!" == "10" (\r
+                if "!ARCH!" == "amd64" (\r
+                    set CMAKE_GENERATOR="Visual Studio 10 Win64"\r
+                ) else (\r
+                    set CMAKE_GENERATOR="Visual Studio 10"\r
+                )\r
+            ) else if "!VS_VERSION!" == "11" (\r
+                if "!ARCH!" == "amd64" (\r
+                    set CMAKE_GENERATOR="Visual Studio 11 Win64"\r
+                ) else if "!ARCH!" == "arm" (\r
+                    set CMAKE_GENERATOR="Visual Studio 11 ARM"\r
+                    set CMAKE_GENERATOR_HOST="Visual Studio 11"\r
+                ) else (\r
+                    set CMAKE_GENERATOR="Visual Studio 11"\r
+                )\r
+            ) else if "!VS_VERSION!" == "12" (\r
+                if "!ARCH!" == "amd64" (\r
+                    set CMAKE_GENERATOR="Visual Studio 12 Win64"\r
+                ) else if "!ARCH!" == "arm" (\r
+                    set CMAKE_GENERATOR="Visual Studio 12 ARM"\r
+                    set CMAKE_GENERATOR_HOST="Visual Studio 12"\r
+                ) else (\r
+                    set CMAKE_GENERATOR="Visual Studio 12"\r
+                )\r
+            ) else if "!VS_VERSION!" == "14" (\r
+                if "!ARCH!" == "amd64" (\r
+                    set CMAKE_GENERATOR="Visual Studio 14 Win64"\r
+                ) else if "!ARCH!" == "arm" (\r
+                    set CMAKE_GENERATOR="Visual Studio 14 ARM"\r
+                    set CMAKE_GENERATOR_HOST="Visual Studio 14"\r
+                ) else (\r
+                    set CMAKE_GENERATOR="Visual Studio 14"\r
+                )\r
+            ) else if "!VS_VERSION!" == "15" (\r
+                if "!ARCH!" == "amd64" (\r
+                    set CMAKE_GENERATOR="Visual Studio 15 Win64"\r
+                ) else if "!ARCH!" == "arm" (\r
+                    set CMAKE_GENERATOR="Visual Studio 15 ARM"\r
+                    set CMAKE_GENERATOR_HOST="Visual Studio 15"\r
+                ) else (\r
+                    set CMAKE_GENERATOR="Visual Studio 15"\r
+                )\r
+            )\r
+        ) else if /I "%1" == "RTC" (\r
+            echo Runtime checks enabled\r
+            set VS_RUNTIME_CHECKS=1\r
+        ) else (\r
+            goto continue\r
+        )\r
+    )\r
+\r
+    REM Go to next parameter\r
+    SHIFT\r
+    goto repeat\r
+:continue\r
+\r
+REM Inform the user about the default build\r
+if "!CMAKE_GENERATOR!" == "Ninja" (\r
+    echo This script defaults to Ninja. Type "configure help" for alternative options.\r
+)\r
+\r
+REM Create directories\r
+set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%\r
+if "%REACTOS_SOURCE_DIR%" == "%CD%\" (\r
+    echo Creating directories in %REACTOS_OUTPUT_PATH%\r
+\r
+    if not exist %REACTOS_OUTPUT_PATH% (\r
+        mkdir %REACTOS_OUTPUT_PATH%\r
+    )\r
+    cd %REACTOS_OUTPUT_PATH%\r
+)\r
+\r
+if "%NEW_STYLE_BUILD%"=="0" (\r
+\r
+    if not exist host-tools (\r
+        mkdir host-tools\r
+    )\r
+\r
+    if not exist reactos (\r
+        mkdir reactos\r
+    )\r
+\r
+    echo Preparing host tools...\r
+    cd host-tools\r
+    if EXIST CMakeCache.txt (\r
+        del CMakeCache.txt /q\r
+    )\r
+\r
+    set REACTOS_BUILD_TOOLS_DIR=!CD!\r
+\r
+    REM Use x86 for ARM host tools\r
+    if "%ARCH%" == "arm" (\r
+        REM Launch new script instance for x86 host tools configuration\r
+        start "Preparing host tools for ARM cross build..." /I /B /WAIT %~dp0configure.cmd arm_hosttools "%VSINSTALLDIR%VC\vcvarsall.bat" %CMAKE_GENERATOR_HOST%\r
+    ) else (\r
+        cmake -G %CMAKE_GENERATOR% -DARCH:STRING=%ARCH% "%REACTOS_SOURCE_DIR%"\r
+    )\r
+\r
+    cd..\r
+\r
+)\r
+\r
+echo Preparing reactos...\r
+\r
+if "%NEW_STYLE_BUILD%"=="0" (\r
+    cd reactos\r
+)\r
+\r
+if EXIST CMakeCache.txt (\r
+    del CMakeCache.txt /q\r
+    del host-tools\CMakeCache.txt /q\r
+)\r
+\r
+if "%NEW_STYLE_BUILD%"=="0" (\r
+    set BUILD_TOOLS_FLAG=-DREACTOS_BUILD_TOOLS_DIR:PATH="%REACTOS_BUILD_TOOLS_DIR%"\r
+)\r
+\r
+if "%BUILD_ENVIRONMENT%" == "MinGW" (\r
+    cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE:BOOL=0 -DCMAKE_TOOLCHAIN_FILE:FILEPATH=%MINGW_TOOCHAIN_FILE% -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %* "%REACTOS_SOURCE_DIR%"\r
+) else (\r
+    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%"\r
+)\r
+\r
+if "%NEW_STYLE_BUILD%"=="0" (\r
+    cd..\r
+)\r
+\r
+echo Configure script complete^^! Execute appropriate build commands (ex: ninja, make, nmake, etc...).\r
+endlocal\r
+exit /b\r
+\r
+:cmake_notfound\r
+echo Unable to find cmake, if it is installed, check your PATH variable.\r
+endlocal\r
+exit /b\r