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