Add 2007 to copyright years.
[bpt/emacs.git] / nt / configure.bat
1 @echo off
2 rem ----------------------------------------------------------------------
3 rem Configuration script for MS Windows 95/98/Me and NT/2000/XP
4 rem Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005,
5 rem 2006, 2007 Free Software Foundation, Inc.
6
7 rem This file is part of GNU Emacs.
8
9 rem GNU Emacs is free software; you can redistribute it and/or modify
10 rem it under the terms of the GNU General Public License as published by
11 rem the Free Software Foundation; either version 2, or (at your option)
12 rem any later version.
13
14 rem GNU Emacs is distributed in the hope that it will be useful,
15 rem but WITHOUT ANY WARRANTY; without even the implied warranty of
16 rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 rem GNU General Public License for more details.
18
19 rem You should have received a copy of the GNU General Public License
20 rem along with GNU Emacs; see the file COPYING. If not, write to the
21 rem Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 rem Boston, MA 02110-1301, USA.
23 rem ----------------------------------------------------------------------
24 rem YOU'LL NEED THE FOLLOWING UTILITIES TO MAKE EMACS:
25 rem
26 rem + MS Windows 95/98/Me or NT/2000/XP
27 rem + either MSVC 2.x or later, or gcc-2.95 or later (with gmake 3.75
28 rem or later) and the Mingw32 and W32 API headers and libraries.
29 rem + Visual Studio 2005 is not supported at this time.
30 rem
31 rem For reference, here is a list of which builds of gmake are known to
32 rem work or not, and whether they work in the presence and/or absence of
33 rem sh.exe.
34 rem
35 rem sh exists no sh
36 rem cygwin b20.1 make (3.75): fails[1,5] fails[2,5]
37 rem MSVC compiled gmake 3.77: okay okay
38 rem MSVC compiled gmake 3.78.1: okay okay
39 rem MSVC compiled gmake 3.79.1: okay okay
40 rem mingw32/gcc-2.92.2 make (3.77): okay okay[4]
41 rem cygwin compiled gmake 3.77: fails[1,5] fails[2,5]
42 rem cygwin compiled gmake 3.78.1: fails[5] fails[2,5]
43 rem cygwin compiled gmake 3.79.1: fails[3,5] fails[2?,5]
44 rem cygwin compiled make 3.80: fails?[6] fails?[6]
45 rem cygwin compiled make 3.81: fails fails?[6]
46 rem mingw32 compiled make 3.79.1: okay okay
47 rem mingw32 compiled make 3.80: okay okay?[6]
48 rem mingw32 compiled make 3.81: okay okay[7]
49 rem
50 rem [1] doesn't cope with makefiles with DOS line endings, so must mount
51 rem emacs source with text!=binary.
52 rem [2] fails when needs to invoke shell commands; okay invoking gcc etc.
53 rem [3] requires LC_MESSAGES support to build; cannot build with early
54 rem versions of cygwin.
55 rem [4] may fail on Windows 9X and Windows ME; if so, install Bash.
56 rem [5] fails when building leim due to the use of cygwin style paths.
57 rem May work if building emacs without leim.
58 rem [6] not recommended; please report if you try this combination.
59 rem [7] tested only on Windows XP.
60 rem
61
62 if exist config.log del config.log
63
64 rem ----------------------------------------------------------------------
65 rem See if the environment is large enough. We need 43 (?) bytes.
66 set $foo$=123456789_123456789_123456789_123456789_123
67 if not "%$foo$%" == "123456789_123456789_123456789_123456789_123" goto SmallEnv
68 set $foo$=
69
70 rem ----------------------------------------------------------------------
71 rem Make sure we are running in the nt subdir
72 if exist configure.bat goto start
73 echo You must run configure from the nt subdirectory.
74 goto end
75
76 :start
77 rem ----------------------------------------------------------------------
78 rem Default settings.
79 set prefix=
80 set nodebug=N
81 set noopt=N
82 set nocygwin=N
83 set COMPILER=
84 set usercflags=
85 set userldflags=
86 set sep1=
87 set sep2=
88
89 rem ----------------------------------------------------------------------
90 rem Handle arguments.
91 :again
92 if "%1" == "-h" goto usage
93 if "%1" == "--help" goto usage
94 if "%1" == "--prefix" goto setprefix
95 if "%1" == "--with-gcc" goto withgcc
96 if "%1" == "--with-msvc" goto withmsvc
97 if "%1" == "--no-debug" goto nodebug
98 if "%1" == "--no-opt" goto noopt
99 if "%1" == "--no-cygwin" goto nocygwin
100 if "%1" == "--cflags" goto usercflags
101 if "%1" == "--ldflags" goto userldflags
102 if "%1" == "--without-png" goto withoutpng
103 if "%1" == "--without-jpeg" goto withoutjpeg
104 if "%1" == "--without-gif" goto withoutgif
105 if "%1" == "--without-tiff" goto withouttiff
106 if "%1" == "--without-xpm" goto withoutxpm
107 if "%1" == "" goto checkutils
108 :usage
109 echo Usage: configure [options]
110 echo Options:
111 echo. --prefix PREFIX install Emacs in directory PREFIX
112 echo. --with-gcc use GCC to compile Emacs
113 echo. --with-msvc use MSVC to compile Emacs
114 echo. --no-debug exclude debug info from executables
115 echo. --no-opt disable optimization
116 echo. --no-cygwin use -mno-cygwin option with GCC
117 echo. --cflags FLAG pass FLAG to compiler
118 echo. --ldflags FLAG pass FLAG to compiler when linking
119 echo. --without-png do not use libpng even if it is installed
120 echo. --without-jpeg do not use jpeg-6b even if it is installed
121 echo. --without-gif do not use libungif even if it is installed
122 echo. --without-tiff do not use libtiff even if it is installed
123 echo. --without-xpm do not use libXpm even if it is installed
124 goto end
125 rem ----------------------------------------------------------------------
126 :setprefix
127 shift
128 set prefix=%1
129 shift
130 goto again
131 rem ----------------------------------------------------------------------
132 :withgcc
133 set COMPILER=gcc
134 shift
135 goto again
136 rem ----------------------------------------------------------------------
137 :withmsvc
138 set COMPILER=cl
139 shift
140 goto again
141 rem ----------------------------------------------------------------------
142 :nodebug
143 set nodebug=Y
144 shift
145 goto again
146 rem ----------------------------------------------------------------------
147 :noopt
148 set noopt=Y
149 shift
150 goto again
151 rem ----------------------------------------------------------------------
152 :nocygwin
153 set nocygwin=Y
154 shift
155 goto again
156 rem ----------------------------------------------------------------------
157 :usercflags
158 shift
159 set usercflags=%usercflags%%sep1%%1
160 set sep1= %nothing%
161 shift
162 goto again
163 rem ----------------------------------------------------------------------
164 :userldflags
165 shift
166 set userldflags=%userldflags%%sep2%%1
167 set sep2= %nothing%
168 shift
169 goto again
170 rem ----------------------------------------------------------------------
171
172 :withoutpng
173 set pngsupport=N
174 set HAVE_PNG=
175 shift
176 goto again
177
178 rem ----------------------------------------------------------------------
179
180 :withoutjpeg
181 set jpegsupport=N
182 set HAVE_JPEG=
183 shift
184 goto again
185
186 rem ----------------------------------------------------------------------
187
188 :withoutgif
189 set gifsupport=N
190 set HAVE_GIF=
191 shift
192 goto again
193
194 rem ----------------------------------------------------------------------
195
196 :withouttiff
197 set tiffsupport=N
198 set HAVE_TIFF=
199 shift
200 goto again
201
202 rem ----------------------------------------------------------------------
203
204 :withoutxpm
205 set xpmsupport=N
206 set HAVE_XPM=
207 shift
208 goto again
209
210 rem ----------------------------------------------------------------------
211 rem Check that necessary utilities (cp and rm) are present.
212 :checkutils
213 echo Checking for 'cp'...
214 cp configure.bat junk.bat
215 if not exist junk.bat goto needcp
216 echo Checking for 'rm'...
217 rm junk.bat
218 if exist junk.bat goto needrm
219 goto checkcompiler
220 :needcp
221 echo You need 'cp' (the Unix file copy program) to build Emacs.
222 goto end
223 :needrm
224 del junk.bat
225 echo You need 'rm' (the Unix file delete program) to build Emacs.
226 goto end
227
228 rem ----------------------------------------------------------------------
229 rem Auto-detect compiler if not specified, and validate GCC if chosen.
230 :checkcompiler
231 if (%COMPILER%)==(cl) goto compilercheckdone
232 if (%COMPILER%)==(gcc) goto checkgcc
233
234 echo Checking whether 'cl' is available...
235 echo main(){} >junk.c
236 cl -nologo -c junk.c
237 if exist junk.obj goto clOK
238
239 echo Checking whether 'gcc' is available...
240 gcc -c junk.c
241 if not exist junk.o goto nocompiler
242 del junk.o
243
244 :checkgcc
245 Rem WARNING -- COMMAND.COM on some systems only looks at the first
246 Rem 8 characters of a label. So do NOT be tempted to change
247 Rem chkapi* into something fancier like checkw32api
248 Rem You HAVE been warned!
249 if (%nocygwin%) == (Y) goto chkapi
250 echo Checking whether gcc requires '-mno-cygwin'...
251 echo #include "cygwin/version.h" >junk.c
252 echo main(){} >>junk.c
253 echo gcc -c junk.c >>config.log
254 gcc -c junk.c >>config.log 2>&1
255 if not exist junk.o goto chkapi
256 echo gcc -mno-cygwin -c junk.c >>config.log
257 gcc -mno-cygwin -c junk.c >>config.log 2>&1
258 if exist junk.o set nocygwin=Y
259 rm -f junk.c junk.o
260
261 :chkapi
262 echo The failed program was: >>config.log
263 type junk.c >>config.log
264 rem ----------------------------------------------------------------------
265 rem Older versions of the Windows API headers either don't have any of
266 rem the IMAGE_xxx definitions (the headers that come with Cygwin b20.1
267 rem are like this), or have a typo in the definition of
268 rem IMAGE_FIRST_SECTION (the headers with gcc/mingw32 2.95 have this
269 rem problem). The gcc/mingw32 2.95.2 headers are okay, as are distros
270 rem of w32api-xxx.zip from Anders Norlander since 1999-11-18 at least.
271 rem
272 echo Checking whether W32 API headers are too old...
273 echo #include "windows.h" >junk.c
274 echo test(PIMAGE_NT_HEADERS pHeader) >>junk.c
275 echo {PIMAGE_SECTION_HEADER pSection = IMAGE_FIRST_SECTION(pHeader);} >>junk.c
276 if (%nocygwin%) == (Y) goto chkapi1
277 set cf=%usercflags%
278 goto chkapi2
279 :chkapi1
280 set cf=%usercflags% -mno-cygwin
281 :chkapi2
282 echo on
283 gcc %cf% -c junk.c
284 @echo off
285 @echo gcc %cf% -c junk.c >>config.log
286 gcc %cf% -c junk.c >>config.log 2>&1
287 set cf=
288 if exist junk.o goto gccOk
289 echo The failed program was: >>config.log
290 type junk.c >>config.log
291
292 :nocompiler
293 echo.
294 echo Configure failed.
295 echo To configure Emacs for Windows, you need to have either
296 echo gcc-2.95 or later with Mingw32 and the W32 API headers,
297 echo or MSVC 2.x or later.
298 del junk.c
299 goto end
300
301 :gccOk
302 set COMPILER=gcc
303 echo Using 'gcc'
304 rm -f junk.c junk.o
305 Rem It is not clear what GCC version began supporting -mtune
306 Rem and pentium4 on x86, so check this explicitly.
307 echo main(){} >junk.c
308 echo gcc -c -O2 -mtune=pentium4 junk.c >>config.log
309 gcc -c -O2 -mtune=pentium4 junk.c >>config.log 2>&1
310 if not errorlevel 1 goto gccMtuneOk
311 echo The failed program was: >>config.log
312 type junk.c >>config.log
313 set mf=-mcpu=i686
314 rm -f junk.c junk.o
315 goto compilercheckdone
316 :gccMtuneOk
317 echo GCC supports -mtune=pentium4 >>config.log
318 set mf=-mtune=pentium4
319 rm -f junk.c junk.o
320 goto compilercheckdone
321
322 :clOk
323 set COMPILER=cl
324 rm -f junk.c junk.obj
325 echo Using 'MSVC'
326
327 :compilercheckdone
328
329 rem ----------------------------------------------------------------------
330 rem Check for external image libraries. Since they are loaded
331 rem dynamically, the libraries themselves do not need to be present
332 rem at compile time, but the header files are required.
333
334 set mingwflag=
335
336 if (%nocygwin%) == (N) goto flagsOK
337 set mingwflag=-mno-cygwin
338
339 :flagsOK
340
341 if (%pngsupport%) == (N) goto pngDone
342
343 echo Checking for libpng...
344 echo #include "png.h" >junk.c
345 echo main (){} >>junk.c
346 rem -o option is ignored with cl, but allows result to be consistent.
347 echo %COMPILER% %usercflags% %mingwflag% -c junk.c -o junk.obj >>config.log
348 %COMPILER% %usercflags% %mingwflag% -c junk.c -o junk.obj >junk.out 2>>config.log
349 if exist junk.obj goto havePng
350
351 echo ...png.h not found, building without PNG support.
352 echo The failed program was: >>config.log
353 type junk.c >>config.log
354 set HAVE_PNG=
355 goto :pngDone
356
357 :havePng
358 echo ...PNG header available, building with PNG support.
359 set HAVE_PNG=1
360
361 :pngDone
362 rm -f junk.c junk.obj
363
364 if (%jpegsupport%) == (N) goto jpegDone
365
366 echo Checking for jpeg-6b...
367 echo #include "jconfig.h" >junk.c
368 echo main (){} >>junk.c
369 rem -o option is ignored with cl, but allows result to be consistent.
370 echo %COMPILER% %usercflags% %mingwflag% -c junk.c -o junk.obj >>config.log
371 %COMPILER% %usercflags% %mingwflag% -c junk.c -o junk.obj >junk.out 2>>config.log
372 if exist junk.obj goto haveJpeg
373
374 echo ...jconfig.h not found, building without JPEG support.
375 echo The failed program was: >>config.log
376 type junk.c >>config.log
377 set HAVE_JPEG=
378 goto :jpegDone
379
380 :haveJpeg
381 echo ...JPEG header available, building with JPEG support.
382 set HAVE_JPEG=1
383
384 :jpegDone
385 rm -f junk.c junk.obj
386
387 if (%gifsupport%) == (N) goto gifDone
388
389 echo Checking for libgif...
390 echo #include "gif_lib.h" >junk.c
391 echo main (){} >>junk.c
392 rem -o option is ignored with cl, but allows result to be consistent.
393 echo %COMPILER% %usercflags% %mingwflag% -c junk.c -o junk.obj >>config.log
394 %COMPILER% %usercflags% %mingwflag% -c junk.c -o junk.obj >junk.out 2>>config.log
395 if exist junk.obj goto haveGif
396
397 echo ...gif_lib.h not found, building without GIF support.
398 echo The failed program was: >>config.log
399 type junk.c >>config.log
400 set HAVE_GIF=
401 goto :gifDone
402
403 :haveGif
404 echo ...GIF header available, building with GIF support.
405 set HAVE_GIF=1
406
407 :gifDone
408 rm -f junk.c junk.obj
409
410 if (%tiffsupport%) == (N) goto tiffDone
411
412 echo Checking for tiff...
413 echo #include "tiffio.h" >junk.c
414 echo main (){} >>junk.c
415 rem -o option is ignored with cl, but allows result to be consistent.
416 echo %COMPILER% %usercflags% %mingwflag% -c junk.c -o junk.obj >>config.log
417 %COMPILER% %usercflags% %mingwflag% -c junk.c -o junk.obj >junk.out 2>>config.log
418 if exist junk.obj goto haveTiff
419
420 echo ...tiffio.h not found, building without TIFF support.
421 echo The failed program was: >>config.log
422 type junk.c >>config.log
423 set HAVE_TIFF=
424 goto :tiffDone
425
426 :haveTiff
427 echo ...TIFF header available, building with TIFF support.
428 set HAVE_TIFF=1
429
430 :tiffDone
431 rm -f junk.c junk.obj
432
433 if (%xpmsupport%) == (N) goto xpmDone
434
435 echo Checking for libXpm...
436 echo #define FOR_MSW 1 >junk.c
437 echo #include "X11/xpm.h" >>junk.c
438 echo main (){} >>junk.c
439 rem -o option is ignored with cl, but allows result to be consistent.
440 echo %COMPILER% %usercflags% %mingwflag% -c junk.c -o junk.obj >>config.log
441 %COMPILER% %usercflags% %mingwflag% -c junk.c -o junk.obj >junk.out 2>>config.log
442 if exist junk.obj goto haveXpm
443
444 echo ...X11/xpm.h not found, building without XPM support.
445 echo The failed program was: >>config.log
446 type junk.c >>config.log
447 set HAVE_XPM=
448 goto :xpmDone
449
450 :haveXpm
451 echo ...XPM header available, building with XPM support.
452 set HAVE_XPM=1
453
454 :xpmDone
455 rm -f junk.c junk.obj junk.err junk.out
456
457 rem ----------------------------------------------------------------------
458 :genmakefiles
459 echo Generating makefiles
460 if %COMPILER% == gcc set MAKECMD=gmake
461 if %COMPILER% == cl set MAKECMD=nmake
462
463 rem Pass on chosen settings to makefiles.
464 rem NB. Be very careful to not have a space before redirection symbols
465 rem except when there is a preceding digit, when a space is required.
466 rem
467 echo # Start of settings from configure.bat >config.settings
468 echo COMPILER=%COMPILER%>>config.settings
469 if not "(%mf%)" == "()" echo MCPU_FLAG=%mf%>>config.settings
470 if (%nodebug%) == (Y) echo NODEBUG=1 >>config.settings
471 if (%noopt%) == (Y) echo NOOPT=1 >>config.settings
472 if (%nocygwin%) == (Y) echo NOCYGWIN=1 >>config.settings
473 if not "(%prefix%)" == "()" echo INSTALL_DIR=%prefix%>>config.settings
474 if not "(%usercflags%)" == "()" echo USER_CFLAGS=%usercflags%>>config.settings
475 if not "(%userldflags%)" == "()" echo USER_LDFLAGS=%userldflags%>>config.settings
476 echo # End of settings from configure.bat>>config.settings
477 echo. >>config.settings
478
479 copy config.nt config.tmp
480 echo. >>config.tmp
481 echo /* Start of settings from configure.bat. */ >>config.tmp
482 if not "(%usercflags%)" == "()" echo #define USER_CFLAGS " %usercflags%">>config.tmp
483 if not "(%userldflags%)" == "()" echo #define USER_LDFLAGS " %userldflags%">>config.tmp
484 if not "(%HAVE_PNG%)" == "()" echo #define HAVE_PNG 1 >>config.tmp
485 if not "(%HAVE_JPEG%)" == "()" echo #define HAVE_JPEG 1 >>config.tmp
486 if not "(%HAVE_GIF%)" == "()" echo #define HAVE_GIF 1 >>config.tmp
487 if not "(%HAVE_TIFF%)" == "()" echo #define HAVE_TIFF 1 >>config.tmp
488 if not "(%HAVE_XPM%)" == "()" echo #define HAVE_XPM 1 >>config.tmp
489 echo /* End of settings from configure.bat. */ >>config.tmp
490
491 Rem See if fc.exe returns a meaningful exit status. If it does, we
492 Rem might as well avoid unnecessary overwriting of config.h and epaths.h,
493 Rem since this forces recompilation of every source file.
494 if exist foo.bar del foo.bar
495 fc /b foo.bar foo.bar >nul 2>&1
496 if not errorlevel 2 goto doCopy
497 fc /b config.tmp ..\src\config.h >nul 2>&1
498 if errorlevel 1 goto doCopy
499 fc /b paths.h ..\src\epaths.h >nul 2>&1
500 if errorlevel 0 goto dontCopy
501 :doCopy
502 copy config.tmp ..\src\config.h
503 copy paths.h ..\src\epaths.h
504
505 :dontCopy
506 if exist config.tmp del config.tmp
507 copy /b config.settings+%MAKECMD%.defs+..\nt\makefile.w32-in ..\nt\makefile
508 copy /b config.settings+%MAKECMD%.defs+..\lib-src\makefile.w32-in ..\lib-src\makefile
509 copy /b config.settings+%MAKECMD%.defs+..\src\makefile.w32-in ..\src\makefile
510 copy /b config.settings+%MAKECMD%.defs+..\man\makefile.w32-in ..\man\makefile
511 copy /b config.settings+%MAKECMD%.defs+..\lispref\makefile.w32-in ..\lispref\makefile
512 copy /b config.settings+%MAKECMD%.defs+..\lispintro\makefile.w32-in ..\lispintro\makefile
513 if exist ..\lisp\makefile rm -f ../lisp/[Mm]akefile
514 copy /b config.settings+%MAKECMD%.defs+..\lisp\makefile.w32-in ..\lisp\makefile
515 rem Use the default (no-op) Makefile.in if the nt version is not present.
516 if exist ..\leim\makefile.w32-in copy /b config.settings+%MAKECMD%.defs+..\leim\makefile.w32-in ..\leim\makefile
517 if not exist ..\leim\makefile.w32-in copy /b config.settings+%MAKECMD%.defs+..\leim\Makefile.in ..\leim\makefile
518 del config.settings
519
520 Rem Some people use WinZip which doesn't create empty directories!
521 if not exist ..\site-lisp\nul mkdir ..\site-lisp\
522 if not exist ..\site-lisp\subdirs.el copy subdirs.el ..\site-lisp\subdirs.el
523
524 echo.
525 echo Emacs successfully configured.
526 echo Emacs successfully configured. >>config.log
527 echo Run `%MAKECMD%' to build, then run `%MAKECMD% install' to install.
528 goto end
529
530 :SmallEnv
531 echo Your environment size is too small. Please enlarge it and rerun configure.
532 echo For example, type "command.com /e:2048" to have 2048 bytes available.
533 set $foo$=
534 :end
535 set prefix=
536 set nodebug=
537 set noopt=
538 set nocygwin=
539 set COMPILER=
540 set MAKECMD=
541 set usercflags=
542 set userldflags=
543 set mingwflag=
544 set mf=
545
546 goto skipArchTag
547 arch-tag: 300d20a4-1675-4e75-b615-7ce1a8c5376c
548 :skipArchTag