Make a mingw tree from mingw tarballs
[ghc-hetmet.git] / configure.ac
1 dnl == autoconf source for the Glasgow FP tools ==
2 dnl (run "grep '^dnl \*' configure.ac | sed -e 's/dnl / /g; s/\*\*/   +/g;'"
3 dnl  (or some such) to see the outline of this file)
4 dnl
5 #
6 # (c) The University of Glasgow 1994-2004
7 #
8 # Configure script template for GHC
9 #
10 # Process with 'autoreconf' to get a working configure script.
11 #
12 # For the generated configure script, do "./configure --help" to
13 # see what flags are available. (Better yet, read the documentation!)
14 #
15
16 AC_INIT([The Glorious Glasgow Haskell Compilation System], [6.13], [glasgow-haskell-bugs@haskell.org], [ghc])
17
18 # Set this to YES for a released version, otherwise NO
19 : ${RELEASE=NO}
20
21 set -e
22
23 # The primary version (e.g. 6.7, 6.6.1) is set in the AC_INIT line
24 # above.  If this is not a released version, then we will append the
25 # date to the version number (e.g. 6.7.20070204).  The date is
26 # constructed by finding the date of the most recent patch in the
27 # darcs repository.  If this is a source distribution (not a darcs
28 # checkout), then we ship a file 'VERSION' containing the full version
29 # when the source distribution was created.
30
31 if test ! -f mk/config.h.in; then
32    echo "mk/config.h.in doesn't exist: perhaps you haven't run 'sh boot'?"
33    exit 1
34 fi
35
36 AC_SUBST([CONFIGURE_ARGS], [$ac_configure_args])
37
38 dnl ----------------------------------------------------------
39 dnl ** Find unixy sort and find commands, 
40 dnl ** which are needed by FP_SETUP_PROJECT_VERSION
41
42 dnl ** Find find command (for Win32's benefit)
43 FP_PROG_FIND
44
45 dnl ** Find sort command (for the benefit of Win32 environs)
46 FP_PROG_SORT
47
48 dnl ----------------------------------------------------------
49 FP_SETUP_PROJECT_VERSION
50
51 # Hmmm, we fix the RPM release number to 1 here... Is this convenient?
52 AC_SUBST([release], [1])
53
54 # First off, a distrib sanity check..
55 AC_CONFIG_SRCDIR([mk/config.mk.in])
56
57 dnl * We require autoconf version 2.52
58 dnl We need 2.50 due to the use of AC_SYS_LARGEFILE and AC_MSG_NOTICE.
59 dnl We need 2.52 due to the use of AS_TR_CPP and AS_TR_SH.
60 AC_PREREQ([2.52])
61
62 # -------------------------------------------------------------------------
63 # Prepare to generate the following header files
64 #
65 #
66 AC_CONFIG_HEADER(mk/config.h)
67
68 # No, semi-sadly, we don't do `--srcdir'...
69 if test x"$srcdir" != 'x.' ; then
70     echo "This configuration does not support the \`--srcdir' option.."
71     exit 1
72 fi
73
74 dnl --------------------------------------------------------------
75 dnl * Project specific configuration options
76 dnl --------------------------------------------------------------
77 dnl What follows is a bunch of options that can either be configured
78 dnl through command line options to the configure script or by
79 dnl supplying defns in the build tree's mk/build.mk. Having the option to
80 dnl use either is considered a Feature.
81
82 dnl ** What command to use to compile compiler sources ?
83 dnl --------------------------------------------------------------
84
85 AC_ARG_WITH([ghc],
86 [AC_HELP_STRING([--with-ghc=ARG],
87   [Use ARG as the path to GHC  [default=autodetect]])],
88   [WithGhc="$withval"],
89   [if test "$GHC" = ""; then
90     AC_PATH_PROG([GHC], [ghc])
91   fi
92   WithGhc="$GHC"])
93
94 dnl ** Booting from .hc files?
95 dnl --------------------------------------------------------------
96 AC_ARG_ENABLE(hc-boot,
97 [AC_HELP_STRING([--enable-hc-boot],
98 [Boot the Glasgow Haskell Compiler from intermediate .hc files.
99  (This option is mostly of interest to porters.) [default=no]])],
100 [ if test x"$enableval" = x"yes"; then
101         BootingFromHc=YES
102   else
103         BootingFromHc=NO
104   fi
105 ],
106 [BootingFromHc=NO]
107 )
108 AC_SUBST(BootingFromHc)
109
110 AC_ARG_ENABLE(bootstrap-with-devel-snapshot,
111 [AC_HELP_STRING([--enable-bootstrap-with-devel-snapshot],
112                 [Allow bootstrapping using a development snapshot of GHC.  This is not guaranteed to work.])],
113         EnableBootstrapWithDevelSnaphost=YES,
114         EnableBootstrapWithDevelSnaphost=NO
115 )
116
117 if test "$WithGhc" != ""; then
118   FPTOOLS_GHC_VERSION([GhcVersion], [GhcMajVersion], [GhcMinVersion], [GhcPatchLevel])dnl
119
120   if test "$GhcMajVersion" = "unknown" -o "$GhcMinVersion" = "unknown"; then
121      AC_MSG_ERROR([Cannot determine the version of $WithGhc.  Is it really GHC?])
122   fi
123
124   AC_SUBST(GhcVersion)dnl
125   AC_SUBST(GhcMajVersion)dnl
126   AC_SUBST(GhcMinVersion)dnl
127   AC_SUBST(GhcPatchLevel)dnl
128   GhcMinVersion2=`echo "$GhcMinVersion" | sed 's/^\\(.\\)$/0\\1/'`
129   GhcCanonVersion="$GhcMajVersion$GhcMinVersion2"
130   if test $GhcCanonVersion -ge 609; then ghc_ge_609=YES; else ghc_ge_609=NO; fi
131   FP_COMPARE_VERSIONS($GhcVersion,[-ge],[6.10.2],
132                       [ghc_ge_6102=YES], [ghc_ge_6102=NO])
133   if test $GhcCanonVersion -ge 611; then ghc_ge_611=YES; else ghc_ge_611=NO; fi
134   AC_SUBST(ghc_ge_609)dnl
135   AC_SUBST(ghc_ge_6102)dnl
136   AC_SUBST(ghc_ge_611)dnl
137 fi
138
139 dnl ** Must have GHC to build GHC, unless --enable-hc-boot is on
140 if test "$BootingFromHc" = "NO" -a -d "$srcdir/compiler"; then
141   if test "$WithGhc" = ""; then
142      AC_MSG_ERROR([GHC is required unless bootstrapping from .hc files.])
143   fi
144   FP_COMPARE_VERSIONS([$GhcVersion],[-lt],[6.8],
145     [AC_MSG_ERROR([GHC version 6.8 or later is required to compile GHC.])])dnl
146
147   if test `expr $GhcMinVersion % 2` = "1"; then
148      if test "$EnableBootstrapWithDevelSnaphost" = "NO"; then
149         AC_MSG_ERROR([
150      $WithGhc is a development snapshot of GHC, version $GhcVersion.
151      Bootstrapping using this version of GHC is not supported, and may not
152      work.  Use --enable-bootstrap-with-devel-snapshot to try it anyway,
153      or --with-ghc to specify a different GHC to use.])
154      fi
155   fi
156 fi;
157
158 # GHC is passed to Cabal, so we need a native path
159 if test "${WithGhc}" != ""
160 then
161     ghc_host=`${WithGhc} +RTS --info | grep 'Host platform' | sed -e 's/.*, "//' -e 's/")//'`
162
163     if test "$ghc_host" = "i386-unknown-mingw32"
164     then
165         if test "${OSTYPE}" = "msys"
166         then
167             WithGhc=`echo "${WithGhc}" | sed "s#^/\([a-zA-Z]\)/#\1:/#"`
168         else
169             # Canonicalise to <drive>:/path/to/ghc
170             WithGhc=`cygpath -m ${WithGhc}`
171         fi
172         echo "GHC path canonicalised to: ${WithGhc}"
173     fi
174 fi
175 AC_SUBST([WithGhc])
176
177 dnl ** Without optimization some INLINE trickery fails for GHCi
178 SRC_CC_OPTS="-O"
179
180 dnl Allow to specify iconv options to the toplevel configure script
181 dnl so they can be properly passed to sub-builds.
182 dnl Note: ICONV_LIB_DIRS and ICONV_INCLUDE_DIRS are not predefined
183 dnl to the empty string to allow them to be overridden from the
184 dnl environment.
185
186 AC_ARG_WITH([iconv-includes],
187   [AC_HELP_STRING([--with-iconv-includes],
188     [directory containing iconv.h])],
189     [ICONV_INCLUDE_DIRS=$withval])
190
191 AC_ARG_WITH([iconv-libraries],
192   [AC_HELP_STRING([--with-iconv-libraries],
193     [directory containing iconv library])],
194     [ICONV_LIB_DIRS=$withval])
195
196 AC_SUBST(ICONV_INCLUDE_DIRS)
197 AC_SUBST(ICONV_LIB_DIRS)
198
199 dnl--------------------------------------------------------------------
200 dnl * Choose host(/target/build) platform
201 dnl--------------------------------------------------------------------
202 dnl We don't use the standard autoconf macros for this, but instead
203 dnl ask the bootstrapping compiler what platform it is for
204
205 dnl Guess host/target/build platform(s) if necessary.
206 m4_divert_once([HELP_CANON],
207 [[
208 System types:
209   --build=BUILD     configure for building on BUILD [guessed]
210   --host=HOST       cross-compile to build programs to run on HOST [guessed]
211   --target=TARGET   configure for building compilers for TARGET [guessed]]])dnl
212
213 if test "$build" = ""
214 then
215     if test "${WithGhc}" != ""
216     then
217         build=`${WithGhc} +RTS --info | grep '^ ,("Target platform"' | sed -e 's/.*, "//' -e 's/")//' | tr -d '\r'`
218         echo "Build platform inferred as: $build"
219     else
220         echo "Can't work out build platform"
221         exit 1
222     fi
223 fi
224
225 if test "$host" = ""
226 then
227     if test "${WithGhc}" != ""
228     then
229         host=`${WithGhc} +RTS --info | grep '^ ,("Target platform"' | sed -e 's/.*, "//' -e 's/")//' | tr -d '\r'`
230         echo "Host platform inferred as: $host"
231     else
232         echo "Can't work out host platform"
233         exit 1
234     fi
235 fi
236
237 if test "$target" = ""
238 then
239     if test "${WithGhc}" != ""
240     then
241         target=`${WithGhc} +RTS --info | grep '^ ,("Target platform"' | sed -e 's/.*, "//' -e 's/")//' | tr -d '\r'`
242         echo "Target platform inferred as: $target"
243     else
244         echo "Can't work out target platform"
245         exit 1
246     fi
247 fi
248
249 exeext=''
250 soext='.so'
251 case $host in
252 *-unknown-cygwin32)
253     AC_MSG_WARN([GHC does not support the Cygwin target at the moment])
254     AC_MSG_WARN([I'm assuming you wanted to build for i386-unknown-mingw32])
255     exit 1
256     ;;
257 *-unknown-mingw32)
258     exeext='.exe'
259     soext='.dll'
260     ;;
261 i386-apple-darwin|powerpc-apple-darwin)
262     soext='.dylib'
263     CFLAGS="$CFLAGS -m32"
264     LDFLAGS="$LDFLAGS -m32"
265     CONF_CC_OPTS="$CONF_CC_OPTS -m32"
266     CONF_LD_OPTS="$CONF_LD_OPTS -m32"
267     ;;
268 x86_64-apple-darwin)
269     soext='.dylib'
270     CFLAGS="$CFLAGS -m64"
271     LDFLAGS="$LDFLAGS -m64"
272     CONF_CC_OPTS="$CONF_CC_OPTS -m64"
273     CONF_LD_OPTS="$CONF_LD_OPTS -m64"
274     ;;
275 esac
276
277 checkArch() {
278     case $1 in
279     alpha|arm|hppa|hppa1_1|i386|ia64|m68k|mips|mipseb|mipsel|powerpc|powerpc64|rs6000|s390|sparc|sparc64|vax|x86_64)
280         ;;
281     *)
282         echo "Unknown arch $1"
283         exit 1
284         ;;
285     esac
286 }
287
288 checkVendor() {
289     case $1 in
290     dec|unknown|hp|apple|next|sun|sgi|ibm)
291         ;;
292     *)
293         echo "Unknown vendor $1"
294         exit 1
295         ;;
296     esac
297 }
298
299 checkOS() {
300     case $1 in
301     linux|freebsd|netbsd|openbsd|osf1|osf3|hpux|linuxaout|kfreebsdgnu|freebsd2|solaris2|cygwin32|mingw32|darwin|gnu|nextstep2|nextstep3|sunos4|ultrix|irix|aix)
302         ;;
303     *)
304         echo "Unknown OS '$1'"
305         exit 1
306         ;;
307     esac
308 }
309
310 BuildPlatform=$build
311 BuildArch=`echo "$build" | sed 's/-.*//'`
312 BuildVendor=`echo "$build" | sed -e 's/.*-\(.*\)-.*/\1/'`
313 BuildOS=`echo "$build" | sed 's/.*-//'`
314 BuildPlatform_CPP=`echo "$BuildPlatform" | sed -e 's/\./_/g' -e 's/-/_/g'`
315 BuildArch_CPP=`    echo "$BuildArch"     | sed -e 's/\./_/g' -e 's/-/_/g'`
316 BuildVendor_CPP=`  echo "$BuildVendor"   | sed -e 's/\./_/g' -e 's/-/_/g'`
317 BuildOS_CPP=`      echo "$BuildOS"       | sed -e 's/\./_/g' -e 's/-/_/g'`
318
319 checkArch "$BuildArch"
320 checkVendor "$BuildVendor"
321 checkOS "$BuildOS"
322
323 HostPlatform=$host
324 HostArch=`echo "$host" | sed 's/-.*//'`
325 HostVendor=`echo "$host" | sed -e 's/.*-\(.*\)-.*/\1/'`
326 HostOS=`echo "$host" | sed 's/.*-//'`
327 HostPlatform_CPP=`echo "$HostPlatform" | sed -e 's/\./_/g' -e 's/-/_/g'`
328 HostArch_CPP=`    echo "$HostArch"     | sed -e 's/\./_/g' -e 's/-/_/g'`
329 HostVendor_CPP=`  echo "$HostVendor"   | sed -e 's/\./_/g' -e 's/-/_/g'`
330 HostOS_CPP=`      echo "$HostOS"       | sed -e 's/\./_/g' -e 's/-/_/g'`
331
332 checkArch "$HostArch"
333 checkVendor "$HostVendor"
334 checkOS "$HostOS"
335
336 TargetPlatform=$target
337 TargetArch=`echo "$target" | sed 's/-.*//'`
338 TargetVendor=`echo "$target" | sed -e 's/.*-\(.*\)-.*/\1/'`
339 TargetOS=`echo "$target" | sed 's/.*-//'`
340 TargetPlatform_CPP=`echo "$TargetPlatform" | sed -e 's/\./_/g' -e 's/-/_/g'`
341 TargetArch_CPP=`    echo "$TargetArch"     | sed -e 's/\./_/g' -e 's/-/_/g'`
342 TargetVendor_CPP=`  echo "$TargetVendor"   | sed -e 's/\./_/g' -e 's/-/_/g'`
343 TargetOS_CPP=`      echo "$TargetOS"       | sed -e 's/\./_/g' -e 's/-/_/g'`
344
345 checkArch "$TargetArch"
346 checkVendor "$TargetVendor"
347 checkOS "$TargetOS"
348
349 AC_SUBST(BuildPlatform)
350 AC_SUBST(HostPlatform)
351 AC_SUBST(TargetPlatform)
352 AC_SUBST(HostPlatform_CPP)
353 AC_SUBST(BuildPlatform_CPP)
354 AC_SUBST(TargetPlatform_CPP)
355
356 AC_SUBST(HostArch_CPP)
357 AC_SUBST(BuildArch_CPP)
358 AC_SUBST(TargetArch_CPP)
359
360 AC_SUBST(HostOS_CPP)
361 AC_SUBST(BuildOS_CPP)
362 AC_SUBST(TargetOS_CPP)
363
364 AC_SUBST(HostVendor_CPP)
365 AC_SUBST(BuildVendor_CPP)
366 AC_SUBST(TargetVendor_CPP)
367
368 AC_SUBST(exeext)
369 AC_SUBST(soext)
370
371 AC_ARG_WITH(hc,
372 [AC_HELP_STRING([--with-hc=ARG],
373         [Use ARG as the path to the compiler for compiling ordinary
374          Haskell code  (default= value of --with-ghc)])],
375 [WithHc="$withval"],
376 [WithHc=$WithGhc]
377 )
378 AC_SUBST(WithHc)
379
380 AC_PATH_PROGS(NHC,nhc nhc98)
381 AC_PATH_PROG(HBC,hbc)
382
383 # This uses GHC, so put it after the "GHC is required" check above:
384 FP_FIND_ROOT
385
386 if test "$HostOS" = "mingw32"
387 then
388     CC="$hardtop/inplace/mingw/bin/gcc.exe"
389     LD="$hardtop/inplace/mingw/bin/ld.exe"
390     NM="$hardtop/inplace/mingw/bin/nm.exe"
391     if ! test -d inplace/mingw ||
392          test inplace/mingw -ot ghc-tarballs/mingw/binutils*.tar.gz ||
393          test inplace/mingw -ot ghc-tarballs/mingw/gcc-core*.tar.gz ||
394          test inplace/mingw -ot ghc-tarballs/mingw/libcrypt*.tar.bz2 ||
395          test inplace/mingw -ot ghc-tarballs/mingw/mingw-runtime*.tar.gz ||
396          test inplace/mingw -ot ghc-tarballs/mingw/perl*.tar.bz2 ||
397          test inplace/mingw -ot ghc-tarballs/mingw/w32api*.tar.gz
398     then
399         AC_MSG_NOTICE([Making in-tree mingw tree])
400         rm -rf inplace/mingw
401         mkdir inplace
402         mkdir inplace/mingw
403         cd inplace/mingw
404         tar -zxf ../../ghc-tarballs/mingw/binutils*.tar.gz
405         tar -zxf ../../ghc-tarballs/mingw/gcc-core*.tar.gz
406         tar -jxf ../../ghc-tarballs/mingw/libcrypt*.tar.bz2
407         tar -zxf ../../ghc-tarballs/mingw/mingw-runtime*.tar.gz
408         tar -jxf ../../ghc-tarballs/mingw/perl*.tar.bz2
409         tar -zxf ../../ghc-tarballs/mingw/w32api*.tar.gz
410         cd ../..
411         AC_MSG_NOTICE([In-tree mingw tree created])
412     fi
413 fi
414
415 dnl ** Which gcc to use?
416 dnl --------------------------------------------------------------
417 FP_ARG_WITH_PATH_GNU_PROG([CC], [gcc])
418 export CC
419 WhatGccIsCalled="$CC"
420 AC_SUBST(WhatGccIsCalled)
421
422 dnl ** Which ld to use?
423 dnl --------------------------------------------------------------
424 FP_ARG_WITH_PATH_GNU_PROG([LD], [ld])
425 LdCmd="$LD"
426 AC_SUBST([LdCmd])
427
428 dnl ** Which nm to use?
429 dnl --------------------------------------------------------------
430 FP_ARG_WITH_PATH_GNU_PROG([NM], [nm])
431 NmCmd="$NM"
432 AC_SUBST([NmCmd])
433
434 dnl ** Mac OS X: explicit deployment target
435 dnl --------------------------------------------------------------
436 AC_ARG_WITH([macosx-deployment-target],
437 [AC_HELP_STRING([--with-macosx-deployment-target=VERSION],
438         [Build for Mac OS VERSION and higher  (default= version of build host)])],
439 [FP_MACOSX_DEPLOYMENT_TARGET="$withval"
440  if test "x$TargetOS_CPP-$TargetVendor_CPP" != "xdarwin-apple"; then
441    # ignore everywhere, but on Mac OS
442    AC_MSG_WARN([--macosx-deployment-target is only available on Mac OS X])
443    FP_MACOSX_DEPLOYMENT_TARGET=none
444  fi],
445 [FP_MACOSX_DEPLOYMENT_TARGET=none]
446 )
447 FP_CHECK_MACOSX_DEPLOYMENT_TARGET
448 AC_SUBST(MACOSX_DEPLOYMENT_VERSION)
449 AC_SUBST(MACOSX_DEPLOYMENT_SDK)
450
451 dnl --------------------------------------------------------------
452 dnl End of configure script option section
453 dnl --------------------------------------------------------------
454
455
456 dnl --------------------------------------------------------------
457 dnl * General configuration checks
458 dnl --------------------------------------------------------------
459
460 dnl ** Can the unix package be built?
461 dnl --------------------------------------------------------------
462
463 if test x"$TargetPlatform" = x"i386-unknown-mingw32"; then
464    GhcLibsWithUnix=NO
465 else
466    GhcLibsWithUnix=YES
467 fi
468 AC_SUBST([GhcLibsWithUnix])
469
470 dnl ** does #! work?
471 AC_SYS_INTERPRETER()
472
473 dnl ** look for `perl', but only in /bin on Windows
474 case $HostOS_CPP in
475 cygwin32|mingw32)
476       AC_CHECK_PROG(PerlCmd,perl,/bin/perl,,/bin)
477       if test -z "$PerlCmd"; then
478          echo "You must install the version of Perl shipped with GHC"
479          echo "(or a compatible one) in /bin."
480          exit 1
481       fi
482    ;;
483 *)
484    AC_PATH_PROG(PerlCmd,perl)
485    if test -z "$PerlCmd"; then
486       echo "You must install perl before you can continue"
487       echo "Perhaps it is already installed, but not in your PATH?"
488       exit 1
489    else
490    FPTOOLS_CHECK_PERL_VERSION
491    fi
492    ;;
493 esac
494
495 dnl ** does #! path/to/perl work? (sometimes it's too long...)
496 FPTOOLS_SHEBANG_PERL
497
498 dnl ** check for Python
499 AC_PATH_PROG(PythonCmd,python)
500
501 dnl ** look for GCC and find out which version
502 dnl     Figure out which C compiler to use.  Gcc is preferred.
503 dnl     If gcc, make sure it's at least 2.1
504 dnl
505 FP_HAVE_GCC
506 FP_GCC_EXTRA_FLAGS
507
508 dnl ** figure out how to invoke cpp directly (gcc -E is no good)
509 AC_PROG_CPP
510
511 AC_SUBST(CONF_CC_OPTS)
512 AC_SUBST(CONF_LD_OPTS)
513
514 dnl ** figure out how to do context diffs
515 FP_PROG_CONTEXT_DIFF
516
517 dnl Let's make sure install-sh is executable here.  If we got it from
518 dnl a darcs repo, it might not be (see bug #978).
519 chmod +x install-sh
520 dnl ** figure out how to do a BSD-ish install
521 AC_PROG_INSTALL
522
523 dnl If you can run configure, you certainly have /bin/sh
524 AC_DEFINE([HAVE_BIN_SH], [1], [Define to 1 if you have /bin/sh.])
525
526 dnl ** how to invoke `ar' and `ranlib'
527 FP_PROG_AR_NEEDS_RANLIB
528 FP_PROG_AR_SUPPORTS_INPUT
529
530 dnl ** Check to see whether ln -s works
531 AC_PROG_LN_S
532
533
534 dnl ** Find the path to sed
535 AC_PATH_PROG(SedCmd,sed)
536
537
538 dnl ** check for time command
539 AC_PATH_PROG(TimeCmd,time)
540
541 dnl ** check for tar
542 dnl   if GNU tar is named gtar, look for it first.
543 AC_PATH_PROGS(TarCmd,gtar tar,tar)
544
545 dnl ** check for patch
546 dnl if GNU patch is named gpatch, look for it first
547 AC_PATH_PROGS(PatchCmd,gpatch patch, patch)
548
549 AC_PATH_PROG(HSCOLOUR,HsColour)
550 # HsColour is passed to Cabal, so we need a native path
551 if test "x$HostPlatform"  = "xi386-unknown-mingw32" && \
552    test "${OSTYPE}"      != "msys"                  && \
553    test "${HSCOLOUR}"    != ""
554 then
555     # Canonicalise to <drive>:/path/to/gcc
556     HSCOLOUR=`cygpath -m ${HSCOLOUR}`
557 fi
558
559 dnl ** check for DocBook toolchain
560 FP_CHECK_DOCBOOK_DTD
561 FP_DOCBOOK_XSL
562 FP_PROG_DBLATEX
563
564 FP_PROG_HSTAGS
565
566 dnl ** check for ghc-pkg command
567 FP_PROG_GHC_PKG
568
569 dnl ** check for installed happy binary + version
570 dnl    (don't do it if we're booting from .hc files though.)
571 if test "$BootingFromHc" = "NO"; then
572 FPTOOLS_HAPPY
573 fi;
574
575 dnl ** check for installed alex binary + version
576 dnl    (don't do it if we're booting from .hc files though.)
577 if test "$BootingFromHc" = "NO"; then
578 FPTOOLS_ALEX
579 fi;
580
581 dnl --------------------------------------------------
582 dnl ### program checking section ends here ###
583 dnl --------------------------------------------------
584
585 dnl --------------------------------------------------
586 dnl * Platform header file and syscall feature tests
587 dnl ### checking the state of the local header files and syscalls ###
588
589 dnl ** check for full ANSI header (.h) files
590 AC_HEADER_STDC
591
592 dnl ** Enable large file support.  NB. do this before testing the type of
593 dnl    off_t, because it will affect the result of that test.
594 AC_SYS_LARGEFILE
595
596 dnl ** check for specific header (.h) files that we are interested in
597 AC_CHECK_HEADERS([bfd.h ctype.h dirent.h dlfcn.h errno.h fcntl.h grp.h limits.h locale.h nlist.h pthread.h pwd.h signal.h sys/mman.h sys/resource.h sys/time.h sys/timeb.h sys/timers.h sys/times.h sys/utsname.h sys/wait.h termios.h time.h utime.h windows.h winsock.h sched.h])
598
599 dnl ** check if it is safe to include both <time.h> and <sys/time.h>
600 AC_HEADER_TIME
601
602 dnl ** do we have long longs?
603 AC_CHECK_TYPES([long long])
604
605 dnl ** what are the sizes of various types
606 AC_CHECK_SIZEOF(char,               1)
607 AC_CHECK_SIZEOF(double,             8)
608 AC_CHECK_SIZEOF(float,              4)
609 AC_CHECK_SIZEOF(int,                4)
610 AC_CHECK_SIZEOF(long,               4)
611 if test "$ac_cv_type_long_long" = yes; then
612 AC_CHECK_SIZEOF(long long,          8)
613 fi
614 AC_CHECK_SIZEOF(short,              2)
615 AC_CHECK_SIZEOF(unsigned char,      1)
616 AC_CHECK_SIZEOF(unsigned int,       4)
617 AC_CHECK_SIZEOF(unsigned long,      4)
618 if test "$ac_cv_type_long_long" = yes; then
619 AC_CHECK_SIZEOF(unsigned long long, 8)
620 fi
621 AC_CHECK_SIZEOF(unsigned short,     2)
622 AC_CHECK_SIZEOF(void *,             4)
623
624 dnl ** what are alignment constraints on various types
625 FP_CHECK_ALIGNMENT(char)
626 FP_CHECK_ALIGNMENT(double)
627 FP_CHECK_ALIGNMENT(float)
628 FP_CHECK_ALIGNMENT(int)
629 FP_CHECK_ALIGNMENT(long)
630 if test "$ac_cv_type_long_long" = yes; then
631 FP_CHECK_ALIGNMENT(long long)
632 fi
633 FP_CHECK_ALIGNMENT(short)
634 FP_CHECK_ALIGNMENT(unsigned char)
635 FP_CHECK_ALIGNMENT(unsigned int)
636 FP_CHECK_ALIGNMENT(unsigned long)
637 if test "$ac_cv_type_long_long" = yes; then
638 FP_CHECK_ALIGNMENT(unsigned long long)
639 fi
640 FP_CHECK_ALIGNMENT(unsigned short)
641 FP_CHECK_ALIGNMENT(void *)
642
643 FP_CHECK_FUNC([WinExec],
644   [@%:@include <windows.h>], [WinExec("",0)])
645
646 FP_CHECK_FUNC([GetModuleFileName],
647   [@%:@include <windows.h>], [GetModuleFileName((HMODULE)0,(LPTSTR)0,0)])
648
649 dnl ** check return type of signal handlers
650 dnl Foo: assumes we can use prototypes.
651 dnl On BCC, signal handlers have type "int(void)", elsewhere its "void(int)".
652 dnl AC_CACHE_CHECK([type of signal handlers], ac_cv_type_signal_handler,
653 dnl [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
654 dnl #include <signal.h>
655 dnl #ifdef signal
656 dnl #undef signal
657 dnl #endif
658 dnl void (*signal (int, void (*)(int)))(int);
659 dnl ]],
660 dnl [[int i;]])],
661 dnl [ac_cv_type_signal_handler=void_int],
662 dnl [ac_cv_type_signal_handler=int_void])])
663 dnl if test "$ac_cv_type_signal_handler" = void_int; then
664 dnl AC_DEFINE(VOID_INT_SIGNALS)
665 dnl fi
666
667 dnl On BCC, signal handlers have type "int(void)", elsewhere its "void(int)".
668 AC_TYPE_SIGNAL
669 if test "$ac_cv_type_signal" = void; then
670   AC_DEFINE([VOID_INT_SIGNALS], [1], [Define to 1 if signal handlers have type void (*)(int). Otherwise, they're assumed to have type int (*)(void).])
671 fi
672
673 dnl ** check for more functions
674 dnl ** The following have been verified to be used in ghc/, but might be used somewhere else, too.
675 AC_CHECK_FUNCS([getclock getrusage gettimeofday setitimer siginterrupt sysconf times ctime_r sched_setaffinity setlocale])
676
677 AC_TRY_RUN([
678 #include <sys/types.h>
679 #include <sys/time.h>
680 int main(void) {
681   struct itimerval tval;
682   tval.it_value.tv_sec = 1;
683   tval.it_value.tv_usec = 0;
684   tval.it_interval = tval.it_value;
685   return setitimer(ITIMER_VIRTUAL, &tval, (void*)0) != 0;
686 }
687 ],[AC_DEFINE([HAVE_SETITIMER_VIRTUAL], [1], [Define to 1 if setitimer accepts ITIMER_VIRTUAL, 0 else.])])
688
689 dnl ** On OS X 10.4 (at least), time.h doesn't declare ctime_r if
690 dnl ** _POSIX_C_SOURCE is defined
691 AC_CHECK_DECLS([ctime_r], , ,
692 [#define _POSIX_SOURCE 1
693 #define _POSIX_C_SOURCE 199506L
694 #include <time.h>])
695
696 dnl ** check for mingwex library
697 AC_CHECK_LIB(mingwex, closedir, HaveLibMingwEx=YES, HaveLibMingwEx=NO)
698 AC_SUBST(HaveLibMingwEx)
699
700 if test $HaveLibMingwEx = YES ; then
701   AC_DEFINE([HAVE_MINGWEX], [1], [Define to 1 if you have the mingwex library.])
702 fi
703
704 dnl ** check whether this machine has BFD and liberty installed (used for debugging)
705 dnl    the order of these tests matters: bfd needs liberty
706 AC_CHECK_LIB(iberty, xmalloc)
707 AC_CHECK_LIB(bfd,    bfd_init)
708
709 dnl ** check for math library
710 AC_CHECK_FUNC(atan,[fp_libm_not_needed=yes;LIBM=],[fp_libm_not_needed=dunno])
711 if test x"$fp_libm_not_needed" = xdunno; then
712    AC_CHECK_LIB([m], [atan], [LIBS="-lm $LIBS"; LIBM="-lm"],[LIBM=])
713 fi
714 AC_SUBST([LIBM])
715
716 dnl ################################################################
717 dnl Check for libraries
718 dnl ################################################################
719
720 dnl ** check whether we need -ldl to get dlopen()
721
722 AC_CHECK_LIB(dl, dlopen,
723     [HaveLibDL=YES
724      AC_DEFINE([HAVE_LIBDL], [1], [Define to 1 if you need -ldl to get dlopen().])
725      LIBS="$LIBS -ldl"],
726     [HaveLibDL=NO])
727 AC_SUBST(HaveLibDL)
728
729 dnl --------------------------------------------------
730 dnl * Miscellaneous feature tests
731 dnl --------------------------------------------------
732
733 dnl ** can we get alloca?
734 AC_FUNC_ALLOCA
735
736 dnl ** Working vfork?
737 AC_FUNC_FORK
738
739 dnl ** determine whether or not const works
740 AC_C_CONST
741
742 dnl ** are we big endian?
743 AC_C_BIGENDIAN
744 FPTOOLS_FLOAT_WORD_ORDER_BIGENDIAN
745
746 dnl ** check for leading underscores in symbol names
747 FP_LEADING_UNDERSCORE
748
749 dnl ** check for ld, whether it has an -x option, and if it is GNU ld
750 FP_PROG_LD_X
751 FP_PROG_LD_IS_GNU
752
753 dnl ** check for Apple-style dead-stripping support
754 dnl    (.subsections-via-symbols assembler directive)
755
756
757 AC_MSG_CHECKING(for .subsections_via_symbols)
758 AC_COMPILE_IFELSE(
759     [AC_LANG_PROGRAM([], [__asm__ (".subsections_via_symbols");])],
760     [AC_MSG_RESULT(yes)
761      AC_DEFINE([HAVE_SUBSECTIONS_VIA_SYMBOLS],[1],
762                [Define to 1 if Apple-style dead-stripping is supported.])
763     ],
764     [AC_MSG_RESULT(no)])
765
766 dnl *** check for GNU non-executable stack note support (ELF only)
767 dnl     (.section .note.GNU-stack,"",@progbits)
768
769 AC_MSG_CHECKING(for GNU non-executable stack support)
770 AC_COMPILE_IFELSE(
771     [AC_LANG_PROGRAM([__asm__ (".section .note.GNU-stack,\"\",@progbits");], [0])],
772     [AC_MSG_RESULT(yes)
773      AC_DEFINE([HAVE_GNU_NONEXEC_STACK],[1],
774                [Define to 1 if GNU non-executable stack notes are supported.])
775     ],
776     [AC_MSG_RESULT(no)])
777
778 dnl ** check for librt
779 AC_CHECK_LIB(rt, clock_gettime)
780 AC_CHECK_FUNCS(clock_gettime timer_create timer_settime)
781 FP_CHECK_TIMER_CREATE
782
783 dnl ** check for Apple's "interesting" long double compatibility scheme
784 AC_MSG_CHECKING(for printf\$LDBLStub)
785 AC_TRY_LINK_FUNC(printf\$LDBLStub,
786     [
787         AC_MSG_RESULT(yes)
788         AC_DEFINE([HAVE_PRINTF_LDBLSTUB],[1],
789             [Define to 1 if we have printf$LDBLStub (Apple Mac OS >= 10.4, PPC).])
790     ],
791     [
792         AC_MSG_RESULT(no)
793         AC_DEFINE([HAVE_PRINTF_LDBLSTUB],[0],
794             [Define to 1 if we have printf$LDBLStub (Apple Mac OS >= 10.4, PPC).])
795     ])
796
797 # test for GTK+
798 AC_PATH_PROGS([GTK_CONFIG], [pkg-config])
799 if test -n "$GTK_CONFIG"; then
800   if $GTK_CONFIG gtk+-2.0 --atleast-version=2.0; then
801     GTK_CONFIG="$GTK_CONFIG gtk+-2.0"
802   else
803     AC_MSG_WARN([GTK+ not usable, need at least version 2.0])
804     GTK_CONFIG=
805   fi
806 fi
807 AC_SUBST([GTK_CONFIG])
808
809 #Checking for PAPI
810 AC_CHECK_LIB(papi, PAPI_library_init, HavePapiLib=YES, HavePapiLib=NO)
811 AC_CHECK_HEADER([papi.h], [HavePapiHeader=YES], [HavePapiHeader=NO])
812 AC_SUBST(HavePapiLib)
813 AC_SUBST(HavePapiHeader)
814
815 AC_CHECK_FUNCS(__mingw_vfprintf)
816
817 if test "$HavePapiLib" = "YES" -a "$HavePapiHeader" = "YES"; then
818    HavePapi=YES
819 else
820    HavePapi=NO
821 fi
822 AC_SUBST(HavePapi)
823
824 if test "$HAVE_DOCBOOK_XSL" = "NO" ||
825    test "$XsltprocCmd" = ""
826 then
827     BUILD_DOCBOOK_HTML=NO
828 else
829     BUILD_DOCBOOK_HTML=YES
830 fi
831 AC_SUBST(BUILD_DOCBOOK_HTML)
832
833 if test "$DblatexCmd" = ""
834 then
835     BUILD_DOCBOOK_PS=NO
836     BUILD_DOCBOOK_PDF=NO
837 else
838     BUILD_DOCBOOK_PS=YES
839     BUILD_DOCBOOK_PDF=YES
840 fi
841 AC_SUBST(BUILD_DOCBOOK_PS)
842 AC_SUBST(BUILD_DOCBOOK_PDF)
843
844 if grep '       ' compiler/ghc.cabal.in 2>&1 >/dev/null; then
845    AC_MSG_ERROR([compiler/ghc.cabal.in contains tab characters; please remove them])
846 fi
847
848 AC_CONFIG_FILES([mk/config.mk mk/install.mk mk/project.mk compiler/ghc.cabal ghc/ghc-bin.cabal ghc.spec extra-gcc-opts docs/users_guide/ug-book.xml distrib/ghc.iss distrib/configure-bin.ac])
849 AC_CONFIG_COMMANDS([mk/stamp-h],[echo timestamp > mk/stamp-h])
850 AC_OUTPUT
851
852 # We get caught by
853 #     http://savannah.gnu.org/bugs/index.php?1516
854 #     $(eval ...) inside conditionals causes errors
855 # with make 3.80, so warn the user if it looks like they're about to
856 # try to use it.
857 # We would use "grep -q" here, but Solaris's grep doesn't support it.
858 checkMake380() {
859     if $1 --version 2>&1 | head -1 | grep 'GNU Make 3\.80' > /dev/null
860     then
861         echo
862         echo "WARNING: It looks like \"$1\" is GNU make 3.80."
863         echo "This version cannot be used to build GHC."
864         echo "Please use GNU make >= 3.81."
865     fi
866 }
867
868 checkMake380 make
869 checkMake380 gmake
870
871 echo ["
872 ----------------------------------------------------------------------
873 Configure completed successfully.
874
875    Building GHC version  : $ProjectVersion
876
877    Build platform        : $BuildPlatform
878    Host platform         : $HostPlatform
879    Target platform       : $TargetPlatform
880 "]
881
882 if test "$BootingFromHc" = "YES"; then
883 echo ["\
884    Bootstrapping from HC files.
885 "]
886 else
887 echo ["\
888    Bootstrapping using   : $WithGhc
889       which is version   : $GhcVersion
890 "]
891 fi
892
893 echo ["\
894    Using GCC             : $WhatGccIsCalled
895       which is version   : $GccVersion
896
897    ld       : $LdCmd
898    Happy    : $HappyCmd ($HappyVersion)
899    Alex     : $AlexCmd ($AlexVersion)
900    Python   : $PythonCmd
901    Perl     : $PerlCmd
902    dblatex  : $DblatexCmd
903    xsltproc : $XsltprocCmd"]
904
905 if test "$HSCOLOUR" = ""; then
906 echo ["
907    HsColour was not found; documentation will not contain source links
908 "]
909 else
910 echo ["\
911    HsColour : $HSCOLOUR
912 "]
913 fi
914
915 echo ["\
916    Building DocBook HTML documentation : $BUILD_DOCBOOK_HTML
917    Building DocBook PS documentation   : $BUILD_DOCBOOK_PS
918    Building DocBook PDF documentation  : $BUILD_DOCBOOK_PDF"]
919
920 echo ["----------------------------------------------------------------------
921 "]
922
923 echo "\
924 For a standard build of GHC (fully optimised with profiling), type (g)make.
925
926 To make changes to the default build configuration, copy the file
927 mk/build.mk.sample to mk/build.mk, and edit the settings in there.
928
929 For more information on how to configure your GHC build, see
930    http://hackage.haskell.org/trac/ghc/wiki/Building
931 "