Wrap gcc on Windows, to provide the -B flags
[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         mv bin/gcc.exe bin/realgcc.exe
411         cd ../..
412         inplace/mingw/bin/realgcc.exe driver/gcc/gcc.c driver/utils/getLocation.c -Idriver/utils -o inplace/mingw/bin/gcc.exe
413         AC_MSG_NOTICE([In-tree mingw tree created])
414     fi
415 fi
416
417 dnl ** Which gcc to use?
418 dnl --------------------------------------------------------------
419 FP_ARG_WITH_PATH_GNU_PROG([CC], [gcc])
420 export CC
421 WhatGccIsCalled="$CC"
422 AC_SUBST(WhatGccIsCalled)
423
424 dnl ** Which ld to use?
425 dnl --------------------------------------------------------------
426 FP_ARG_WITH_PATH_GNU_PROG([LD], [ld])
427 LdCmd="$LD"
428 AC_SUBST([LdCmd])
429
430 dnl ** Which nm to use?
431 dnl --------------------------------------------------------------
432 FP_ARG_WITH_PATH_GNU_PROG([NM], [nm])
433 NmCmd="$NM"
434 AC_SUBST([NmCmd])
435
436 dnl ** Mac OS X: explicit deployment target
437 dnl --------------------------------------------------------------
438 AC_ARG_WITH([macosx-deployment-target],
439 [AC_HELP_STRING([--with-macosx-deployment-target=VERSION],
440         [Build for Mac OS VERSION and higher  (default= version of build host)])],
441 [FP_MACOSX_DEPLOYMENT_TARGET="$withval"
442  if test "x$TargetOS_CPP-$TargetVendor_CPP" != "xdarwin-apple"; then
443    # ignore everywhere, but on Mac OS
444    AC_MSG_WARN([--macosx-deployment-target is only available on Mac OS X])
445    FP_MACOSX_DEPLOYMENT_TARGET=none
446  fi],
447 [FP_MACOSX_DEPLOYMENT_TARGET=none]
448 )
449 FP_CHECK_MACOSX_DEPLOYMENT_TARGET
450 AC_SUBST(MACOSX_DEPLOYMENT_VERSION)
451 AC_SUBST(MACOSX_DEPLOYMENT_SDK)
452
453 dnl --------------------------------------------------------------
454 dnl End of configure script option section
455 dnl --------------------------------------------------------------
456
457
458 dnl --------------------------------------------------------------
459 dnl * General configuration checks
460 dnl --------------------------------------------------------------
461
462 dnl ** Can the unix package be built?
463 dnl --------------------------------------------------------------
464
465 if test x"$TargetPlatform" = x"i386-unknown-mingw32"; then
466    GhcLibsWithUnix=NO
467 else
468    GhcLibsWithUnix=YES
469 fi
470 AC_SUBST([GhcLibsWithUnix])
471
472 dnl ** does #! work?
473 AC_SYS_INTERPRETER()
474
475 dnl ** look for `perl', but only in /bin on Windows
476 case $HostOS_CPP in
477 cygwin32|mingw32)
478       AC_CHECK_PROG(PerlCmd,perl,/bin/perl,,/bin)
479       if test -z "$PerlCmd"; then
480          echo "You must install the version of Perl shipped with GHC"
481          echo "(or a compatible one) in /bin."
482          exit 1
483       fi
484    ;;
485 *)
486    AC_PATH_PROG(PerlCmd,perl)
487    if test -z "$PerlCmd"; then
488       echo "You must install perl before you can continue"
489       echo "Perhaps it is already installed, but not in your PATH?"
490       exit 1
491    else
492    FPTOOLS_CHECK_PERL_VERSION
493    fi
494    ;;
495 esac
496
497 dnl ** does #! path/to/perl work? (sometimes it's too long...)
498 FPTOOLS_SHEBANG_PERL
499
500 dnl ** check for Python
501 AC_PATH_PROG(PythonCmd,python)
502
503 dnl ** look for GCC and find out which version
504 dnl     Figure out which C compiler to use.  Gcc is preferred.
505 dnl     If gcc, make sure it's at least 2.1
506 dnl
507 FP_HAVE_GCC
508 FP_GCC_EXTRA_FLAGS
509
510 dnl ** figure out how to invoke cpp directly (gcc -E is no good)
511 AC_PROG_CPP
512
513 AC_SUBST(CONF_CC_OPTS)
514 AC_SUBST(CONF_LD_OPTS)
515
516 dnl ** figure out how to do context diffs
517 FP_PROG_CONTEXT_DIFF
518
519 dnl Let's make sure install-sh is executable here.  If we got it from
520 dnl a darcs repo, it might not be (see bug #978).
521 chmod +x install-sh
522 dnl ** figure out how to do a BSD-ish install
523 AC_PROG_INSTALL
524
525 dnl If you can run configure, you certainly have /bin/sh
526 AC_DEFINE([HAVE_BIN_SH], [1], [Define to 1 if you have /bin/sh.])
527
528 dnl ** how to invoke `ar' and `ranlib'
529 FP_PROG_AR_NEEDS_RANLIB
530 FP_PROG_AR_SUPPORTS_INPUT
531
532 dnl ** Check to see whether ln -s works
533 AC_PROG_LN_S
534
535
536 dnl ** Find the path to sed
537 AC_PATH_PROG(SedCmd,sed)
538
539
540 dnl ** check for time command
541 AC_PATH_PROG(TimeCmd,time)
542
543 dnl ** check for tar
544 dnl   if GNU tar is named gtar, look for it first.
545 AC_PATH_PROGS(TarCmd,gtar tar,tar)
546
547 dnl ** check for patch
548 dnl if GNU patch is named gpatch, look for it first
549 AC_PATH_PROGS(PatchCmd,gpatch patch, patch)
550
551 AC_PATH_PROG(HSCOLOUR,HsColour)
552 # HsColour is passed to Cabal, so we need a native path
553 if test "x$HostPlatform"  = "xi386-unknown-mingw32" && \
554    test "${OSTYPE}"      != "msys"                  && \
555    test "${HSCOLOUR}"    != ""
556 then
557     # Canonicalise to <drive>:/path/to/gcc
558     HSCOLOUR=`cygpath -m ${HSCOLOUR}`
559 fi
560
561 dnl ** check for DocBook toolchain
562 FP_CHECK_DOCBOOK_DTD
563 FP_DOCBOOK_XSL
564 FP_PROG_DBLATEX
565
566 FP_PROG_HSTAGS
567
568 dnl ** check for ghc-pkg command
569 FP_PROG_GHC_PKG
570
571 dnl ** check for installed happy binary + version
572 dnl    (don't do it if we're booting from .hc files though.)
573 if test "$BootingFromHc" = "NO"; then
574 FPTOOLS_HAPPY
575 fi;
576
577 dnl ** check for installed alex binary + version
578 dnl    (don't do it if we're booting from .hc files though.)
579 if test "$BootingFromHc" = "NO"; then
580 FPTOOLS_ALEX
581 fi;
582
583 dnl --------------------------------------------------
584 dnl ### program checking section ends here ###
585 dnl --------------------------------------------------
586
587 dnl --------------------------------------------------
588 dnl * Platform header file and syscall feature tests
589 dnl ### checking the state of the local header files and syscalls ###
590
591 dnl ** check for full ANSI header (.h) files
592 AC_HEADER_STDC
593
594 dnl ** Enable large file support.  NB. do this before testing the type of
595 dnl    off_t, because it will affect the result of that test.
596 AC_SYS_LARGEFILE
597
598 dnl ** check for specific header (.h) files that we are interested in
599 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])
600
601 dnl ** check if it is safe to include both <time.h> and <sys/time.h>
602 AC_HEADER_TIME
603
604 dnl ** do we have long longs?
605 AC_CHECK_TYPES([long long])
606
607 dnl ** what are the sizes of various types
608 AC_CHECK_SIZEOF(char,               1)
609 AC_CHECK_SIZEOF(double,             8)
610 AC_CHECK_SIZEOF(float,              4)
611 AC_CHECK_SIZEOF(int,                4)
612 AC_CHECK_SIZEOF(long,               4)
613 if test "$ac_cv_type_long_long" = yes; then
614 AC_CHECK_SIZEOF(long long,          8)
615 fi
616 AC_CHECK_SIZEOF(short,              2)
617 AC_CHECK_SIZEOF(unsigned char,      1)
618 AC_CHECK_SIZEOF(unsigned int,       4)
619 AC_CHECK_SIZEOF(unsigned long,      4)
620 if test "$ac_cv_type_long_long" = yes; then
621 AC_CHECK_SIZEOF(unsigned long long, 8)
622 fi
623 AC_CHECK_SIZEOF(unsigned short,     2)
624 AC_CHECK_SIZEOF(void *,             4)
625
626 dnl ** what are alignment constraints on various types
627 FP_CHECK_ALIGNMENT(char)
628 FP_CHECK_ALIGNMENT(double)
629 FP_CHECK_ALIGNMENT(float)
630 FP_CHECK_ALIGNMENT(int)
631 FP_CHECK_ALIGNMENT(long)
632 if test "$ac_cv_type_long_long" = yes; then
633 FP_CHECK_ALIGNMENT(long long)
634 fi
635 FP_CHECK_ALIGNMENT(short)
636 FP_CHECK_ALIGNMENT(unsigned char)
637 FP_CHECK_ALIGNMENT(unsigned int)
638 FP_CHECK_ALIGNMENT(unsigned long)
639 if test "$ac_cv_type_long_long" = yes; then
640 FP_CHECK_ALIGNMENT(unsigned long long)
641 fi
642 FP_CHECK_ALIGNMENT(unsigned short)
643 FP_CHECK_ALIGNMENT(void *)
644
645 FP_CHECK_FUNC([WinExec],
646   [@%:@include <windows.h>], [WinExec("",0)])
647
648 FP_CHECK_FUNC([GetModuleFileName],
649   [@%:@include <windows.h>], [GetModuleFileName((HMODULE)0,(LPTSTR)0,0)])
650
651 dnl ** check return type of signal handlers
652 dnl Foo: assumes we can use prototypes.
653 dnl On BCC, signal handlers have type "int(void)", elsewhere its "void(int)".
654 dnl AC_CACHE_CHECK([type of signal handlers], ac_cv_type_signal_handler,
655 dnl [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
656 dnl #include <signal.h>
657 dnl #ifdef signal
658 dnl #undef signal
659 dnl #endif
660 dnl void (*signal (int, void (*)(int)))(int);
661 dnl ]],
662 dnl [[int i;]])],
663 dnl [ac_cv_type_signal_handler=void_int],
664 dnl [ac_cv_type_signal_handler=int_void])])
665 dnl if test "$ac_cv_type_signal_handler" = void_int; then
666 dnl AC_DEFINE(VOID_INT_SIGNALS)
667 dnl fi
668
669 dnl On BCC, signal handlers have type "int(void)", elsewhere its "void(int)".
670 AC_TYPE_SIGNAL
671 if test "$ac_cv_type_signal" = void; then
672   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).])
673 fi
674
675 dnl ** check for more functions
676 dnl ** The following have been verified to be used in ghc/, but might be used somewhere else, too.
677 AC_CHECK_FUNCS([getclock getrusage gettimeofday setitimer siginterrupt sysconf times ctime_r sched_setaffinity setlocale])
678
679 AC_TRY_RUN([
680 #include <sys/types.h>
681 #include <sys/time.h>
682 int main(void) {
683   struct itimerval tval;
684   tval.it_value.tv_sec = 1;
685   tval.it_value.tv_usec = 0;
686   tval.it_interval = tval.it_value;
687   return setitimer(ITIMER_VIRTUAL, &tval, (void*)0) != 0;
688 }
689 ],[AC_DEFINE([HAVE_SETITIMER_VIRTUAL], [1], [Define to 1 if setitimer accepts ITIMER_VIRTUAL, 0 else.])])
690
691 dnl ** On OS X 10.4 (at least), time.h doesn't declare ctime_r if
692 dnl ** _POSIX_C_SOURCE is defined
693 AC_CHECK_DECLS([ctime_r], , ,
694 [#define _POSIX_SOURCE 1
695 #define _POSIX_C_SOURCE 199506L
696 #include <time.h>])
697
698 dnl ** check for mingwex library
699 AC_CHECK_LIB(mingwex, closedir, HaveLibMingwEx=YES, HaveLibMingwEx=NO)
700 AC_SUBST(HaveLibMingwEx)
701
702 if test $HaveLibMingwEx = YES ; then
703   AC_DEFINE([HAVE_MINGWEX], [1], [Define to 1 if you have the mingwex library.])
704 fi
705
706 dnl ** check whether this machine has BFD and liberty installed (used for debugging)
707 dnl    the order of these tests matters: bfd needs liberty
708 AC_CHECK_LIB(iberty, xmalloc)
709 AC_CHECK_LIB(bfd,    bfd_init)
710
711 dnl ** check for math library
712 AC_CHECK_FUNC(atan,[fp_libm_not_needed=yes;LIBM=],[fp_libm_not_needed=dunno])
713 if test x"$fp_libm_not_needed" = xdunno; then
714    AC_CHECK_LIB([m], [atan], [LIBS="-lm $LIBS"; LIBM="-lm"],[LIBM=])
715 fi
716 AC_SUBST([LIBM])
717
718 dnl ################################################################
719 dnl Check for libraries
720 dnl ################################################################
721
722 dnl ** check whether we need -ldl to get dlopen()
723
724 AC_CHECK_LIB(dl, dlopen,
725     [HaveLibDL=YES
726      AC_DEFINE([HAVE_LIBDL], [1], [Define to 1 if you need -ldl to get dlopen().])
727      LIBS="$LIBS -ldl"],
728     [HaveLibDL=NO])
729 AC_SUBST(HaveLibDL)
730
731 dnl --------------------------------------------------
732 dnl * Miscellaneous feature tests
733 dnl --------------------------------------------------
734
735 dnl ** can we get alloca?
736 AC_FUNC_ALLOCA
737
738 dnl ** Working vfork?
739 AC_FUNC_FORK
740
741 dnl ** determine whether or not const works
742 AC_C_CONST
743
744 dnl ** are we big endian?
745 AC_C_BIGENDIAN
746 FPTOOLS_FLOAT_WORD_ORDER_BIGENDIAN
747
748 dnl ** check for leading underscores in symbol names
749 FP_LEADING_UNDERSCORE
750
751 dnl ** check for ld, whether it has an -x option, and if it is GNU ld
752 FP_PROG_LD_X
753 FP_PROG_LD_IS_GNU
754
755 dnl ** check for Apple-style dead-stripping support
756 dnl    (.subsections-via-symbols assembler directive)
757
758
759 AC_MSG_CHECKING(for .subsections_via_symbols)
760 AC_COMPILE_IFELSE(
761     [AC_LANG_PROGRAM([], [__asm__ (".subsections_via_symbols");])],
762     [AC_MSG_RESULT(yes)
763      AC_DEFINE([HAVE_SUBSECTIONS_VIA_SYMBOLS],[1],
764                [Define to 1 if Apple-style dead-stripping is supported.])
765     ],
766     [AC_MSG_RESULT(no)])
767
768 dnl *** check for GNU non-executable stack note support (ELF only)
769 dnl     (.section .note.GNU-stack,"",@progbits)
770
771 AC_MSG_CHECKING(for GNU non-executable stack support)
772 AC_COMPILE_IFELSE(
773     [AC_LANG_PROGRAM([__asm__ (".section .note.GNU-stack,\"\",@progbits");], [0])],
774     [AC_MSG_RESULT(yes)
775      AC_DEFINE([HAVE_GNU_NONEXEC_STACK],[1],
776                [Define to 1 if GNU non-executable stack notes are supported.])
777     ],
778     [AC_MSG_RESULT(no)])
779
780 dnl ** check for librt
781 AC_CHECK_LIB(rt, clock_gettime)
782 AC_CHECK_FUNCS(clock_gettime timer_create timer_settime)
783 FP_CHECK_TIMER_CREATE
784
785 dnl ** check for Apple's "interesting" long double compatibility scheme
786 AC_MSG_CHECKING(for printf\$LDBLStub)
787 AC_TRY_LINK_FUNC(printf\$LDBLStub,
788     [
789         AC_MSG_RESULT(yes)
790         AC_DEFINE([HAVE_PRINTF_LDBLSTUB],[1],
791             [Define to 1 if we have printf$LDBLStub (Apple Mac OS >= 10.4, PPC).])
792     ],
793     [
794         AC_MSG_RESULT(no)
795         AC_DEFINE([HAVE_PRINTF_LDBLSTUB],[0],
796             [Define to 1 if we have printf$LDBLStub (Apple Mac OS >= 10.4, PPC).])
797     ])
798
799 # test for GTK+
800 AC_PATH_PROGS([GTK_CONFIG], [pkg-config])
801 if test -n "$GTK_CONFIG"; then
802   if $GTK_CONFIG gtk+-2.0 --atleast-version=2.0; then
803     GTK_CONFIG="$GTK_CONFIG gtk+-2.0"
804   else
805     AC_MSG_WARN([GTK+ not usable, need at least version 2.0])
806     GTK_CONFIG=
807   fi
808 fi
809 AC_SUBST([GTK_CONFIG])
810
811 #Checking for PAPI
812 AC_CHECK_LIB(papi, PAPI_library_init, HavePapiLib=YES, HavePapiLib=NO)
813 AC_CHECK_HEADER([papi.h], [HavePapiHeader=YES], [HavePapiHeader=NO])
814 AC_SUBST(HavePapiLib)
815 AC_SUBST(HavePapiHeader)
816
817 AC_CHECK_FUNCS(__mingw_vfprintf)
818
819 if test "$HavePapiLib" = "YES" -a "$HavePapiHeader" = "YES"; then
820    HavePapi=YES
821 else
822    HavePapi=NO
823 fi
824 AC_SUBST(HavePapi)
825
826 if test "$HAVE_DOCBOOK_XSL" = "NO" ||
827    test "$XsltprocCmd" = ""
828 then
829     BUILD_DOCBOOK_HTML=NO
830 else
831     BUILD_DOCBOOK_HTML=YES
832 fi
833 AC_SUBST(BUILD_DOCBOOK_HTML)
834
835 if test "$DblatexCmd" = ""
836 then
837     BUILD_DOCBOOK_PS=NO
838     BUILD_DOCBOOK_PDF=NO
839 else
840     BUILD_DOCBOOK_PS=YES
841     BUILD_DOCBOOK_PDF=YES
842 fi
843 AC_SUBST(BUILD_DOCBOOK_PS)
844 AC_SUBST(BUILD_DOCBOOK_PDF)
845
846 if grep '       ' compiler/ghc.cabal.in 2>&1 >/dev/null; then
847    AC_MSG_ERROR([compiler/ghc.cabal.in contains tab characters; please remove them])
848 fi
849
850 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])
851 AC_CONFIG_COMMANDS([mk/stamp-h],[echo timestamp > mk/stamp-h])
852 AC_OUTPUT
853
854 # We get caught by
855 #     http://savannah.gnu.org/bugs/index.php?1516
856 #     $(eval ...) inside conditionals causes errors
857 # with make 3.80, so warn the user if it looks like they're about to
858 # try to use it.
859 # We would use "grep -q" here, but Solaris's grep doesn't support it.
860 checkMake380() {
861     if $1 --version 2>&1 | head -1 | grep 'GNU Make 3\.80' > /dev/null
862     then
863         echo
864         echo "WARNING: It looks like \"$1\" is GNU make 3.80."
865         echo "This version cannot be used to build GHC."
866         echo "Please use GNU make >= 3.81."
867     fi
868 }
869
870 checkMake380 make
871 checkMake380 gmake
872
873 echo ["
874 ----------------------------------------------------------------------
875 Configure completed successfully.
876
877    Building GHC version  : $ProjectVersion
878
879    Build platform        : $BuildPlatform
880    Host platform         : $HostPlatform
881    Target platform       : $TargetPlatform
882 "]
883
884 if test "$BootingFromHc" = "YES"; then
885 echo ["\
886    Bootstrapping from HC files.
887 "]
888 else
889 echo ["\
890    Bootstrapping using   : $WithGhc
891       which is version   : $GhcVersion
892 "]
893 fi
894
895 echo ["\
896    Using GCC             : $WhatGccIsCalled
897       which is version   : $GccVersion
898
899    ld       : $LdCmd
900    Happy    : $HappyCmd ($HappyVersion)
901    Alex     : $AlexCmd ($AlexVersion)
902    Python   : $PythonCmd
903    Perl     : $PerlCmd
904    dblatex  : $DblatexCmd
905    xsltproc : $XsltprocCmd"]
906
907 if test "$HSCOLOUR" = ""; then
908 echo ["
909    HsColour was not found; documentation will not contain source links
910 "]
911 else
912 echo ["\
913    HsColour : $HSCOLOUR
914 "]
915 fi
916
917 echo ["\
918    Building DocBook HTML documentation : $BUILD_DOCBOOK_HTML
919    Building DocBook PS documentation   : $BUILD_DOCBOOK_PS
920    Building DocBook PDF documentation  : $BUILD_DOCBOOK_PDF"]
921
922 echo ["----------------------------------------------------------------------
923 "]
924
925 echo "\
926 For a standard build of GHC (fully optimised with profiling), type (g)make.
927
928 To make changes to the default build configuration, copy the file
929 mk/build.mk.sample to mk/build.mk, and edit the settings in there.
930
931 For more information on how to configure your GHC build, see
932    http://hackage.haskell.org/trac/ghc/wiki/Building
933 "