Change make license
[platform/upstream/make.git] / build_w32.bat
1 @echo off\r
2 :: Copyright (C) 1996-2020 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 <http://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 \r
41 if exist maintMakefile (\r
42     set MAINT=Y\r
43 ) else (\r
44     set MAINT=N\r
45 )\r
46 \r
47 :ParseSW\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
53 goto Usage\r
54 \r
55 :SetDebug\r
56 set DEBUG=Y\r
57 echo - Building without compiler optimizations\r
58 shift\r
59 goto ParseSW\r
60 \r
61 :NoGuile\r
62 set GUILE=N\r
63 echo - Building without Guile\r
64 shift\r
65 goto ParseSW\r
66 \r
67 :Set32Bit\r
68 set ARCH=x86\r
69 echo - Building 32bit GNU Make\r
70 shift\r
71 goto ParseSW\r
72 \r
73 :SetCC\r
74 set COMPILER=gcc\r
75 set O=o\r
76 echo - Building with GCC\r
77 shift\r
78 goto ParseSW\r
79 \r
80 :DoneSW\r
81 if "%MAINT%" == "Y" echo - Enabling maintainer mode\r
82 \r
83 if "%COMPILER%" == "gcc" goto FindGcc\r
84 \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
88 \r
89 :: Visual Studio 17 and above provides the "vswhere" tool\r
90 call :FindVswhere\r
91 if ERRORLEVEL 1 goto LegacyVS\r
92 \r
93 for /f "tokens=* usebackq" %%i in (`%VSWHERE% -latest -property installationPath`) do (\r
94     set InstallPath=%%i\r
95 )\r
96 set "VSVARS=%InstallPath%\VC\Auxiliary\Build\vcvarsall.bat"\r
97 call :CheckMSVC\r
98 if not ERRORLEVEL 1 goto FoundMSVC\r
99 \r
100 :: No "vswhere" or it can't find a compiler.  Go old-school.\r
101 :LegacyVS\r
102 set "VSVARS=%VS150COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
103 call :CheckMSVC\r
104 if not ERRORLEVEL 1 goto FoundMSVC\r
105 \r
106 set "VSVARS=%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
107 call :CheckMSVC\r
108 if not ERRORLEVEL 1 goto FoundMSVC\r
109 \r
110 set "VSVARS=%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
111 call :CheckMSVC\r
112 if not ERRORLEVEL 1 goto FoundMSVC\r
113 \r
114 set "VSVARS=%VS110COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
115 call :CheckMSVC\r
116 if not ERRORLEVEL 1 goto FoundMSVC\r
117 \r
118 set "VSVARS=%VS100COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
119 call :CheckMSVC\r
120 if not ERRORLEVEL 1 goto FoundMSVC\r
121 \r
122 set "VSVARS=%VS90COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
123 call :CheckMSVC\r
124 if not ERRORLEVEL 1 goto FoundMSVC\r
125 \r
126 set "VSVARS=%VS80COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
127 call :CheckMSVC\r
128 if not ERRORLEVEL 1 goto FoundMSVC\r
129 \r
130 set "VSVARS=%VS71COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
131 call :CheckMSVC\r
132 if not ERRORLEVEL 1 goto FoundMSVC\r
133 \r
134 set "VSVARS=%VS70COMNTOOLS%\..\..\VC\vcvarsall.bat"\r
135 call :CheckMSVC\r
136 if not ERRORLEVEL 1 goto FoundMSVC\r
137 \r
138 set "VSVARS=%V6TOOLS%\VC98\Bin\vcvars32.bat"\r
139 call :CheckMSVC\r
140 if not ERRORLEVEL 1 goto FoundMSVC\r
141 \r
142 set "VSVARS=%V6TOOLS%\VC97\Bin\vcvars32.bat"\r
143 call :CheckMSVC\r
144 if not ERRORLEVEL 1 goto FoundMSVC\r
145 \r
146 set "VSVARS=%V5TOOLS%\VC\Bin\vcvars32.bat"\r
147 call :CheckMSVC\r
148 if not ERRORLEVEL 1 goto FoundMSVC\r
149 \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
153 exit 1\r
154 \r
155 :FoundMSVC\r
156 set OUTDIR=.\WinRel\r
157 set LNKOUT=./WinRel\r
158 set "OPTS=/O2 /D NDEBUG"\r
159 set LINKOPTS=\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
167 echo.\r
168 %COMPILER%\r
169 goto Build\r
170 \r
171 :FindGcc\r
172 set OUTDIR=.\GccRel\r
173 set LNKOUT=./GccRel\r
174 set OPTS=-O2\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
180 echo.\r
181 %COMPILER% --version\r
182 if not ERRORLEVEL 1 goto Build\r
183 echo No %COMPILER% found.\r
184 exit 1\r
185 \r
186 :Build\r
187 :: Clean the directory if it exists\r
188 if exist %OUTDIR%\nul rmdir /S /Q %OUTDIR%\r
189 \r
190 :: Recreate it\r
191 mkdir %OUTDIR%\r
192 mkdir %OUTDIR%\src\r
193 mkdir %OUTDIR%\src\w32\r
194 mkdir %OUTDIR%\src\w32\compat\r
195 mkdir %OUTDIR%\src\w32\subproc\r
196 mkdir %OUTDIR%\lib\r
197 \r
198 if "%GUILE%" == "Y" call :ChkGuile\r
199 \r
200 echo.\r
201 echo Compiling %OUTDIR% version\r
202 \r
203 if exist src\config.h.W32.template call :ConfigSCM\r
204 copy src\config.h.W32 %OUTDIR%\src\config.h\r
205 \r
206 copy lib\glob.in.h %OUTDIR%\lib\glob.h\r
207 copy lib\fnmatch.in.h %OUTDIR%\lib\fnmatch.h\r
208 \r
209 if exist %OUTDIR%\link.sc del %OUTDIR%\link.sc\r
210 \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
248 \r
249 if not "%COMPILER%" == "gcc" call :Compile src\w32\compat\dirent\r
250 \r
251 call :Link\r
252 \r
253 echo.\r
254 if exist %OUTDIR%\%MAKE%.exe goto Success\r
255 echo %OUTDIR% build FAILED!\r
256 exit 1\r
257 \r
258 :Success\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
262 call :Reset\r
263 goto :EOF\r
264 \r
265 ::\r
266 :: Subroutines\r
267 ::\r
268 \r
269 :Compile\r
270 echo %LNKOUT%/%1.%O% >>%OUTDIR%\link.sc\r
271 set EXTRAS=\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
275 \r
276 :: MSVC Compile\r
277 echo on\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
279 @echo off\r
280 goto CompileDone\r
281 \r
282 :GccCompile\r
283 :: GCC Compile\r
284 echo on\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
286 @echo off\r
287 \r
288 :CompileDone\r
289 if not exist "%OUTDIR%\%1.%O%" exit 1\r
290 goto :EOF\r
291 \r
292 :Link\r
293 echo.\r
294 echo Linking %LNKOUT%/%MAKE%.exe\r
295 if "%COMPILER%" == "gcc" goto GccLink\r
296 \r
297 :: MSVC Link\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
299 echo on\r
300 link.exe /NOLOGO /SUBSYSTEM:console /PDB:%LNKOUT%\%MAKE%.pdb %LINKOPTS% /OUT:%LNKOUT%\%MAKE%.exe @%LNKOUT%\link.sc\r
301 @echo off\r
302 goto :EOF\r
303 \r
304 :GccLink\r
305 :: GCC Link\r
306 echo on\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
309 @echo off\r
310 goto :EOF\r
311 \r
312 :ConfigSCM\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
320 goto :EOF\r
321 \r
322 :ChkGuile\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
327 \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
332 \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
335 \r
336 if not "%GUILECFLAGS%" == "" goto GuileDone\r
337 \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
341 \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
344 \r
345 if not "%GUILECFLAGS%" == "" goto GuileDone\r
346 \r
347 echo - No Guile found, building without Guile\r
348 goto GuileDone\r
349 \r
350 :NoPkgCfg\r
351 echo - pkg-config not found, building without Guile\r
352 \r
353 :GuileDone\r
354 if "%GUILECFLAGS%" == "" goto :EOF\r
355 \r
356 echo - Guile found: building with Guile\r
357 set "GUILECFLAGS=%GUILECFLAGS% -DHAVE_GUILE"\r
358 goto :EOF\r
359 \r
360 :FindVswhere\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
367 goto :EOF\r
368 \r
369 :CheckMSVC\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
375 goto :EOF\r
376 \r
377 :Usage\r
378 echo Usage: %0 [options] [gcc]\r
379 echo Options:\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
384 goto :EOF\r
385 \r
386 :Reset\r
387 set ARCH=\r
388 set COMPILER=\r
389 set DEBUG=\r
390 set GUILE=\r
391 set GUILECFLAGS=\r
392 set GUILELIBS=\r
393 set LINKOPTS=\r
394 set MAKE=\r
395 set NOGUILE=\r
396 set O=\r
397 set OPTS=\r
398 set OUTDIR=\r
399 set LNKOUT=\r
400 set PKGMSC=\r
401 set VSVARS=\r
402 goto :EOF\r