@ECHO OFF
::
:: build-all-msvc.bat --
::
:: Multi-Platform Build Tool for MSVC
::
REM
REM This batch script is used to build the SQLite DLL for multiple platforms
REM and configurations using MSVC. The built SQLite DLLs, their associated
REM import libraries, and optionally their symbols files, are placed within
REM the directory specified on the command line, in sub-directories named for
REM their respective platforms and configurations. This batch script must be
REM run from inside a Visual Studio Command Prompt for the desired version of
REM Visual Studio ^(the initial platform configured for the command prompt does
REM not really matter^). Exactly one command line argument is required, the
REM name of an existing directory to be used as the final destination directory
REM for the generated output files, which will be placed in sub-directories
REM created therein. Ideally, the directory specified should be empty.
REM
REM Example:
REM
REM CD /D C:\dev\sqlite\core
REM CALL tool\build-all-msvc.bat C:\Temp
REM
REM In the example above, "C:\dev\sqlite\core" represents the root of the
REM source tree for SQLite and "C:\Temp" represents the final destination
REM directory for the generated output files.
REM
REM Please note that the SQLite build process performed by the Makefile
REM associated with this batch script requires a Tcl shell to be present
REM in a directory contained in the PATH environment variable unless a
REM pre-existing amalgamation file is used.
REM
REM There are several environment variables that may be set to modify the
REM behavior of this batch script and its associated Makefile. The list of
REM platforms to build may be overriden by using the PLATFORMS environment
REM variable, which should contain a list of platforms ^(e.g. x86 x86_amd64
REM x86_arm^). All platforms must be supported by the version of Visual Studio
REM being used. The list of configurations to build may be overridden by
REM setting the CONFIGURATIONS environment variable, which should contain a
REM list of configurations to build ^(e.g. Debug Retail^). Neither of these
REM variable values may contain any double quotes, surrounding or embedded.
REM
REM Finally, the NCRTLIBPATH, NUCRTLIBPATH, and NSDKLIBPATH environment
REM variables may be set to specify the location of the CRT, Universal CRT, and
REM Windows SDK, respectively, that may be needed to compile executables native
REM to the architecture of the build machine during any cross-compilation that
REM may be necessary, depending on the platforms to be built. These values in
REM these three variables should be surrounded by double quotes if they contain
REM spaces.
REM
REM There are a few other environment variables that impact the build process
REM when set ^(to anything^), they are:
REM
REM USE_AUTOCONF_MAKEFILE
REM
REM When set, the "autoconf" Makefile for MSVC will be used instead of the main
REM Makefile for MSVC. It must exist at "%ROOT%\autoconf\Makefile.msc".
REM
REM NOCLEAN
REM
REM When set, the "clean" target will not be used during each build iteration.
REM However, the target binaries, if any, will still be deleted manually prior
REM to being rebuilt. Setting this environment variable is only rarely needed
REM and could cause issues in some circumstances; therefore, setting it is not
REM recommended.
REM
REM NOSYMBOLS
REM
REM When set, copying of symbol files ^(*.pdb^) created during the build will
REM be skipped and they will not appear in the final destination directory.
REM Setting this environment variable is never strictly needed and could cause
REM issues in some circumstances; therefore, setting it is not recommended.
REM
REM NOMEMDEBUG
REM
REM When set, disables use of MEMDEBUG when building binaries for the "Debug"
REM configuration.
REM
REM BUILD_ALL_SHELL
REM
REM When set, the command line shell will be built for each selected platform
REM and configuration as well. In addition, the command line shell binaries
REM will be copied, with their symbols, to the final destination directory.
REM
REM USE_WINV63_NSDKLIBPATH
REM
REM When set, modifies how the NSDKLIBPATH environment variable is built, based
REM on the WindowsSdkDir environment variable. It forces this batch script to
REM assume the Windows 8.1 SDK location should be used.
REM
REM USE_WINV100_NSDKLIBPATH
REM
REM When set, modifies how the NSDKLIBPATH environment variable is built, based
REM on the WindowsSdkDir environment variable. It causes this batch script to
REM assume the Windows 10.0 SDK location should be used.
REM
REM NMAKE_ARGS
REM NMAKE_ARGS_DEBUG
REM NMAKE_ARGS_RETAIL
REM
REM When set, these values are expanded and passed to the NMAKE command line,
REM after its other arguments. These may be used to specify additional NMAKE
REM options, for example:
REM
REM SET NMAKE_ARGS=FOR_WINRT=1
REM SET NMAKE_ARGS_DEBUG=MEMDEBUG=1
REM SET NMAKE_ARGS_RETAIL=WIN32HEAP=1
REM
REM Using the above command before running this tool will cause the compiled
REM binaries to target the WinRT environment, which provides a subset of the
REM Win32 API.
REM
REM DLL_FILE_NAME
REM DLL_PDB_FILE_NAME
REM LIB_FILE_NAME
REM EXE_FILE_NAME
REM EXE_PDB_FILE_NAME
REM
REM When set, these values will override the associated target file name used
REM for the build.
REM
SETLOCAL
REM SET __ECHO=ECHO
REM SET __ECHO2=ECHO
REM SET __ECHO3=ECHO
IF NOT DEFINED _AECHO
IF NOT DEFINED _CECHO
IF NOT DEFINED _CECHO2
IF NOT DEFINED _CECHO3
IF NOT DEFINED _VECHO
SET REDIRECT=^>
IF DEFINED __ECHO SET REDIRECT=^^^>
%_AECHO% Running %0 %*
REM SET DFLAGS=/L
%_VECHO% DFlags = '%DFLAGS%'
SET FFLAGS=/V /F /G /H /I /R /Y /Z
%_VECHO% FFlags = '%FFLAGS%'
SET ROOT=%~dp0\..
SET ROOT=%ROOT:%
%_VECHO% Root = '%ROOT%'
REM
REM NOTE: The first and only argument to this batch file should be the output
REM directory where the platform-specific binary directories should be
REM created.
REM
SET BINARYDIRECTORY=%1
IF NOT DEFINED BINARYDIRECTORY
%_VECHO% BinaryDirectory = '%BINARYDIRECTORY%'
SET DUMMY=%2
IF DEFINED DUMMY
REM
REM NOTE: From this point, we need a clean error level. Reset it now.
REM
CALL :fn_ResetErrorLevel
REM
REM NOTE: Change the current directory to the root of the source tree, saving
REM the current directory on the directory stack.
REM
%_CECHO2% PUSHD "%ROOT%"
%__ECHO2% PUSHD "%ROOT%"
IF ERRORLEVEL 1
REM
REM NOTE: This batch file requires the ComSpec environment variable to be set,
REM typically to something like "C:\Windows\System32\cmd.exe".
REM
IF NOT DEFINED ComSpec
REM
REM NOTE: This batch file requires the VcInstallDir environment variable to be
REM set. Tyipcally, this means this batch file needs to be run from an
REM MSVC command prompt.
REM
IF NOT DEFINED VCINSTALLDIR
REM
REM NOTE: If the list of platforms is not already set, use the default list.
REM
IF NOT DEFINED PLATFORMS
%_VECHO% Platforms = '%PLATFORMS%'
REM
REM NOTE: If the list of configurations is not already set, use the default
REM list.
REM
IF NOT DEFINED CONFIGURATIONS
%_VECHO% Configurations = '%CONFIGURATIONS%'
REM
REM NOTE: If the command used to invoke NMAKE is not already set, use the
REM default.
REM
IF NOT DEFINED NMAKE_CMD
%_VECHO% NmakeCmd = '%NMAKE_CMD%'
%_VECHO% NmakeArgs = '%NMAKE_ARGS%'
%_VECHO% NmakeArgsDebug = '%NMAKE_ARGS_DEBUG%'
%_VECHO% NmakeArgsRetail = '%NMAKE_ARGS_RETAIL%'
REM
REM NOTE: Setup environment variables to translate between the MSVC platform
REM names and the names to be used for the platform-specific binary
REM directories.
REM
SET amd64_NAME=x64
SET arm_NAME=ARM
SET x64_NAME=x64
SET x86_NAME=x86
SET x86_amd64_NAME=x64
SET x86_arm_NAME=ARM
SET x86_x64_NAME=x64
%_VECHO% amd64_Name = '%amd64_NAME%'
%_VECHO% arm_Name = '%arm_NAME%'
%_VECHO% x64_Name = '%x64_NAME%'
%_VECHO% x86_Name = '%x86_NAME%'
%_VECHO% x86_amd64_Name = '%x86_amd64_NAME%'
%_VECHO% x86_arm_Name = '%x86_arm_NAME%'
%_VECHO% x86_x64_Name = '%x86_x64_NAME%'
REM
REM NOTE: Check for the external tools needed during the build process ^(i.e.
REM those that do not get compiled as part of the build process itself^)
REM along the PATH.
REM
IF DEFINED TCLSH_CMD ELSE
FOR %%T IN DO
REM
REM NOTE: A Tcl shell executable is required during the SQLite build process
REM unless a pre-existing amalgamation file is used.
REM
IF NOT DEFINED %TCLSH_FILE%_PATH
REM
REM NOTE: Setup the default names for the build targets we are creating. Any
REM ^(or all^) of these may end up being overridden.
REM
IF NOT DEFINED DLL_FILE_NAME
IF NOT DEFINED DLL_PDB_FILE_NAME
IF NOT DEFINED LIB_FILE_NAME
IF NOT DEFINED EXE_FILE_NAME
IF NOT DEFINED EXE_PDB_FILE_NAME
REM
REM NOTE: Set the TOOLPATH variable to contain all the directories where the
REM external tools were found in the search above.
REM
CALL :fn_CopyVariable %TCLSH_FILE%_PATH TOOLPATH
%_VECHO% ToolPath = '%TOOLPATH%'
REM
REM NOTE: Setting the Windows SDK library path is only required for MSVC
REM 2012, 2013, and 2015.
REM
CALL :fn_UnsetVariable SET_NSDKLIBPATH
REM
REM NOTE: Setting the Universal CRT library path is only required for MSVC
REM 2015.
REM
CALL :fn_UnsetVariable SET_NUCRTLIBPATH
REM
REM NOTE: Check for MSVC 2012, 2013, and 2015 specially because the Windows
REM SDK directory handling is slightly different for those versions.
REM
IF "%VisualStudioVersion%" == "11.0" ELSE IF "%VisualStudioVersion%" == "12.0" ELSE IF "%VisualStudioVersion%" == "14.0"
REM
REM NOTE: This is the name of the sub-directory where the UCRT libraries may
REM be found. It is only used when compiling against the UCRT.
REM
IF DEFINED UCRTVersion ELSE
REM
REM NOTE: This is the name of the sub-directory where the Windows 10.0 SDK
REM libraries may be found. It is only used when compiling with the
REM Windows 10.0 SDK.
REM
IF DEFINED WindowsSDKLibVersion ELSE
REM
REM NOTE: Check if this is the Windows Phone SDK. If so, a different batch
REM file is necessary to setup the build environment. Since the variable
REM values involved here may contain parenthesis, using GOTO instead of
REM an IF block is required.
REM
IF DEFINED WindowsPhoneKitDir GOTO set_vcvarsall_phone
SET VCVARSALL=%VCINSTALLDIR%\vcvarsall.bat
GOTO set_vcvarsall_done
:set_vcvarsall_phone
SET VCVARSALL=%VCINSTALLDIR%\WPSDK\WP80\vcvarsphoneall.bat
:set_vcvarsall_done
SET VCVARSALL=%VCVARSALL:%
REM
REM NOTE: This is the outer loop. There should be exactly one iteration per
REM platform.
REM
FOR %%P IN DO
REM
REM NOTE: Restore the saved current directory from the directory stack.
REM
%_CECHO2% POPD
%__ECHO2% POPD
IF ERRORLEVEL 1
REM
REM NOTE: If we get to this point, we have succeeded.
REM
GOTO no_errors
:fn_MakeClean
%__ECHO% %NMAKE_CMD% clean "PLATFORM=%1" XCOMPILE=1 USE_NATIVE_LIBPATHS=1 NO_TCL=1 %NMAKE_ARGS% %NMAKE_ARGS_CFG%
GOTO :EOF
:fn_MakeDll
%__ECHO% %NMAKE_CMD% "%DLL_FILE_NAME%" "PLATFORM=%1" XCOMPILE=1 USE_NATIVE_LIBPATHS=1 NO_TCL=1 %NMAKE_ARGS% %NMAKE_ARGS_CFG%
GOTO :EOF
:fn_MakeExe
%__ECHO% %NMAKE_CMD% "%EXE_FILE_NAME%" "PLATFORM=%1" XCOMPILE=1 USE_NATIVE_LIBPATHS=1 NO_TCL=1 %NMAKE_ARGS% %NMAKE_ARGS_CFG%
GOTO :EOF
:fn_ShowVariable
SETLOCAL
SET __ECHO_CMD=ECHO %%%2%%
FOR /F "delims=" %%V IN DO
ENDLOCAL
GOTO :EOF
:fn_ResetErrorLevel
VERIFY > NUL
GOTO :EOF
:fn_SetErrorLevel
VERIFY MAYBE 2> NUL
GOTO :EOF
:fn_CopyVariable
IF NOT DEFINED %1 GOTO :EOF
IF "%2" == "" GOTO :EOF
SETLOCAL
SET __ECHO_CMD=ECHO %%%1%%
FOR /F "delims=" %%V IN DO
ENDLOCAL && SET %2=%VALUE%
GOTO :EOF
:fn_UnsetVariable
SETLOCAL
SET VALUE=%1
IF DEFINED VALUE ELSE
CALL :fn_ResetErrorLevel
GOTO :EOF
:fn_ResetPath
SET PATH=%TOOLPATH%;%SystemRoot%\System32;%SystemRoot%
GOTO :EOF
:fn_AppendVariable
SET __ECHO_CMD=ECHO %%%1%%
IF DEFINED %1 ELSE
SET __ECHO_CMD=
CALL :fn_ResetErrorLevel
GOTO :EOF
:usage
ECHO.
ECHO Usage: %~nx0 ^<binaryDirectory^>
ECHO.
GOTO errors
:errors
CALL :fn_SetErrorLevel
ENDLOCAL
ECHO.
ECHO Failure, errors were encountered.
GOTO end_of_file
:no_errors
CALL :fn_ResetErrorLevel
ENDLOCAL
ECHO.
ECHO Success, no errors were encountered.
GOTO end_of_file
:end_of_file
%__ECHO% EXIT /B %ERRORLEVEL%