]> git.ipfire.org Git - thirdparty/make.git/commitdiff
* build_w32.bat: Support Visual Studio 17.
authorPaul Smith <psmith@gnu.org>
Sat, 10 Feb 2018 20:34:53 +0000 (15:34 -0500)
committerPaul Smith <psmith@gnu.org>
Sat, 10 Feb 2018 20:34:53 +0000 (15:34 -0500)
build_w32.bat

index 12a1d9324412860594cfa287bdd1b7d50bac8e2c..82dfc77729c9db8f7eefea8bd7c7af421194ce6b 100755 (executable)
@@ -1,26 +1,36 @@
 @echo off\r
-rem Copyright (C) 1996-2017 Free Software Foundation, Inc.\r
-rem This file is part of GNU Make.\r
-rem\r
-rem GNU Make is free software; you can redistribute it and/or modify it under\r
-rem the terms of the GNU General Public License as published by the Free\r
-rem Software Foundation; either version 3 of the License, or (at your option)\r
-rem any later version.\r
-rem\r
-rem GNU Make is distributed in the hope that it will be useful, but WITHOUT\r
-rem ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
-rem FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for.\r
-rem more details.\r
-rem\r
-rem You should have received a copy of the GNU General Public License along\r
-rem with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+:: Copyright (C) 1996-2017 Free Software Foundation, Inc.\r
+:: This file is part of GNU Make.\r
+::\r
+:: GNU Make is free software; you can redistribute it and/or modify it under\r
+:: the terms of the GNU General Public License as published by the Free\r
+:: Software Foundation; either version 3 of the License, or (at your option)\r
+:: any later version.\r
+::\r
+:: GNU Make is distributed in the hope that it will be useful, but WITHOUT\r
+:: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
+:: FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for.\r
+:: more details.\r
+::\r
+:: You should have received a copy of the GNU General Public License along\r
+:: with this program.  If not, see <http://www.gnu.org/licenses/>.\r
 \r
 setlocal\r
+if not "%RECURSEME%"=="%~0" (\r
+    set "RECURSEME=%~0"\r
+    %ComSpec% /s /c ""%~0" %*"\r
+    goto :EOF\r
+)\r
+\r
 call :Reset\r
 \r
 if "%1" == "-h" goto Usage\r
 if "%1" == "--help" goto Usage\r
 \r
+echo.\r
+echo Creating GNU Make for Windows 9X/NT/2K/XP/Vista/7/8/10\r
+echo.\r
+\r
 set MAKE=gnumake\r
 set GUILE=Y\r
 set COMPILER=cl.exe\r
@@ -38,39 +48,53 @@ goto Usage
 \r
 :SetDebug\r
 set DEBUG=Y\r
+echo - Building without compiler optimizations\r
 shift\r
 goto ParseSW\r
 \r
 :NoGuile\r
 set GUILE=N\r
-echo Building without Guile\r
+echo Building without Guile\r
 shift\r
 goto ParseSW\r
 \r
 :Set32Bit\r
 set ARCH=x86\r
+echo - Building 32bit GNU Make\r
 shift\r
 goto ParseSW\r
 \r
 :SetCC\r
 set COMPILER=gcc\r
 set O=o\r
-echo Building with GCC\r
+echo Building with GCC\r
 shift\r
 goto ParseSW\r
 \r
-rem Build with Guile is supported only on NT and later versions\r
 :DoneSW\r
-echo.\r
-echo Creating GNU Make for Windows 9X/NT/2K/XP/Vista/7/8/10\r
-if "%DEBUG%" == "Y" echo Building without compiler optimizations\r
+if "%COMPILER%" == "gcc" goto FindGcc\r
 \r
-if "%COMPILER%" == "gcc" goto GccBuild\r
-\r
-rem Make sure we can find a compiler\r
+:: Find a compiler.  Visual Studio requires a lot of effort to locate :-/.\r
 %COMPILER% >nul 2>&1\r
 if not ERRORLEVEL 1 goto FoundMSVC\r
 \r
