2 :: Copyright (C) 1996-2020 Free Software Foundation, Inc.
\r
3 :: This file is part of GNU Make.
\r
5 :: GNU Make is free software; you can redistribute it and/or modify it under
\r
6 :: the terms of the GNU General Public License as published by the Free
\r
7 :: Software Foundation; either version 3 of the License, or (at your option)
\r
8 :: any later version.
\r
10 :: GNU Make is distributed in the hope that it will be useful, but WITHOUT
\r
11 :: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
12 :: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for.
\r
15 :: You should have received a copy of the GNU General Public License along
\r
16 :: with this program. If not, see <http://www.gnu.org/licenses/>.
\r
19 if not "%RECURSEME%"=="%~0" (
\r
21 %ComSpec% /s /c ""%~0" %*"
\r
27 if "%1" == "-h" goto Usage
\r
28 if "%1" == "--help" goto Usage
\r
31 echo Creating GNU Make for Windows 9X/NT/2K/XP/Vista/7/8/10
\r
41 if exist maintMakefile (
\r
48 if "%1" == "--debug" goto SetDebug
\r
49 if "%1" == "--without-guile" goto NoGuile
\r
50 if "%1" == "--x86" goto Set32Bit
\r
51 if "%1" == "gcc" goto SetCC
\r
52 if "%1" == "" goto DoneSW
\r
57 echo - Building without compiler optimizations
\r
63 echo - Building without Guile
\r
69 echo - Building 32bit GNU Make
\r
76 echo - Building with GCC
\r
81 if "%MAINT%" == "Y" echo - Enabling maintainer mode
\r
83 if "%COMPILER%" == "gcc" goto FindGcc
\r
85 :: Find a compiler. Visual Studio requires a lot of effort to locate :-/.
\r
86 %COMPILER% >nul 2>&1
\r
87 if not ERRORLEVEL 1 goto FoundMSVC
\r
89 :: Visual Studio 17 and above provides the "vswhere" tool
\r
91 if ERRORLEVEL 1 goto LegacyVS
\r
93 for /f "tokens=* usebackq" %%i in (`%VSWHERE% -latest -property installationPath`) do (
\r
96 set "VSVARS=%InstallPath%\VC\Auxiliary\Build\vcvarsall.bat"
\r
98 if not ERRORLEVEL 1 goto FoundMSVC
\r
100 :: No "vswhere" or it can't find a compiler. Go old-school.
\r
102 set "VSVARS=%VS150COMNTOOLS%\..\..\VC\vcvarsall.bat"
\r
104 if not ERRORLEVEL 1 goto FoundMSVC
\r
106 set "VSVARS=%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat"
\r
108 if not ERRORLEVEL 1 goto FoundMSVC
\r
110 set "VSVARS=%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat"
\r
112 if not ERRORLEVEL 1 goto FoundMSVC
\r
114 set "VSVARS=%VS110COMNTOOLS%\..\..\VC\vcvarsall.bat"
\r
116 if not ERRORLEVEL 1 goto FoundMSVC
\r
118 set "VSVARS=%VS100COMNTOOLS%\..\..\VC\vcvarsall.bat"
\r
120 if not ERRORLEVEL 1 goto FoundMSVC
\r
122 set "VSVARS=%VS90COMNTOOLS%\..\..\VC\vcvarsall.bat"
\r
124 if not ERRORLEVEL 1 goto FoundMSVC
\r
126 set "VSVARS=%VS80COMNTOOLS%\..\..\VC\vcvarsall.bat"
\r
128 if not ERRORLEVEL 1 goto FoundMSVC
\r
130 set "VSVARS=%VS71COMNTOOLS%\..\..\VC\vcvarsall.bat"
\r
132 if not ERRORLEVEL 1 goto FoundMSVC
\r
134 set "VSVARS=%VS70COMNTOOLS%\..\..\VC\vcvarsall.bat"
\r
136 if not ERRORLEVEL 1 goto FoundMSVC
\r
138 set "VSVARS=%V6TOOLS%\VC98\Bin\vcvars32.bat"
\r
140 if not ERRORLEVEL 1 goto FoundMSVC
\r
142 set "VSVARS=%V6TOOLS%\VC97\Bin\vcvars32.bat"
\r
144 if not ERRORLEVEL 1 goto FoundMSVC
\r
146 set "VSVARS=%V5TOOLS%\VC\Bin\vcvars32.bat"
\r
148 if not ERRORLEVEL 1 goto FoundMSVC
\r
150 :: We did not find anything--fail
\r
151 echo No MSVC compiler available.
\r
152 echo Please run vcvarsall.bat and/or configure your Path.
\r
156 set OUTDIR=.\WinRel
\r
157 set LNKOUT=./WinRel
\r
158 set "OPTS=/O2 /D NDEBUG"
\r
160 if "%DEBUG%" == "Y" set OUTDIR=.\WinDebug
\r
161 if "%DEBUG%" == "Y" set LNKOUT=./WinDebug
\r
162 if "%DEBUG%" == "Y" set "OPTS=/Zi /Od /D _DEBUG"
\r
163 if "%DEBUG%" == "Y" set LINKOPTS=/DEBUG
\r
164 if "%MAINT%" == "Y" set "OPTS=%OPTS% /D MAKE_MAINTAINER_MODE"
\r
165 :: Show the compiler version that we found
\r
166 :: Unfortunately this also shows a "usage" note; I can't find anything better.
\r
172 set OUTDIR=.\GccRel
\r
173 set LNKOUT=./GccRel
\r
175 if "%DEBUG%" == "Y" set OPTS=-O0
\r
176 if "%DEBUG%" == "Y" set OUTDIR=.\GccDebug
\r
177 if "%DEBUG%" == "Y" set LNKOUT=./GccDebug
\r
178 if "%MAINT%" == "Y" set "OPTS=%OPTS% -DMAKE_MAINTAINER_MODE"
\r
179 :: Show the compiler version that we found
\r
181 %COMPILER% --version
\r
182 if not ERRORLEVEL 1 goto Build
\r
183 echo No %COMPILER% found.
\r
187 :: Clean the directory if it exists
\r
188 if exist %OUTDIR%\nul rmdir /S /Q %OUTDIR%
\r
193 mkdir %OUTDIR%\src\w32
\r
194 mkdir %OUTDIR%\src\w32\compat
\r
195 mkdir %OUTDIR%\src\w32\subproc
\r
198 if "%GUILE%" == "Y" call :ChkGuile
\r
201 echo Compiling %OUTDIR% version
\r
203 if exist src\config.h.W32.template call :ConfigSCM
\r
204 copy src\config.h.W32 %OUTDIR%\src\config.h
\r
206 copy lib\glob.in.h %OUTDIR%\lib\glob.h
\r
207 copy lib\fnmatch.in.h %OUTDIR%\lib\fnmatch.h
\r
209 if exist %OUTDIR%\link.sc del %OUTDIR%\link.sc
\r
211 call :Compile src/ar
\r
212 call :Compile src/arscan
\r
213 call :Compile src/commands
\r
214 call :Compile src/default
\r
215 call :Compile src/dir
\r
216 call :Compile src/expand
\r
217 call :Compile src/file
\r
218 call :Compile src/function
\r
219 call :Compile src/getopt
\r
220 call :Compile src/getopt1
\r
221 call :Compile src/guile GUILE
\r
222 call :Compile src/hash
\r
223 call :Compile src/implicit
\r
224 call :Compile src/job
\r
225 call :Compile src/load
\r
226 call :Compile src/loadapi
\r
227 call :Compile src/main GUILE
\r
228 call :Compile src/misc
\r
229 call :Compile src/output
\r
230 call :Compile src/read
\r
231 call :Compile src/remake
\r
232 call :Compile src/remote-stub
\r
233 call :Compile src/rule
\r
234 call :Compile src/signame
\r
235 call :Compile src/strcache
\r
236 call :Compile src/variable
\r
237 call :Compile src/version
\r
238 call :Compile src/vpath
\r
239 call :Compile src/w32/pathstuff
\r
240 call :Compile src/w32/w32os
\r
241 call :Compile src/w32/compat/posixfcn
\r
242 call :Compile src/w32/subproc/misc
\r
243 call :Compile src/w32/subproc/sub_proc
\r
244 call :Compile src/w32/subproc/w32err
\r
245 call :Compile lib/fnmatch
\r
246 call :Compile lib/glob
\r
247 call :Compile lib/getloadavg
\r
249 if not "%COMPILER%" == "gcc" call :Compile src\w32\compat\dirent
\r
254 if exist %OUTDIR%\%MAKE%.exe goto Success
\r
255 echo %OUTDIR% build FAILED!
\r
259 echo %OUTDIR% build succeeded.
\r
260 if exist Basic.mk copy /Y Basic.mk Makefile
\r
261 if not exist tests\config-flags.pm copy /Y tests\config-flags.pm.W32 tests\config-flags.pm
\r
270 echo %LNKOUT%/%1.%O% >>%OUTDIR%\link.sc
\r
272 if "%2" == "GUILE" set "EXTRAS=%GUILECFLAGS%"
\r
273 if exist "%OUTDIR%\%1.%O%" del "%OUTDIR%\%1.%O%"
\r
274 if "%COMPILER%" == "gcc" goto GccCompile
\r
278 %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
285 %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
289 if not exist "%OUTDIR%\%1.%O%" exit 1
\r
294 echo Linking %LNKOUT%/%MAKE%.exe
\r
295 if "%COMPILER%" == "gcc" goto GccLink
\r
298 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
300 link.exe /NOLOGO /SUBSYSTEM:console /PDB:%LNKOUT%\%MAKE%.pdb %LINKOPTS% /OUT:%LNKOUT%\%MAKE%.exe @%LNKOUT%\link.sc
\r
307 echo %GUILELIBS% -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 >>%OUTDIR%\link.sc
\r
308 %COMPILER% -mthreads -gdwarf-2 -g3 %OPTS% -o %LNKOUT%/%MAKE%.exe @%LNKOUT%/link.sc -Wl,--out-implib=%LNKOUT%/libgnumake-1.dll.a
\r
313 echo Generating config from SCM templates
\r
314 sed -n "s/^AC_INIT(\[GNU make\],\[\([^]]\+\)\].*/s,%%VERSION%%,\1,g/p" configure.ac > %OUTDIR%\src\config.h.W32.sed
\r
315 echo s,%%PACKAGE%%,make,g >> %OUTDIR%\src\config.h.W32.sed
\r
316 sed -f %OUTDIR%\src\config.h.W32.sed src\config.h.W32.template > src\config.h.W32
\r
317 echo static const char *const GUILE_module_defn = ^" \ > src\gmk-default.h
\r
318 sed -e "s/;.*//" -e "/^[ \t]*$/d" -e "s/\"/\\\\\"/g" -e "s/$/ \\\/" src\gmk-default.scm >> src\gmk-default.h
\r
319 echo ^";>> src\gmk-default.h
\r
323 :: Build with Guile is supported only on NT and later versions
\r
324 if not "%OS%" == "Windows_NT" goto NoGuile
\r
325 pkg-config --help > %OUTDIR%\guile.tmp 2> NUL
\r
326 if ERRORLEVEL 1 goto NoPkgCfg
\r
328 echo Checking for Guile 2.0
\r
329 if not "%COMPILER%" == "gcc" set PKGMSC=--msvc-syntax
\r
330 pkg-config --cflags --short-errors "guile-2.0" > %OUTDIR%\guile.tmp
\r
331 if not ERRORLEVEL 1 set /P GUILECFLAGS= < %OUTDIR%\guile.tmp
\r
333 pkg-config --libs --static --short-errors %PKGMSC% "guile-2.0" > %OUTDIR%\guile.tmp
\r
334 if not ERRORLEVEL 1 set /P GUILELIBS= < %OUTDIR%\guile.tmp
\r
336 if not "%GUILECFLAGS%" == "" goto GuileDone
\r
338 echo Checking for Guile 1.8
\r
339 pkg-config --cflags --short-errors "guile-1.8" > %OUTDIR%\guile.tmp
\r
340 if not ERRORLEVEL 1 set /P GUILECFLAGS= < %OUTDIR%\guile.tmp
\r
342 pkg-config --libs --static --short-errors %PKGMSC% "guile-1.8" > %OUTDIR%\guile.tmp
\r
343 if not ERRORLEVEL 1 set /P GUILELIBS= < %OUTDIR%\guile.tmp
\r
345 if not "%GUILECFLAGS%" == "" goto GuileDone
\r
347 echo - No Guile found, building without Guile
\r
351 echo - pkg-config not found, building without Guile
\r
354 if "%GUILECFLAGS%" == "" goto :EOF
\r
356 echo - Guile found: building with Guile
\r
357 set "GUILECFLAGS=%GUILECFLAGS% -DHAVE_GUILE"
\r
361 set VSWHERE=vswhere
\r
362 %VSWHERE% -help >nul 2>&1
\r
363 if not ERRORLEVEL 1 exit /b 0
\r
364 set "VSWHERE=C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere"
\r
365 %VSWHERE% -help >nul 2>&1
\r
366 if ERRORLEVEL 1 exit /b 1
\r
370 if not exist "%VSVARS%" exit /b 1
\r
371 call "%VSVARS%" %ARCH%
\r
372 if ERRORLEVEL 1 exit /b 1
\r
373 %COMPILER% >nul 2>&1
\r
374 if ERRORLEVEL 1 exit /b 1
\r
378 echo Usage: %0 [options] [gcc]
\r
380 echo. --without-guile Do not compile Guile support even if found
\r
381 echo. --debug Make a Debug build--default is Release
\r
382 echo. --x86 Make a 32bit binary--default is 64bit
\r
383 echo. --help Display these instructions and exit
\r