Change make license
[platform/upstream/make.git] / build_w32.bat
index 59e068b..553e9d9 100755 (executable)
 @echo off\r
-rem Copyright (C) 1996-2016 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-2020 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=msvc\r
+set COMPILER=cl.exe\r
+set O=obj\r
+set ARCH=x64\r
+set DEBUG=N\r
+\r
+if exist maintMakefile (\r
+    set MAINT=Y\r
+) else (\r
+    set MAINT=N\r
+)\r
 \r
 :ParseSW\r
 if "%1" == "--debug" goto SetDebug\r
 if "%1" == "--without-guile" goto NoGuile\r
+if "%1" == "--x86" goto Set32Bit\r
 if "%1" == "gcc" goto SetCC\r
 if "%1" == "" goto DoneSW\r
+goto Usage\r
 \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
-echo Building with GCC\r
+set O=o\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\r
-if "%DEBUG%" == "Y" echo Building without compiler optimizations\r
+if "%MAINT%" == "Y" echo - Enabling maintainer mode\r
+\r
+if "%COMPILER%" == "gcc" goto FindGcc\r
+\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
+\r
+set "VSVARS=%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
+call :CheckMSVC\r
+if not ERRORLEVEL 1 goto FoundMSVC\r
+\r
+set "VSVARS=%VS110COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
+call :CheckMSVC\r
+if not ERRORLEVEL 1 goto FoundMSVC\r
+\r
+set "VSVARS=%VS100COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
+call :CheckMSVC\r
+if not ERRORLEVEL 1 goto FoundMSVC\r
+\r
+set "VSVARS=%VS90COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
+call :CheckMSVC\r
+if not ERRORLEVEL 1 goto FoundMSVC\r
+\r
+set "VSVARS=%VS80COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
+call :CheckMSVC\r
+if not ERRORLEVEL 1 goto FoundMSVC\r
 \r
-if "%COMPILER%" == "gcc" goto GccBuild\r
+set "VSVARS=%VS71COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
+call :CheckMSVC\r
+if not ERRORLEVEL 1 goto FoundMSVC\r
 \r
+set "VSVARS=%VS70COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
+call :CheckMSVC\r
+if not ERRORLEVEL 1 goto FoundMSVC\r
+\r
+set "VSVARS=%V6TOOLS%\VC98\Bin\vcvars32.bat"\r
+call :CheckMSVC\r
+if not ERRORLEVEL 1 goto FoundMSVC\r
+\r
+set "VSVARS=%V6TOOLS%\VC97\Bin\vcvars32.bat"\r
+call :CheckMSVC\r
+if not ERRORLEVEL 1 goto FoundMSVC\r
+\r
+set "VSVARS=%V5TOOLS%\VC\Bin\vcvars32.bat"\r
+call :CheckMSVC\r
+if not ERRORLEVEL 1 goto FoundMSVC\r
+\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 1\r
+\r
+:FoundMSVC\r
 set OUTDIR=.\WinRel\r
+set LNKOUT=./WinRel\r
 set "OPTS=/O2 /D NDEBUG"\r
 set LINKOPTS=\r
 if "%DEBUG%" == "Y" set OUTDIR=.\WinDebug\r
+if "%DEBUG%" == "Y" set LNKOUT=./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
+if "%MAINT%" == "Y" set "OPTS=%OPTS% /D MAKE_MAINTAINER_MODE"\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 LNKOUT=./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
+if "%DEBUG%" == "Y" set LNKOUT=./GccDebug\r
+if "%MAINT%" == "Y" set "OPTS=%OPTS% -DMAKE_MAINTAINER_MODE"\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
@@ -82,114 +189,138 @@ if exist %OUTDIR%\nul rmdir /S /Q %OUTDIR%
 \r
 :: Recreate it\r
 mkdir %OUTDIR%\r
-mkdir %OUTDIR%\glob\r
-mkdir %OUTDIR%\w32\r
-mkdir %OUTDIR%\w32\compat\r
-mkdir %OUTDIR%\w32\subproc\r
+mkdir %OUTDIR%\src\r
+mkdir %OUTDIR%\src\w32\r
+mkdir %OUTDIR%\src\w32\compat\r
+mkdir %OUTDIR%\src\w32\subproc\r
+mkdir %OUTDIR%\lib\r
 \r
 if "%GUILE%" == "Y" call :ChkGuile\r
 \r
 echo.\r
 echo Compiling %OUTDIR% version\r
 \r