+:: Visual Studio 17 and above provides the "vswhere" tool\r
+call :FindVswhere\r
+if ERRORLEVEL 1 goto LegacyVS\r
+\r
+for /f "tokens=* usebackq" %%i in (`%VSWHERE% -latest -property installationPath`) do (\r
+    set InstallPath=%%i\r
+)\r
+set "VSVARS=%InstallPath%\VC\Auxiliary\Build\vcvarsall.bat"\r
+call :CheckMSVC\r
+if not ERRORLEVEL 1 goto FoundMSVC\r
+\r
+:: No "vswhere" or it can't find a compiler.  Go old-school.\r
+:LegacyVS\r
+set "VSVARS=%VS150COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
+call :CheckMSVC\r
+if not ERRORLEVEL 1 goto FoundMSVC\r
+\r
 set "VSVARS=%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
 call :CheckMSVC\r
 if not ERRORLEVEL 1 goto FoundMSVC\r
@@ -115,10 +139,10 @@ set "VSVARS=%V5TOOLS%\VC\Bin\vcvars32.bat"
 call :CheckMSVC\r
 if not ERRORLEVEL 1 goto FoundMSVC\r
 \r
-rem We did not find anything--fail\r
+:: We did not find anything--fail\r
 echo No MSVC compiler available.\r
 echo Please run vcvarsall.bat and/or configure your Path.\r
-exit /b 1\r
+exit 1\r
 \r
 :FoundMSVC\r
 set OUTDIR=.\WinRel\r
@@ -127,20 +151,23 @@ set LINKOPTS=
 if "%DEBUG%" == "Y" set OUTDIR=.\WinDebug\r
 if "%DEBUG%" == "Y" set "OPTS=/Zi /Od /D _DEBUG"\r
 if "%DEBUG%" == "Y" set LINKOPTS=/DEBUG\r
-call :Build\r
-goto Done\r
+:: Show the compiler version that we found\r
+:: Unfortunately this also shows a "usage" note; I can't find anything better.\r
+echo.\r
+%COMPILER%\r
+goto Build\r
 \r
-:GccBuild\r
+:FindGcc\r
 set OUTDIR=.\GccRel\r
 set OPTS=-O2\r
 if "%DEBUG%" == "Y" set OPTS=-O0\r
 if "%DEBUG%" == "Y" set OUTDIR=.\GccDebug\r
-call :Build\r
-goto Done\r
-\r
-:Done\r
-call :Reset\r
-goto :EOF\r
+:: Show the compiler version that we found\r
+echo.\r
+%COMPILER% --version\r
+if not ERRORLEVEL 1 goto Build\r
+echo No %COMPILER% found.\r
+exit 1\r
 \r
 :Build\r
 :: Clean the directory if it exists\r
@@ -207,28 +234,41 @@ if not "%COMPILER%" == "gcc" call :Compile src\w32\compat\dirent
 call :Link\r
 \r
 echo.\r
-if not exist %OUTDIR%\%MAKE%.exe echo %OUTDIR% build FAILED!\r
-if exist %OUTDIR%\%MAKE%.exe echo %OUTDIR% build succeeded.\r
-if exist %OUTDIR%\%MAKE%.exe copy /Y Basic.mk Makefile\r
+if exist %OUTDIR%\%MAKE%.exe goto Success\r
+echo %OUTDIR% build FAILED!\r
+exit 1\r
+\r
+:Success\r
+echo %OUTDIR% build succeeded.\r
+if exist Basic.mk copy /Y Basic.mk Makefile\r
+call :Reset\r
 goto :EOF\r
 \r
+::\r
+:: Subroutines\r
+::\r
+\r
 :Compile\r
 echo %OUTDIR%\%1.%O% >>%OUTDIR%\link.sc\r
 set EXTRAS=\r
 if "%2" == "GUILE" set "EXTRAS=%GUILECFLAGS%"\r
