Bump to 4.4
[platform/upstream/make.git] / build_w32.bat
old mode 100755 (executable)
new mode 100644 (file)
index 553e9d9..30ca0b2
@@ -1,5 +1,5 @@
 @echo off\r
-:: Copyright (C) 1996-2020 Free Software Foundation, Inc.\r
+:: Copyright (C) 1996-2022 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
@@ -13,7 +13,7 @@
 :: 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
+:: with this program.  If not, see <https://www.gnu.org/licenses/>.\r
 \r
 setlocal\r
 if not "%RECURSEME%"=="%~0" (\r
@@ -37,6 +37,8 @@ set COMPILER=cl.exe
 set O=obj\r
 set ARCH=x64\r
 set DEBUG=N\r
+set DIRENT=Y\r
+set VERBOSE=N\r
 \r
 if exist maintMakefile (\r
     set MAINT=Y\r
@@ -45,13 +47,20 @@ if exist maintMakefile (
 )\r
 \r
 :ParseSW\r
+if "%1" == "--verbose" goto SetVerbose\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" == "tcc" goto SetTCC\r
 if "%1" == "" goto DoneSW\r
 goto Usage\r
 \r
+:SetVerbose\r
+set VERBOSE=Y\r
+shift\r
+goto ParseSW\r
+\r
 :SetDebug\r
 set DEBUG=Y\r
 echo - Building without compiler optimizations\r
@@ -77,20 +86,28 @@ echo - Building with GCC
 shift\r
 goto ParseSW\r
 \r
+:SetTCC\r
+set COMPILER=tcc\r
+set O=o\r
+echo - Building with TinyC\r
+shift\r
+goto ParseSW\r
+\r
 :DoneSW\r
 if "%MAINT%" == "Y" echo - Enabling maintainer mode\r
 \r
 if "%COMPILER%" == "gcc" goto FindGcc\r
+if "%COMPILER%" == "tcc" goto FindTcc\r
 \r
 :: Find a compiler.  Visual Studio requires a lot of effort to locate :-/.\r
-%COMPILER% >nul 2>&1\r
+call %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
+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
@@ -165,20 +182,36 @@ if "%MAINT%" == "Y" set "OPTS=%OPTS% /D MAKE_MAINTAINER_MODE"
 :: 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
+call %COMPILER%\r
 goto Build\r
 \r
 :FindGcc\r
 set OUTDIR=.\GccRel\r
 set LNKOUT=./GccRel\r
 set OPTS=-O2\r
+set DIRENT=N\r
 if "%DEBUG%" == "Y" set OPTS=-O0\r
 if "%DEBUG%" == "Y" set OUTDIR=.\GccDebug\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
+call %COMPILER% --version\r
+if not ERRORLEVEL 1 goto Build\r
+echo No %COMPILER% found.\r
+exit 1\r
+\r
+:FindTcc\r
+set OUTDIR=.\TccRel\r
+set LNKOUT=./TccRel\r
+set OPTS=-O2\r
+if "%DEBUG%" == "Y" set OPTS=-O0\r
+if "%DEBUG%" == "Y" set OUTDIR=.\TccDebug\r
+if "%DEBUG%" == "Y" set LNKOUT=./TccDebug\r
+if "%MAINT%" == "Y" set "OPTS=%OPTS% -DMAKE_MAINTAINER_MODE"\r
+:: Show the compiler version that we found\r
+echo.\r
+call %COMPILER% -v\r
 if not ERRORLEVEL 1 goto Build\r
 echo No %COMPILER% found.\r
 exit 1\r
@@ -197,10 +230,11 @@ mkdir %OUTDIR%\lib
 \r
 if "%GUILE%" == "Y" call :ChkGuile\r
 \r
+if not exist src\config.h.W32 goto NotConfig\r
+\r
 echo.\r
 echo Compiling %OUTDIR% version\r
 \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
@@ -231,6 +265,7 @@ call :Compile src/read
 call :Compile src/remake\r
 call :Compile src/remote-stub\r
 call :Compile src/rule\r
+call :Compile src/shuffle\r
 call :Compile src/signame\r
 call :Compile src/strcache\r
 call :Compile src/variable\r
@@ -246,7 +281,8 @@ call :Compile lib/fnmatch
 call :Compile lib/glob\r
 call :Compile lib/getloadavg\r
 \r
-if not "%COMPILER%" == "gcc" call :Compile src\w32\compat\dirent\r
+:: Compile dirent unless it is supported by compiler library (like with gcc).\r
+if "%DIRENT%" == "Y" call :Compile src\w32\compat\dirent\r
 \r
 call :Link\r
 \r
@@ -267,23 +303,33 @@ goto :EOF
 ::\r
 \r
 :Compile\r
+if "%VERBOSE%" == "N" echo - Compiling %1.c\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
+if "%COMPILER%" == "tcc" goto TccCompile\r
 \r
 :: MSVC Compile\r
-echo on\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
+if "%VERBOSE%" == "Y" echo on\r
+call %COMPILER% /nologo /MT /W4 /EHsc %OPTS% /I %OUTDIR%/src /I src /I %OUTDIR%/lib /I lib /I src/w32/include /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 CompileDone\r
 \r
 :GccCompile\r
 :: GCC Compile\r
-echo on\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
+if "%VERBOSE%" == "Y" echo on\r
+call %COMPILER% -mthreads -Wall -std=gnu99 -gdwarf-2 -g3 %OPTS% -I%OUTDIR%/src -I./src -I%OUTDIR%/lib -I./lib -I./src/w32/include -DHAVE_CONFIG_H %EXTRAS% -o %OUTDIR%/%1.%O% -c %1.c\r
 @echo off\r
+goto CompileDone\r
+\r
+:TccCompile\r
+:: TCC Compile\r
+if "%VERBOSE%" == "Y" echo on\r
+call %COMPILER% -mthreads -Wall -std=c11 %OPTS% -I%OUTDIR%/src -I./src -I%OUTDIR%/lib -I./lib -I./src/w32/include -D_cdecl= -D_MSC_VER -DHAVE_CONFIG_H %EXTRAS% -o %OUTDIR%/%1.%O% -c %1.c\r
+@echo off\r
+goto CompileDone\r
 \r
 :CompileDone\r
 if not exist "%OUTDIR%\%1.%O%" exit 1\r
@@ -291,56 +337,57 @@ goto :EOF
 \r
 :Link\r
 echo.\r
-echo Linking %LNKOUT%/%MAKE%.exe\r
+echo Linking %LNKOUT%/%MAKE%.exe\r
 if "%COMPILER%" == "gcc" goto GccLink\r
+if "%COMPILER%" == "tcc" goto TccLink\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:%LNKOUT%\%MAKE%.pdb %LINKOPTS% /OUT:%LNKOUT%\%MAKE%.exe @%LNKOUT%\link.sc\r
+if "%VERBOSE%" == "Y" echo on\r
+call 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
+if "%VERBOSE%" == "Y" echo on\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
+call %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%\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
+:TccLink\r
+:: TCC Link\r
+if "%VERBOSE%" == "Y" echo on\r
+echo %GUILELIBS% -lkernel32 -luser32 -lgdi32 -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lodbc32 -lodbccp32 >>%OUTDIR%\link.sc\r
+call %COMPILER% -mthreads %OPTS% -o %LNKOUT%/%MAKE%.exe @%LNKOUT%/link.sc \r
+@echo off\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
+call pkg-config --help > %OUTDIR%\guile.tmp 2> NUL\r
 if ERRORLEVEL 1 goto NoPkgCfg\r
 \r
-echo Checking for Guile 2.0\r
+set PKGMSC=\r
 if not "%COMPILER%" == "gcc" set PKGMSC=--msvc-syntax\r
-pkg-config --cflags --short-errors "guile-2.0" > %OUTDIR%\guile.tmp\r
-if not ERRORLEVEL 1 set /P GUILECFLAGS= < %OUTDIR%\guile.tmp\r
 \r
-pkg-config --libs --static --short-errors %PKGMSC% "guile-2.0" > %OUTDIR%\guile.tmp\r
-if not ERRORLEVEL 1 set /P GUILELIBS= < %OUTDIR%\guile.tmp\r
+echo Checking for Guile 2.0\r
+call pkg-config --cflags --short-errors "guile-2.0" > %OUTDIR%\gl-c2.tmp 2> NUL\r
+if not ERRORLEVEL 1 set /P GUILECFLAGS= < %OUTDIR%\gl-c2.tmp\r
+\r
+call pkg-config --libs --static --short-errors %PKGMSC% "guile-2.0" > %OUTDIR%\gl-l2.tmp 2> NUL\r
+if not ERRORLEVEL 1 set /P GUILELIBS= < %OUTDIR%\gl-l2.tmp\r
 \r
 if not "%GUILECFLAGS%" == "" goto GuileDone\r
 \r
 echo Checking for Guile 1.8\r
-pkg-config --cflags --short-errors "guile-1.8" > %OUTDIR%\guile.tmp\r
-if not ERRORLEVEL 1 set /P GUILECFLAGS= < %OUTDIR%\guile.tmp\r
+call pkg-config --cflags --short-errors "guile-1.8" > %OUTDIR%\gl-c18.tmp 2> NUL\r
+if not ERRORLEVEL 1 set /P GUILECFLAGS= < %OUTDIR%\gl-c18.tmp\r
 \r
-pkg-config --libs --static --short-errors %PKGMSC% "guile-1.8" > %OUTDIR%\guile.tmp\r
-if not ERRORLEVEL 1 set /P GUILELIBS= < %OUTDIR%\guile.tmp\r
+call pkg-config --libs --static --short-errors %PKGMSC% "guile-1.8" > %OUTDIR%\gl-l18.tmp 2> NUL\r
+if not ERRORLEVEL 1 set /P GUILELIBS= < %OUTDIR%\gl-l18.tmp\r
 \r
 if not "%GUILECFLAGS%" == "" goto GuileDone\r
 \r
@@ -359,10 +406,10 @@ goto :EOF
 \r
 :FindVswhere\r
 set VSWHERE=vswhere\r
-%VSWHERE% -help >nul 2>&1\r
+call "%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
+call "%VSWHERE%" -help >nul 2>&1\r
 if ERRORLEVEL 1 exit /b 1\r
 goto :EOF\r
 \r
@@ -370,17 +417,26 @@ goto :EOF
 if not exist "%VSVARS%" exit /b 1\r
 call "%VSVARS%" %ARCH%\r
 if ERRORLEVEL 1 exit /b 1\r
-%COMPILER% >nul 2>&1\r
+call %COMPILER% >nul 2>&1\r
 if ERRORLEVEL 1 exit /b 1\r
 goto :EOF\r
 \r
+:NotConfig\r
+echo.\r
+echo *** This workspace is not configured.\r
+echo Either retrieve the configured source in the release tarball\r
+echo or, if building from Git, run the .\bootstrap.bat script first.\r
+exit /b 1\r
+\r
 :Usage\r
-echo Usage: %0 [options] [gcc]\r
+echo Usage: %0 [options] [gcc] OR [tcc]\r
 echo Options:\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
+echo.\r
+echo. "gcc" means compile with GCC, "tcc" means compile with Tiny C's TCC\r
 goto :EOF\r
 \r
 :Reset\r