-if exist config.h.W32.template call :ConfigSCM\r
-copy config.h.W32 %OUTDIR%\config.h\r
-\r
-call :Compile ar\r
-call :Compile arscan\r
-call :Compile commands\r
-call :Compile default\r
-call :Compile dir\r
-call :Compile expand\r
-call :Compile file\r
-call :Compile function\r
-call :Compile getloadavg\r
-call :Compile getopt\r
-call :Compile getopt1\r
-call :Compile glob\fnmatch\r
-call :Compile glob\glob\r
-call :Compile guile GUILE\r
-call :Compile hash\r
-call :Compile implicit\r
-call :Compile job\r
-call :Compile load\r
-call :Compile loadapi\r
-call :Compile main GUILE\r
-call :Compile misc\r
-call :Compile output\r
-call :Compile read\r
-call :Compile remake\r
-call :Compile remote-stub\r
-call :Compile rule\r
-call :Compile signame\r
-call :Compile strcache\r
-call :Compile variable\r
-call :Compile version\r
-call :Compile vpath\r
-call :Compile w32\compat\posixfcn\r
-call :Compile w32\pathstuff\r
-call :Compile w32\subproc\misc\r
-call :Compile w32\subproc\sub_proc\r
-call :Compile w32\subproc\w32err\r
-call :Compile w32\w32os\r
-\r
-if not "%COMPILER%" == "gcc" call :Compile w32\compat\dirent\r
+if exist src\config.h.W32.template call :ConfigSCM\r
+copy src\config.h.W32 %OUTDIR%\src\config.h\r
+\r
+copy lib\glob.in.h %OUTDIR%\lib\glob.h\r
+copy lib\fnmatch.in.h %OUTDIR%\lib\fnmatch.h\r
+\r
+if exist %OUTDIR%\link.sc del %OUTDIR%\link.sc\r
+\r
+call :Compile src/ar\r
+call :Compile src/arscan\r
+call :Compile src/commands\r
+call :Compile src/default\r
+call :Compile src/dir\r
+call :Compile src/expand\r
+call :Compile src/file\r
+call :Compile src/function\r
+call :Compile src/getopt\r
+call :Compile src/getopt1\r
+call :Compile src/guile GUILE\r
+call :Compile src/hash\r
+call :Compile src/implicit\r
+call :Compile src/job\r
+call :Compile src/load\r
+call :Compile src/loadapi\r
+call :Compile src/main GUILE\r
+call :Compile src/misc\r
+call :Compile src/output\r
+call :Compile src/read\r
+call :Compile src/remake\r
+call :Compile src/remote-stub\r
+call :Compile src/rule\r
+call :Compile src/signame\r
+call :Compile src/strcache\r
+call :Compile src/variable\r
+call :Compile src/version\r
+call :Compile src/vpath\r
+call :Compile src/w32/pathstuff\r
+call :Compile src/w32/w32os\r
+call :Compile src/w32/compat/posixfcn\r
+call :Compile src/w32/subproc/misc\r
+call :Compile src/w32/subproc/sub_proc\r
+call :Compile src/w32/subproc/w32err\r
+call :Compile lib/fnmatch\r
+call :Compile lib/glob\r
+call :Compile lib/getloadavg\r
+\r
+if not "%COMPILER%" == "gcc" call :Compile src\w32\compat\dirent\r
 \r
 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 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
+if not exist tests\config-flags.pm copy /Y tests\config-flags.pm.W32 tests\config-flags.pm\r
+call :Reset\r
 goto :EOF\r
 \r
+::\r
+:: Subroutines\r
+::\r
+\r
 :Compile\r
+echo %LNKOUT%/%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
-cl.exe /nologo /MT /W4 /EHsc %OPTS% /I %OUTDIR% /I . /I glob /I w32/include /D WINDOWS32 /D WIN32 /D _CONSOLE /D HAVE_CONFIG_H /FR%OUTDIR% /Fp%OUTDIR%\%MAKE%.pch /Fo%OUTDIR%\%1.obj /Fd%OUTDIR%\%MAKE%.pdb %EXTRAS% /c %1.c\r
+%COMPILER% /nologo /MT /W4 /EHsc %OPTS% /I %OUTDIR%/src /I src /I %OUTDIR%/lib /I lib /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
-echo %OUTDIR%\%1.obj >>%OUTDIR%\link.sc\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% -I. -I./glob -I./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%OUTDIR%/lib -I./lib -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
-echo Linking %OUTDIR%/%MAKE%.exe\r
+echo.\r
+echo Linking %LNKOUT%/%MAKE%.exe\r
 if "%COMPILER%" == "gcc" goto GccLink\r
 \r
 :: MSVC Link\r
 echo %GUILELIBS% kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib >>%OUTDIR%\link.sc\r
 echo on\r
-link.exe /NOLOGO /SUBSYSTEM:console /PDB:%OUTDIR%\%MAKE%.pdb %LINKOPTS% /OUT:%OUTDIR%\%MAKE%.exe @%OUTDIR%\link.sc\r
+link.exe /NOLOGO /SUBSYSTEM:console /PDB:%LNKOUT%\%MAKE%.pdb %LINKOPTS% /OUT:%LNKOUT%\%MAKE%.exe @%LNKOUT%\link.sc\r
 @echo off\r
 goto :EOF\r
 \r
 :GccLink\r
 :: GCC Link\r
 echo on\r
