Imported Upstream version 4.4
[platform/upstream/make.git] / build_w32.bat
1 @echo off\r
2 :: Copyright (C) 1996-2022 Free Software Foundation, Inc.\r
3 :: This file is part of GNU Make.\r
4 ::\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
9 ::\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
13 :: more details.\r
14 ::\r
15 :: You should have received a copy of the GNU General Public License along\r
16 :: with this program.  If not, see <https://www.gnu.org/licenses/>.\r
17 \r
18 setlocal\r
19 if not "%RECURSEME%"=="%~0" (\r
20     set "RECURSEME=%~0"\r
21     %ComSpec% /s /c ""%~0" %*"\r
22     goto :EOF\r
23 )\r
24 \r
25 call :Reset\r
26 \r
27 if "%1" == "-h" goto Usage\r
28 if "%1" == "--help" goto Usage\r
29 \r
30 echo.\r
31 echo Creating GNU Make for Windows 9X/NT/2K/XP/Vista/7/8/10\r
32 echo.\r
33 \r
34 set MAKE=gnumake\r
35 set GUILE=Y\r
36 set COMPILER=cl.exe\r
37 set O=obj\r
38 set ARCH=x64\r
39 set DEBUG=N\r
40 set DIRENT=Y\r
41 set VERBOSE=N\r
42 \r
43 if exist maintMakefile (\r
44     set MAINT=Y\r
45 ) else (\r
46     set MAINT=N\r
47 )\r
48 \r
49 :ParseSW\r
50 if "%1" == "--verbose" goto SetVerbose\r
51 if "%1" == "--debug" goto SetDebug\r
52 if "%1" == "--without-guile" goto NoGuile\r
53 if "%1" == "--x86" goto Set32Bit\r
54 if "%1" == "gcc" goto SetCC\r
55 if "%1" == "tcc" goto SetTCC\r
56 if "%1" == "" goto DoneSW\r
57 goto Usage\r
58 \r
59 :SetVerbose\r
60 set VERBOSE=Y\r
61 shift\r
62 goto ParseSW\r
63 \r
64 :SetDebug\r
65 set DEBUG=Y\r
66 echo - Building without compiler optimizations\r
67 shift\r
68 goto ParseSW\r
69 \r
70 :NoGuile\r
71 set GUILE=N\r
72 echo - Building without Guile\r
73 shift\r
74 goto ParseSW\r
75 \r
76 :Set32Bit\r
77 set ARCH=x86\r
78 echo - Building 32bit GNU Make\r
79 shift\r
80 goto ParseSW\r
81 \r
82 :SetCC\r
83 set COMPILER=gcc\r
84 set O=o\r
85 echo - Building with GCC\r
86 shift\r
87 goto ParseSW\r
88 \r
89 :SetTCC\r
90 set COMPILER=tcc\r
91 set O=o\r
92 echo - Building with TinyC\r
93 shift\r
94 goto ParseSW\r
95 \r
96 :DoneSW\r
97 if "%MAINT%" == "Y" echo - Enabling maintainer mode\r
98 \r
99 if "%COMPILER%" == "gcc" goto FindGcc\r
100 if "%COMPILER%" == "tcc" goto FindTcc\r
101 \r
102 :: Find a compiler.  Visual Studio requires a lot of effort to locate :-/.\r
103 call %COMPILER% >nul 2>&1\r
104 if not ERRORLEVEL 1 goto FoundMSVC\r
105 \r
106 :: Visual Studio 17 and above provides the "vswhere" tool\r
107 call :FindVswhere\r
108 if ERRORLEVEL 1 goto LegacyVS\r
109 \r
110 for /f "tokens=* usebackq" %%i in (`"%VSWHERE%" -latest -property installationPath`) do (\r
111     set InstallPath=%%i\r
112 )\r
113 set "VSVARS=%InstallPath%\VC\Auxiliary\Build\vcvarsall.bat"\r
114 call :CheckMSVC\r
115 if not ERRORLEVEL 1 goto FoundMSVC\r
116 \r
117 :: No "vswhere" or it can't find a compiler.  Go old-school.\r
118 :LegacyVS\r
119 set "VSVARS=%VS150COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
120 call :CheckMSVC\r
121 if not ERRORLEVEL 1 goto FoundMSVC\r
122 \r
123 set "VSVARS=%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
124 call :CheckMSVC\r
125 if not ERRORLEVEL 1 goto FoundMSVC\r
126 \r
127 set "VSVARS=%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
128 call :CheckMSVC\r
129 if not ERRORLEVEL 1 goto FoundMSVC\r
130 \r
131 set "VSVARS=%VS110COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
132 call :CheckMSVC\r
133 if not ERRORLEVEL 1 goto FoundMSVC\r
134 \r
135 set "VSVARS=%VS100COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
136 call :CheckMSVC\r
137 if not ERRORLEVEL 1 goto FoundMSVC\r
138 \r
139 set "VSVARS=%VS90COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
140 call :CheckMSVC\r
141 if not ERRORLEVEL 1 goto FoundMSVC\r
142 \r
143 set "VSVARS=%VS80COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
144 call :CheckMSVC\r
145 if not ERRORLEVEL 1 goto FoundMSVC\r
146 \r
147 set "VSVARS=%VS71COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
148 call :CheckMSVC\r
149 if not ERRORLEVEL 1 goto FoundMSVC\r
150 \r
151 set "VSVARS=%VS70COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
152 call :CheckMSVC\r
153 if not ERRORLEVEL 1 goto FoundMSVC\r
154 \r
155 set "VSVARS=%V6TOOLS%\VC98\Bin\vcvars32.bat"\r
156 call :CheckMSVC\r
157 if not ERRORLEVEL 1 goto FoundMSVC\r
158 \r
159 set "VSVARS=%V6TOOLS%\VC97\Bin\vcvars32.bat"\r
160 call :CheckMSVC\r
161 if not ERRORLEVEL 1 goto FoundMSVC\r
162 \r
163 set "VSVARS=%V5TOOLS%\VC\Bin\vcvars32.bat"\r
164 call :CheckMSVC\r
165 if not ERRORLEVEL 1 goto FoundMSVC\r
166 \r
167 :: We did not find anything--fail\r
168 echo No MSVC compiler available.\r
169 echo Please run vcvarsall.bat and/or configure your Path.\r
170 exit 1\r
171 \r
172 :FoundMSVC\r
173 set OUTDIR=.\WinRel\r
174 set LNKOUT=./WinRel\r
175 set "OPTS=/O2 /D NDEBUG"\r
176 set LINKOPTS=\r
177 if "%DEBUG%" == "Y" set OUTDIR=.\WinDebug\r
178 if "%DEBUG%" == "Y" set LNKOUT=./WinDebug\r
179 if "%DEBUG%" == "Y" set "OPTS=/Zi /Od /D _DEBUG"\r
180 if "%DEBUG%" == "Y" set LINKOPTS=/DEBUG\r
181 if "%MAINT%" == "Y" set "OPTS=%OPTS% /D MAKE_MAINTAINER_MODE"\r
182 :: Show the compiler version that we found\r
183 :: Unfortunately this also shows a "usage" note; I can't find anything better.\r
184 echo.\r
185 call %COMPILER%\r
186 goto Build\r
187 \r
188 :FindGcc\r
189 set OUTDIR=.\GccRel\r
190 set LNKOUT=./GccRel\r
191 set OPTS=-O2\r
192 set DIRENT=N\r
193 if "%DEBUG%" == "Y" set OPTS=-O0\r
194 if "%DEBUG%" == "Y" set OUTDIR=.\GccDebug\r
195 if "%DEBUG%" == "Y" set LNKOUT=./GccDebug\r
196 if "%MAINT%" == "Y" set "OPTS=%OPTS% -DMAKE_MAINTAINER_MODE"\r
197 :: Show the compiler version that we found\r
198 echo.\r
199 call %COMPILER% --version\r
200 if not ERRORLEVEL 1 goto Build\r
201 echo No %COMPILER% found.\r
202 exit 1\r
203 \r
204 :FindTcc\r
205 set OUTDIR=.\TccRel\r
206 set LNKOUT=./TccRel\r
207 set OPTS=-O2\r
208 if "%DEBUG%" == "Y" set OPTS=-O0\r
209 if "%DEBUG%" == "Y" set OUTDIR=.\TccDebug\r
210 if "%DEBUG%" == "Y" set LNKOUT=./TccDebug\r
211 if "%MAINT%" == "Y" set "OPTS=%OPTS% -DMAKE_MAINTAINER_MODE"\r
212 :: Show the compiler version that we found\r
213 echo.\r
214 call %COMPILER% -v\r
215 if not ERRORLEVEL 1 goto Build\r
216 echo No %COMPILER% found.\r
217 exit 1\r
218 \r
219 :Build\r
220 :: Clean the directory if it exists\r
221 if exist %OUTDIR%\nul rmdir /S /Q %OUTDIR%\r
222 \r
223 :: Recreate it\r
224 mkdir %OUTDIR%\r
225 mkdir %OUTDIR%\src\r
226 mkdir %OUTDIR%\src\w32\r
227 mkdir %OUTDIR%\src\w32\compat\r
228 mkdir %OUTDIR%\src\w32\subproc\r
229 mkdir %OUTDIR%\lib\r
230 \r
231 if "%GUILE%" == "Y" call :ChkGuile\r
232 \r
233 if not exist src\config.h.W32 goto NotConfig\r
234 \r
235 echo.\r
236 echo Compiling %OUTDIR% version\r
237 \r
238 copy src\config.h.W32 %OUTDIR%\src\config.h\r
239 \r
240 copy lib\glob.in.h %OUTDIR%\lib\glob.h\r
241 copy lib\fnmatch.in.h %OUTDIR%\lib\fnmatch.h\r
242 \r
243 if exist %OUTDIR%\link.sc del %OUTDIR%\link.sc\r
244 \r
245 call :Compile src/ar\r
246 call :Compile src/arscan\r
247 call :Compile src/commands\r
248 call :Compile src/default\r
249 call :Compile src/dir\r
250 call :Compile src/expand\r
251 call :Compile src/file\r
252 call :Compile src/function\r
253 call :Compile src/getopt\r
254 call :Compile src/getopt1\r
255 call :Compile src/guile GUILE\r
256 call :Compile src/hash\r
257 call :Compile src/implicit\r
258 call :Compile src/job\r
259 call :Compile src/load\r
260 call :Compile src/loadapi\r
261 call :Compile src/main GUILE\r
262 call :Compile src/misc\r
263 call :Compile src/output\r
264 call :Compile src/read\r
265 call :Compile src/remake\r
266 call :Compile src/remote-stub\r
267 call :Compile src/rule\r
268 call :Compile src/shuffle\r
269 call :Compile src/signame\r
270 call :Compile src/strcache\r
271 call :Compile src/variable\r
272 call :Compile src/version\r
273 call :Compile src/vpath\r
274 call :Compile src/w32/pathstuff\r
275 call :Compile src/w32/w32os\r
276 call :Compile src/w32/compat/posixfcn\r
277 call :Compile src/w32/subproc/misc\r
278 call :Compile src/w32/subproc/sub_proc\r
279 call :Compile src/w32/subproc/w32err\r
280 call :Compile lib/fnmatch\r
281 call :Compile lib/glob\r
282 call :Compile lib/getloadavg\r
283 \r
284 :: Compile dirent unless it is supported by compiler library (like with gcc).\r
285 if "%DIRENT%" == "Y" call :Compile src\w32\compat\dirent\r
286 \r
287 call :Link\r
288 \r
289 echo.\r
290 if exist %OUTDIR%\%MAKE%.exe goto Success\r
291 echo %OUTDIR% build FAILED!\r
292 exit 1\r
293 \r
294 :Success\r
295 echo %OUTDIR% build succeeded.\r
296 if exist Basic.mk copy /Y Basic.mk Makefile\r
297 if not exist tests\config-flags.pm copy /Y tests\config-flags.pm.W32 tests\config-flags.pm\r
298 call :Reset\r
299 goto :EOF\r
300 \r
301 ::\r
302 :: Subroutines\r
303 ::\r
304 \r
305 :Compile\r
306 if "%VERBOSE%" == "N" echo - Compiling %1.c\r
307 echo %LNKOUT%/%1.%O% >>%OUTDIR%\link.sc\r
308 set EXTRAS=\r
309 if "%2" == "GUILE" set "EXTRAS=%GUILECFLAGS%"\r
310 if exist "%OUTDIR%\%1.%O%" del "%OUTDIR%\%1.%O%"\r
311 if "%COMPILER%" == "gcc" goto GccCompile\r
312 if "%COMPILER%" == "tcc" goto TccCompile\r
313 \r
314 :: MSVC Compile\r
315 if "%VERBOSE%" == "Y" echo on\r
316 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
317 @echo off\r
318 goto CompileDone\r
319 \r
320 :GccCompile\r
321 :: GCC Compile\r
322 if "%VERBOSE%" == "Y" echo on\r
323 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
324 @echo off\r
325 goto CompileDone\r
326 \r
327 :TccCompile\r
328 :: TCC Compile\r
329 if "%VERBOSE%" == "Y" echo on\r
330 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
331 @echo off\r
332 goto CompileDone\r
333 \r
334 :CompileDone\r
335 if not exist "%OUTDIR%\%1.%O%" exit 1\r
336 goto :EOF\r
337 \r
338 :Link\r
339 echo.\r
340 echo - Linking %LNKOUT%/%MAKE%.exe\r
341 if "%COMPILER%" == "gcc" goto GccLink\r
342 if "%COMPILER%" == "tcc" goto TccLink\r
343 \r
344 :: MSVC Link\r
345 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
346 if "%VERBOSE%" == "Y" echo on\r
347 call link.exe /NOLOGO /SUBSYSTEM:console /PDB:%LNKOUT%\%MAKE%.pdb %LINKOPTS% /OUT:%LNKOUT%\%MAKE%.exe @%LNKOUT%\link.sc\r
348 @echo off\r
349 goto :EOF\r
350 \r
351 :GccLink\r
352 :: GCC Link\r
353 if "%VERBOSE%" == "Y" echo on\r
354 echo %GUILELIBS% -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 >>%OUTDIR%\link.sc\r
355 call %COMPILER% -mthreads -gdwarf-2 -g3 %OPTS% -o %LNKOUT%/%MAKE%.exe @%LNKOUT%/link.sc -Wl,--out-implib=%LNKOUT%/libgnumake-1.dll.a\r
356 @echo off\r
357 goto :EOF\r
358 \r
359 :TccLink\r
360 :: TCC Link\r
361 if "%VERBOSE%" == "Y" echo on\r
362 echo %GUILELIBS% -lkernel32 -luser32 -lgdi32 -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lodbc32 -lodbccp32 >>%OUTDIR%\link.sc\r
363 call %COMPILER% -mthreads %OPTS% -o %LNKOUT%/%MAKE%.exe @%LNKOUT%/link.sc \r
364 @echo off\r
365 goto :EOF\r
366 \r
367 :ChkGuile\r
368 :: Build with Guile is supported only on NT and later versions\r
369 if not "%OS%" == "Windows_NT" goto NoGuile\r
370 call pkg-config --help > %OUTDIR%\guile.tmp 2> NUL\r
371 if ERRORLEVEL 1 goto NoPkgCfg\r
372 \r
373 set PKGMSC=\r
374 if not "%COMPILER%" == "gcc" set PKGMSC=--msvc-syntax\r
375 \r
376 echo Checking for Guile 2.0\r
377 call pkg-config --cflags --short-errors "guile-2.0" > %OUTDIR%\gl-c2.tmp 2> NUL\r
378 if not ERRORLEVEL 1 set /P GUILECFLAGS= < %OUTDIR%\gl-c2.tmp\r
379 \r
380 call pkg-config --libs --static --short-errors %PKGMSC% "guile-2.0" > %OUTDIR%\gl-l2.tmp 2> NUL\r
381 if not ERRORLEVEL 1 set /P GUILELIBS= < %OUTDIR%\gl-l2.tmp\r
382 \r
383 if not "%GUILECFLAGS%" == "" goto GuileDone\r
384 \r
385 echo Checking for Guile 1.8\r
386 call pkg-config --cflags --short-errors "guile-1.8" > %OUTDIR%\gl-c18.tmp 2> NUL\r
387 if not ERRORLEVEL 1 set /P GUILECFLAGS= < %OUTDIR%\gl-c18.tmp\r
388 \r
389 call pkg-config --libs --static --short-errors %PKGMSC% "guile-1.8" > %OUTDIR%\gl-l18.tmp 2> NUL\r
390 if not ERRORLEVEL 1 set /P GUILELIBS= < %OUTDIR%\gl-l18.tmp\r
391 \r
392 if not "%GUILECFLAGS%" == "" goto GuileDone\r
393 \r
394 echo - No Guile found, building without Guile\r
395 goto GuileDone\r
396 \r
397 :NoPkgCfg\r
398 echo - pkg-config not found, building without Guile\r
399 \r
400 :GuileDone\r
401 if "%GUILECFLAGS%" == "" goto :EOF\r
402 \r
403 echo - Guile found: building with Guile\r
404 set "GUILECFLAGS=%GUILECFLAGS% -DHAVE_GUILE"\r
405 goto :EOF\r
406 \r
407 :FindVswhere\r
408 set VSWHERE=vswhere\r
409 call "%VSWHERE%" -help >nul 2>&1\r
410 if not ERRORLEVEL 1 exit /b 0\r
411 set "VSWHERE=C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere"\r
412 call "%VSWHERE%" -help >nul 2>&1\r
413 if ERRORLEVEL 1 exit /b 1\r
414 goto :EOF\r
415 \r
416 :CheckMSVC\r
417 if not exist "%VSVARS%" exit /b 1\r
418 call "%VSVARS%" %ARCH%\r
419 if ERRORLEVEL 1 exit /b 1\r
420 call %COMPILER% >nul 2>&1\r
421 if ERRORLEVEL 1 exit /b 1\r
422 goto :EOF\r
423 \r
424 :NotConfig\r
425 echo.\r
426 echo *** This workspace is not configured.\r
427 echo Either retrieve the configured source in the release tarball\r
428 echo or, if building from Git, run the .\bootstrap.bat script first.\r
429 exit /b 1\r
430 \r
431 :Usage\r
432 echo Usage: %0 [options] [gcc] OR [tcc]\r
433 echo Options:\r
434 echo.  --without-guile   Do not compile Guile support even if found\r
435 echo.  --debug           Make a Debug build--default is Release\r
436 echo.  --x86             Make a 32bit binary--default is 64bit\r
437 echo.  --help            Display these instructions and exit\r
438 echo.\r
439 echo. "gcc" means compile with GCC, "tcc" means compile with Tiny C's TCC\r
440 goto :EOF\r
441 \r
442 :Reset\r
443 set ARCH=\r
444 set COMPILER=\r
445 set DEBUG=\r
446 set GUILE=\r
447 set GUILECFLAGS=\r
448 set GUILELIBS=\r
449 set LINKOPTS=\r
450 set MAKE=\r
451 set NOGUILE=\r
452 set O=\r
453 set OPTS=\r
454 set OUTDIR=\r
455 set LNKOUT=\r
456 set PKGMSC=\r
457 set VSVARS=\r
458 goto :EOF\r