+if exist "%OUTDIR%\%1.%O%" del "%OUTDIR%\%1.%O%"\r
 if "%COMPILER%" == "gcc" goto GccCompile\r
 \r
 :: MSVC Compile\r
 echo on\r
 %COMPILER% /nologo /MT /W4 /EHsc %OPTS% /I %OUTDIR%/src /I src /I glob /I src/w32/include /D WINDOWS32 /D WIN32 /D _CONSOLE /D HAVE_CONFIG_H /FR%OUTDIR% /Fp%OUTDIR%\%MAKE%.pch /Fo%OUTDIR%\%1.%O% /Fd%OUTDIR%\%MAKE%.pdb %EXTRAS% /c %1.c\r
 @echo off\r
-goto :EOF\r
+goto CompileDone\r
 \r
 :GccCompile\r
 :: GCC Compile\r
 echo on\r
-gcc -mthreads -Wall -std=gnu99 -gdwarf-2 -g3 %OPTS% -I%OUTDIR%/src -I./src -I./glob -I./src/w32/include -DWINDOWS32 -DHAVE_CONFIG_H %EXTRAS% -o %OUTDIR%\%1.%O% -c %1.c\r
+%COMPILER% -mthreads -Wall -std=gnu99 -gdwarf-2 -g3 %OPTS% -I%OUTDIR%/src -I./src -I./glob -I./src/w32/include -DWINDOWS32 -DHAVE_CONFIG_H %EXTRAS% -o %OUTDIR%\%1.%O% -c %1.c\r
 @echo off\r
+\r
+:CompileDone\r
+if not exist "%OUTDIR%\%1.%O%" exit 1\r
 goto :EOF\r
 \r
 :Link\r
@@ -246,7 +286,7 @@ goto :EOF
 :: GCC Link\r
 echo on\r
 echo %GUILELIBS% -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 >>%OUTDIR%\link.sc\r
-gcc -mthreads -gdwarf-2 -g3 %OPTS% -o %OUTDIR%\%MAKE%.exe @%OUTDIR%\link.sc -Wl,--out-implib=%OUTDIR%\libgnumake-1.dll.a\r
+%COMPILER% -mthreads -gdwarf-2 -g3 %OPTS% -o %OUTDIR%\%MAKE%.exe @%OUTDIR%\link.sc -Wl,--out-implib=%OUTDIR%\libgnumake-1.dll.a\r
 @echo off\r
 goto :EOF\r
 \r
@@ -261,6 +301,7 @@ echo ^";>> src\gmk-default.h
 goto :EOF\r
 \r
 :ChkGuile\r
+:: Build with Guile is supported only on NT and later versions\r
 if not "%OS%" == "Windows_NT" goto NoGuile\r
 pkg-config --help > %OUTDIR%\guile.tmp 2> NUL\r
 if ERRORLEVEL 1 goto NoPkgCfg\r
@@ -284,19 +325,28 @@ if not ERRORLEVEL 1 set /P GUILELIBS= < %OUTDIR%\guile.tmp
 \r
 if not "%GUILECFLAGS%" == "" goto GuileDone\r
 \r
-echo No Guile found, building without Guile\r
+echo No Guile found, building without Guile\r
 goto GuileDone\r
 \r
 :NoPkgCfg\r
-echo pkg-config not found, building without Guile\r
+echo pkg-config not found, building without Guile\r
 \r
 :GuileDone\r
 if "%GUILECFLAGS%" == "" goto :EOF\r
 \r
-echo Guile found, building with Guile\r
+echo - Guile found: building with Guile\r
 set "GUILECFLAGS=%GUILECFLAGS% -DHAVE_GUILE"\r
 goto :EOF\r
 \r
+:FindVswhere\r
+set VSWHERE=vswhere\r
+%VSWHERE% -help >nul 2>&1\r
+if not ERRORLEVEL 1 exit /b 0\r
+set "VSWHERE=C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere"\r
+%VSWHERE% -help >nul 2>&1\r
+if ERRORLEVEL 1 exit /b 1\r
+goto :EOF\r
+\r
 :CheckMSVC\r
 if not exist "%VSVARS%" exit /b 1\r
 call "%VSVARS%" %ARCH%\r