-gcc -mthreads -gdwarf-2 -g3 -o %OUTDIR%\%MAKE%.exe %OUTDIR%\variable.o %OUTDIR%\rule.o %OUTDIR%\remote-stub.o %OUTDIR%\commands.o %OUTDIR%\file.o %OUTDIR%\getloadavg.o %OUTDIR%\default.o %OUTDIR%\signame.o %OUTDIR%\expand.o %OUTDIR%\dir.o %OUTDIR%\main.o %OUTDIR%\getopt1.o %OUTDIR%\guile.o %OUTDIR%\job.o %OUTDIR%\output.o %OUTDIR%\read.o %OUTDIR%\version.o %OUTDIR%\getopt.o %OUTDIR%\arscan.o %OUTDIR%\remake.o %OUTDIR%\misc.o %OUTDIR%\hash.o %OUTDIR%\strcache.o %OUTDIR%\ar.o %OUTDIR%\function.o %OUTDIR%\vpath.o %OUTDIR%\implicit.o %OUTDIR%\loadapi.o %OUTDIR%\load.o %OUTDIR%\glob\glob.o %OUTDIR%\glob\fnmatch.o %OUTDIR%\w32\pathstuff.o %OUTDIR%\w32\compat\posixfcn.o %OUTDIR%\w32\w32os.o %OUTDIR%\w32\subproc\misc.o %OUTDIR%\w32\subproc\sub_proc.o %OUTDIR%\w32\subproc\w32err.o %GUILELIBS% -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -Wl,--out-implib=%OUTDIR%\libgnumake-1.dll.a\r
+echo %GUILELIBS% -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 >>%OUTDIR%\link.sc\r
+%COMPILER% -mthreads -gdwarf-2 -g3 %OPTS% -o %LNKOUT%/%MAKE%.exe @%LNKOUT%/link.sc -Wl,--out-implib=%LNKOUT%/libgnumake-1.dll.a\r
 @echo off\r
 goto :EOF\r
 \r
 :ConfigSCM\r
 echo Generating config from SCM templates\r
-sed -n "s/^AC_INIT(\[GNU make\],\[\([^]]\+\)\].*/s,%%VERSION%%,\1,g/p" configure.ac > %OUTDIR%\config.h.W32.sed\r
-echo s,%%PACKAGE%%,make,g >> %OUTDIR%\config.h.W32.sed\r
-sed -f %OUTDIR%\config.h.W32.sed config.h.W32.template > config.h.W32\r
-echo static const char *const GUILE_module_defn = ^" \gmk-default.h\r
-sed -e "s/;.*//" -e "/^[ \t]*$/d" -e "s/\"/\\\\\"/g" -e "s/$/ \\\/" gmk-default.scm >> gmk-default.h\r
-echo ^";>> gmk-default.h\r
+sed -n "s/^AC_INIT(\[GNU make\],\[\([^]]\+\)\].*/s,%%VERSION%%,\1,g/p" configure.ac > %OUTDIR%\src\config.h.W32.sed\r
+echo s,%%PACKAGE%%,make,g >> %OUTDIR%\src\config.h.W32.sed\r
+sed -f %OUTDIR%\src\config.h.W32.sed src\config.h.W32.template > src\config.h.W32\r
+echo static const char *const GUILE_module_defn = ^" \ > src\gmk-default.h\r
+sed -e "s/;.*//" -e "/^[ \t]*$/d" -e "s/\"/\\\\\"/g" -e "s/$/ \\\/" src\gmk-default.scm >> src\gmk-default.h\r
+echo ^";>> src\gmk-default.h\r
 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
@@ -213,29 +344,47 @@ 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
+if ERRORLEVEL 1 exit /b 1\r
+%COMPILER% >nul 2>&1\r
+if ERRORLEVEL 1 exit /b 1\r
+goto :EOF\r
+\r
 :Usage\r
 echo Usage: %0 [options] [gcc]\r
 echo Options:\r
-echo.  --debug           For GCC only, make a debug build\r
-echo.                    (MSVC build always makes both debug and release)\r
 echo.  --without-guile   Do not compile Guile support even if found\r
+echo.  --debug           Make a Debug build--default is Release\r
+echo.  --x86             Make a 32bit binary--default is 64bit\r
 echo.  --help            Display these instructions and exit\r
 goto :EOF\r
 \r
 :Reset\r
+set ARCH=\r
 set COMPILER=\r
 set DEBUG=\r
 set GUILE=\r
@@ -244,7 +393,10 @@ set GUILELIBS=
 set LINKOPTS=\r
 set MAKE=\r
 set NOGUILE=\r
+set O=\r
 set OPTS=\r
 set OUTDIR=\r
+set LNKOUT=\r
 set PKGMSC=\r
+set VSVARS=\r
 goto :EOF\r