configure.ac 48.6 KB
Newer Older
1
dnl == autoconf source for the Glasgow FP tools ==
2
dnl (run "grep '^dnl \*' configure.ac | sed -e 's/dnl / /g; s/\*\*/   +/g;'"
sof's avatar
sof committed
3
dnl  (or some such) to see the outline of this file)
4 5
dnl
#
6
# (c) The University of Glasgow 1994-2012
7
#
8
# Configure script template for GHC
9
#
10
# Process with 'autoreconf' to get a working configure script.
11
#
sof's avatar
sof committed
12 13 14 15
# For the generated configure script, do "./configure --help" to
# see what flags are available. (Better yet, read the documentation!)
#

Ben Gamari's avatar
Ben Gamari committed
16
AC_INIT([The Glorious Glasgow Haskell Compilation System], [8.11.0], [glasgow-haskell-bugs@haskell.org], [ghc-AC_PACKAGE_VERSION])
17

18
# Set this to YES for a released version, otherwise NO
19
: ${RELEASE=NO}
20

21
# The primary version (e.g. 7.5, 7.4.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. 7.4.20111220).  The date is
24
# constructed by finding the date of the most recent patch in the
25
# git repository.  If this is a source distribution (not a git
26 27 28
# checkout), then we ship a file 'VERSION' containing the full version
# when the source distribution was created.

29
if test ! -f mk/config.h.in; then
Ben Gamari's avatar
Ben Gamari committed
30
   echo "mk/config.h.in doesn't exist: perhaps you haven't run 'python3 boot'?"
31 32 33
   exit 1
fi

34 35 36 37 38
dnl this makes sure `./configure --target=<cross-compile-target>`
dnl works as expected, since we're slightly modifying how Autoconf
dnl interprets build/host/target and how this interacts with $CC tests
test -n "$target_alias" && ac_tool_prefix=$target_alias-

39
dnl ----------------------------------------------------------
40
dnl ** Find unixy sort and find commands,
41 42 43 44
dnl ** which are needed by FP_SETUP_PROJECT_VERSION

dnl ** Find find command (for Win32's benefit)
FP_PROG_FIND
45
FP_PROG_SORT
46 47

dnl ----------------------------------------------------------
48 49 50 51
FP_SETUP_PROJECT_VERSION

# Hmmm, we fix the RPM release number to 1 here... Is this convenient?
AC_SUBST([release], [1])
52

53
# First off, a distrib sanity check..
54
AC_CONFIG_SRCDIR([mk/config.mk.in])
55

56 57 58 59 60 61 62 63
dnl * We require autoconf version 2.69 due to
dnl   https://bugs.ruby-lang.org/issues/8179. Also see #14910.
dnl * We need 2.50 due to the use of AC_SYS_LARGEFILE and AC_MSG_NOTICE.
dnl * We need 2.52 due to the use of AS_TR_CPP and AS_TR_SH.
dnl * Using autoconf 2.59 started to give nonsense like this
dnl     #define SIZEOF_CHAR 0
dnl   recently.
AC_PREREQ([2.69])
64

65 66 67
# -------------------------------------------------------------------------
# Prepare to generate the following header files
#
68 69
#
AC_CONFIG_HEADER(mk/config.h)
70

sof's avatar
sof committed
71
# No, semi-sadly, we don't do `--srcdir'...
72
if test x"$srcdir" != 'x.' ; then
73
    echo "This configuration does not support the \`--srcdir' option.."
74 75 76
    exit 1
fi

sof's avatar
sof committed
77 78 79 80 81 82 83 84 85 86
dnl --------------------------------------------------------------
dnl * Project specific configuration options
dnl --------------------------------------------------------------
dnl What follows is a bunch of options that can either be configured
dnl through command line options to the configure script or by
dnl supplying defns in the build tree's mk/build.mk. Having the option to
dnl use either is considered a Feature.

dnl ** What command to use to compile compiler sources ?
dnl --------------------------------------------------------------
87

88 89
AC_ARG_VAR(GHC,[Use as the path to GHC [default=autodetect]])
AC_PATH_PROG([GHC], [ghc])
90
AC_ARG_WITH([ghc],
91 92 93
        AS_HELP_STRING([--with-ghc=ARG], [Use ARG as the path to ghc (obsolete, use GHC=ARG instead) [default=autodetect]]),
        AC_MSG_ERROR([--with-ghc=$withval is obsolete (use './configure GHC=$withval' or 'GHC=$withval ./configure' instead)]))
AC_SUBST(WithGhc,$GHC)
94

Ian Lynagh's avatar
Ian Lynagh committed
95 96 97 98 99 100 101
AC_ARG_ENABLE(bootstrap-with-devel-snapshot,
[AC_HELP_STRING([--enable-bootstrap-with-devel-snapshot],
                [Allow bootstrapping using a development snapshot of GHC.  This is not guaranteed to work.])],
        EnableBootstrapWithDevelSnaphost=YES,
        EnableBootstrapWithDevelSnaphost=NO
)

102 103 104 105 106 107
AC_ARG_ENABLE(tarballs-autodownload,
[AC_HELP_STRING([--enable-tarballs-autodownload],
                [Automatically download Windows distribution binaries if needed.])],
        TarballsAutodownload=YES,
        TarballsAutodownload=NO
)
108

109 110 111 112 113 114 115 116 117 118 119
AC_ARG_ENABLE(distro-toolchain,
[AC_HELP_STRING([--enable-distro-toolchain],
                [Do not use bundled Windows toolchain binaries.])],
        EnableDistroToolchain=YES,
        EnableDistroToolchain=NO
)

if test "$EnableDistroToolchain" = "YES"; then
  TarballsAutodownload=NO
fi

120 121
dnl CC_STAGE0, LD_STAGE0, AR_STAGE0 are like the "previous" variable
dnl CC, LD, AR (inherited by CC_STAGE[123], etc.)
122 123
dnl but instead used by stage0 for bootstrapping stage1
AC_ARG_VAR(CC_STAGE0, [C compiler command (bootstrap)])
124 125
AC_ARG_VAR(LD_STAGE0, [Linker command (bootstrap)])
AC_ARG_VAR(AR_STAGE0, [Archive command (bootstrap)])
126

127 128
if test "$WithGhc" != ""; then
  FPTOOLS_GHC_VERSION([GhcVersion], [GhcMajVersion], [GhcMinVersion], [GhcPatchLevel])dnl
Ian Lynagh's avatar
Ian Lynagh committed
129

130
  if test "$GhcMajVersion" = "unknown" || test "$GhcMinVersion" = "unknown"; then
131
     AC_MSG_ERROR([Cannot determine the version of $WithGhc.  Is it really GHC?])
Ian Lynagh's avatar
Ian Lynagh committed
132 133
  fi

134 135 136 137
  AC_SUBST(GhcVersion)dnl
  AC_SUBST(GhcMajVersion)dnl
  AC_SUBST(GhcMinVersion)dnl
  AC_SUBST(GhcPatchLevel)dnl
138 139
  GhcMinVersion2=`echo "$GhcMinVersion" | sed 's/^\\(.\\)$/0\\1/'`
  GhcCanonVersion="$GhcMajVersion$GhcMinVersion2"
140

141
  dnl infer {CC,LD,AR}_STAGE0 from `ghc --info` unless explicitly set by user
142 143 144 145
  if test -z "$CC_STAGE0"; then
    BOOTSTRAPPING_GHC_INFO_FIELD([CC_STAGE0],[C compiler command])
  fi

146 147 148 149 150 151
  if test -z "$LD_STAGE0"; then
    BOOTSTRAPPING_GHC_INFO_FIELD([LD_STAGE0],[ld command])
  fi
  if test -z "$AR_STAGE0"; then
    BOOTSTRAPPING_GHC_INFO_FIELD([AR_STAGE0],[ar command])
  fi
152 153
  BOOTSTRAPPING_GHC_INFO_FIELD([AR_OPTS_STAGE0],[ar flags])
  BOOTSTRAPPING_GHC_INFO_FIELD([ArSupportsAtFile_STAGE0],[ar supports at file])
154 155
fi

156
dnl ** Must have GHC to build GHC
ian@well-typed.com's avatar
ian@well-typed.com committed
157 158 159 160
if test "$WithGhc" = ""
then
    AC_MSG_ERROR([GHC is required.])
fi
161 162
FP_COMPARE_VERSIONS([$GhcVersion],[-lt],[8.8],
    [AC_MSG_ERROR([GHC version 8.8 or later is required to compile GHC.])])
Simon Marlow's avatar
Simon Marlow committed
163

ian@well-typed.com's avatar
ian@well-typed.com committed
164 165 166 167
if test `expr $GhcMinVersion % 2` = "1"
then
    if test "$EnableBootstrapWithDevelSnaphost" = "NO"
    then
Simon Marlow's avatar
Simon Marlow committed
168 169 170 171
        AC_MSG_ERROR([
     $WithGhc is a development snapshot of GHC, version $GhcVersion.
     Bootstrapping using this version of GHC is not supported, and may not
     work.  Use --enable-bootstrap-with-devel-snapshot to try it anyway,
172
     or 'GHC=' to specify a different GHC to use.])
ian@well-typed.com's avatar
ian@well-typed.com committed
173 174
    fi
fi
175

176 177 178
# GHC is passed to Cabal, so we need a native path
if test "${WithGhc}" != ""
then
179
    ghc_host_os=`"${WithGhc}" +RTS --info | grep 'Host OS' | sed -e 's/.*, "//' -e 's/")//'`
180

181
    if test "$ghc_host_os" = "mingw32"
182
    then
183 184 185 186 187 188 189
        if test "${OSTYPE}" = "msys"
        then
            WithGhc=`echo "${WithGhc}" | sed "s#^/\([a-zA-Z]\)/#\1:/#"`
        else
            # Canonicalise to <drive>:/path/to/ghc
            WithGhc=`cygpath -m "${WithGhc}"`
        fi
190 191 192 193 194
        echo "GHC path canonicalised to: ${WithGhc}"
    fi
fi
AC_SUBST([WithGhc])

195 196 197
dnl ** Without optimization some INLINE trickery fails for GHCi
SRC_CC_OPTS="-O"

198 199 200
dnl--------------------------------------------------------------------
dnl * Choose host(/target/build) platform
dnl--------------------------------------------------------------------
201 202
dnl If we aren't explicitly told what values to use with configure flags,
dnl we ask the bootstrapping compiler what platform it is for
203

204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
if test "${WithGhc}" != ""
then
        bootstrap_host=`"${WithGhc}" +RTS --info | grep '^ ,("Host platform"' | sed -e 's/.*, "//' -e 's/")//' | tr -d '\r'`
        bootstrap_target=`"${WithGhc}" +RTS --info | grep '^ ,("Target platform"' | sed -e 's/.*, "//' -e 's/")//' | tr -d '\r'`
        if test "$bootstrap_host" != "$bootstrap_target"
        then
                echo "Bootstrapping GHC is a cross compiler. This probably isn't going to work"
        fi
fi

# We have to run these unconditionally, but we may discard their
# results in the following code
AC_CANONICAL_BUILD
AC_CANONICAL_HOST
AC_CANONICAL_TARGET

220
FPTOOLS_SET_PLATFORM_VARS
221

222 223
# Verify that the installed (bootstrap) GHC is capable of generating
# code for the requested build platform.
ian@well-typed.com's avatar
ian@well-typed.com committed
224 225 226 227 228 229 230
if test "$BuildPlatform" != "$bootstrap_target"
then
    echo "This GHC (${WithGhc}) does not generate code for the build platform"
    echo "   GHC target platform    : $bootstrap_target"
    echo "   Desired build platform : $BuildPlatform"
    exit 1
fi
231

232 233
# Testing if we shall enable shared libs support on Solaris.
# Anything older than SunOS 5.11 aka Solaris 11 (Express) is broken.
234

235
SOLARIS_BROKEN_SHLD=NO
236

237 238 239 240 241
case $host in
     i386-*-solaris2)
     # here we go with the test
     MINOR=`uname -r|cut -d '.' -f 2-`
     if test "$MINOR" -lt "11"; then
242
         SOLARIS_BROKEN_SHLD=YES
243 244 245
     fi
     ;;
esac
246

247 248
AC_SUBST(SOLARIS_BROKEN_SHLD)

249 250
dnl ** Do an unregisterised build?
dnl --------------------------------------------------------------
251 252

AC_MSG_CHECKING(whether target supports a registerised ABI)
253
case "$TargetArch" in
254
    i386|x86_64|powerpc|powerpc64|powerpc64le|s390x|arm|aarch64)
255
        UnregisterisedDefault=NO
256
        AC_MSG_RESULT([yes])
257 258 259
        ;;
    *)
        UnregisterisedDefault=YES
260
        AC_MSG_RESULT([no])
261 262
        ;;
esac
263 264 265 266 267 268 269 270 271
FP_DEFAULT_CHOICE_OVERRIDE_CHECK(
  [unregisterised],
  [unregisterised],
  [registerised],
  [Unregisterised],
  [Build a toolchain with the unregisterised ABI (disabled by default on platforms with registerised support)],
  [NO],
  [YES],
  [no])
272 273
AC_SUBST(Unregisterised)

274 275 276 277 278 279 280 281 282 283
dnl ** Do a build with tables next to code?
dnl
dnl Whether the target architecture supports placing info tables
dnl directly before the entry code (see TABLES_NEXT_TO_CODE in the RTS).
dnl Whether we actually compile for TABLES_NEXT_TO_CODE depends on
dnl whether we're building unregisterised code or not, which may be
dnl decided by options to the compiler later.
dnl
dnl See https://gitlab.haskell.org/ghc/ghc/wikis/commentary/rts/storage/heap-objects#tables_next_to_code
dnl --------------------------------------------------------------
284 285

AC_MSG_CHECKING(whether target supports tables next to code)
286 287 288
case "$Unregisterised" in
    NO)
        case "$TargetArch" in
289
            ia64|powerpc64|powerpc64le|s390x)
290
                TablesNextToCodeDefault=NO
291
                AC_MSG_RESULT([no])
292 293 294
                ;;
            *)
                TablesNextToCodeDefault=YES
295
                AC_MSG_RESULT([yes])
296 297 298 299 300
                ;;
        esac
        ;;
    YES)
        TablesNextToCodeDefault=NO
301
        AC_MSG_RESULT([no])
302 303
        ;;
esac
304 305 306 307 308
FP_DEFAULT_CHOICE_OVERRIDE_CHECK(
  [tables-next-to-code],
  [tables next to code],
  [tables apart from code],
  [TablesNextToCode],
309
  [Build a tool chain with info tables laid out next to code (enabled by default when using the registerised ABI, on platforms that support it)])
310
if test x"$TablesNextToCode" = xYES; then
311
   AC_DEFINE([TABLES_NEXT_TO_CODE], [1], [Define to 1 if info tables are laid out next to code])
312 313 314
fi
AC_SUBST(TablesNextToCode)

315 316 317
dnl ** Does target have runtime linker support?
dnl --------------------------------------------------------------
case "$target" in
318
    powerpc64-*|powerpc64le-*|powerpc-ibm-aix*|s390x-ibm-linux)
319
        TargetHasRTSLinker=NO
320 321
        ;;
    *)
322
        TargetHasRTSLinker=YES
323 324
        ;;
esac
325
AC_SUBST(TargetHasRTSLinker)
326

327 328 329
# Requires FPTOOLS_SET_PLATFORM_VARS to be run first.
FP_FIND_ROOT

330

331 332
if test "$HostOS" = "mingw32"
then
333
    # Find the mingw-w64 7z file to extract.
334 335
    # NB. If you update the tarballs to a new version of gcc, don't
    # forget to tweak the paths in driver/gcc/gcc.c.
336 337 338
    if test "$HostArch" = "i386"
    then
        mingw_arch="i686"
339
        tarball_dest_dir="mingw-w64/i686"
340 341 342 343 344 345 346 347
        tarball_mingw_dir="mingw32"
    else
        mingw_arch="x86_64"
        tarball_dest_dir="mingw-w64/x86_64"
        tarball_mingw_dir="mingw64"
    fi
fi

348 349 350 351
set_up_tarballs() {
    AC_MSG_NOTICE([Checking for Windows toolchain tarballs...])
    local action
    if test "$TarballsAutodownload" = "NO"
352
    then
353
        action="verify"
354
    else
355
        action="download"
356
    fi
357
    $PYTHON mk/get-win32-tarballs.py $action $mingw_arch > missing-win32-tarballs
358 359 360 361 362 363 364 365 366 367 368
    case $? in
        0)
           rm missing-win32-tarballs
           ;;
        2)
           echo
           echo "Error:"
           echo "Needed msys2 tarballs are missing. You have a few options to get them,"
           echo
           echo "  * run configure with the --enable-tarballs-autodownload option"
           echo
369
           echo "  * run mk/get-win32-tarballs.py download $mingw_arch"
370 371 372 373 374 375 376 377 378 379 380 381
           echo
           echo "  * manually download the files listed in ./missing-win32-tarballs and place"
           echo "    them in the ghc-tarballs directory."
           echo
           exit 1
           ;;
        *)
           echo
           echo "Error fetching msys2 tarballs; see errors above."
           exit 1
           ;;
    esac
382 383 384 385 386 387

    # Extract all the tarballs in one go
    if ! test -d inplace/mingw
    then
        AC_MSG_NOTICE([Extracting Windows toolchain from archives (may take a while)...])
        rm -rf inplace/mingw
388
        local base_dir="../ghc-tarballs/${tarball_dest_dir}"
389 390 391 392
        ( cd inplace &&
        find "${base_dir}" -name "*.tar.xz" -exec tar xfJ {} \; &&
        rm ".MTREE" &&
        rm ".PKGINFO" &&
393
        cd .. ) || AC_MSG_ERROR([Could not extract Windows toolchains.])
394 395 396 397

        mv "inplace/${tarball_mingw_dir}" inplace/mingw &&
        touch inplace/mingw

398 399 400 401 402 403
        # NB. Now since the GCC is hardcoded to use /mingw32 we need to
        # make a wrapper around it to give it the proper paths
        mv inplace/mingw/bin/gcc.exe inplace/mingw/bin/realgcc.exe
        PATH=`pwd`/inplace/mingw/bin:$PATH
        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

404 405 406 407
        AC_MSG_NOTICE([In-tree MingW-w64 tree created])
    fi
}

408
if test "$HostOS" = "mingw32" -a "$EnableDistroToolchain" = "NO"
409 410 411 412 413 414
then
    test -d inplace || mkdir inplace

    # NB. Download and extract the MingW-w64 distribution if required
    set_up_tarballs

415
    mingwbin="$hardtop/inplace/mingw/bin/"
416 417 418
    CC="${mingwbin}gcc.exe"
    LD="${mingwbin}ld.exe"
    NM="${mingwbin}nm.exe"
419
    RANLIB="${mingwbin}ranlib.exe"
420
    OBJDUMP="${mingwbin}objdump.exe"
Ian Lynagh's avatar
Ian Lynagh committed
421
    fp_prog_ar="${mingwbin}ar.exe"
422

423
    AC_PATH_PROG([Genlib],[genlib])
424 425
fi

426 427 428 429 430 431 432 433 434 435 436 437 438 439
# We don't want to bundle a MinGW-w64 toolchain
# So we have to find these individual tools.
if test "$EnableDistroToolchain" = "YES"
then
    # Ideally should use AC_CHECK_TARGET_TOOL but our triples
    # are screwed up. Configure doesn't think they're ever equal and
    # so never tried without the prefix.
    AC_PATH_PROG([CC],[gcc], [clang])
    AC_PATH_PROG([NM],[nm])
    AC_PATH_PROG([AR],[ar])
    AC_PATH_PROG([RANLIB],[ranlib])
    AC_PATH_PROG([OBJDUMP],[objdump])
    AC_PATH_PROG([DllWrap],[dllwrap])
    AC_PATH_PROG([Windres],[windres])
440
    AC_PATH_PROG([Genlib],[genlib])
441 442 443 444
else
    AC_CHECK_TARGET_TOOL([Windres],[windres])
    AC_CHECK_TARGET_TOOL([DllWrap],[dllwrap])
    AC_CHECK_TARGET_TOOL([OBJDUMP],[objdump])
Tamar Christina's avatar
Tamar Christina committed
445
fi
446

Tamar Christina's avatar
Tamar Christina committed
447 448
DllWrapCmd="$DllWrap"
WindresCmd="$Windres"
449

450 451 452 453 454 455 456 457 458
HAVE_GENLIB=False
if test "$HostOS" = "mingw32"
then
    if test "$Genlib" != ""; then
        GenlibCmd="$(cygpath -m $Genlib)"
        HAVE_GENLIB=True
    fi
fi

Tamar Christina's avatar
Tamar Christina committed
459 460
AC_SUBST([DllWrapCmd])
AC_SUBST([WindresCmd])
461 462
AC_SUBST([GenlibCmd])
AC_SUBST([HAVE_GENLIB])
463

Ian Lynagh's avatar
Ian Lynagh committed
464 465
FP_ICONV
FP_GMP
466
FP_CURSES
Ian Lynagh's avatar
Ian Lynagh committed
467

468 469 470 471 472 473
dnl On Windows we force in-tree GMP build until we support dynamic linking
if test "$HostOS" = "mingw32"
then
  GMP_FORCE_INTREE="YES"
fi

474
XCODE_VERSION()
Ian Lynagh's avatar
Ian Lynagh committed
475

476

477 478 479 480
dnl ** Building a cross compiler?
dnl --------------------------------------------------------------
CrossCompiling=NO
# If 'host' and 'target' differ, then this means we are building a cross-compiler.
481
if test "$target" != "$host" ; then
482 483 484 485 486 487
    CrossCompiling=YES
    cross_compiling=yes   # This tells configure that it can accept just 'target',
                          # otherwise you get
                          #   configure: error: cannot run C compiled programs.
                          #   If you meant to cross compile, use `--host'.
fi
488
if test "$BuildPlatform" != "$HostPlatform" ; then
489 490 491
   AC_MSG_ERROR([
You've selected:

Tamar Christina's avatar
Tamar Christina committed
492 493 494
  BUILD:  $BuildPlatform   (the architecture we're building on)
  HOST:   $HostPlatform    (the architecture the compiler we're building will execute on)
  TARGET: $TargetPlatform  (the architecture the compiler we're building will produce code for)
495

Simon Marlow's avatar
Simon Marlow committed
496 497 498 499
BUILD must equal HOST; that is, we do not support building GHC itself
with a cross-compiler.  To cross-compile GHC itself, set TARGET: stage
1 will be a cross-compiler, and stage 2 will be the cross-compiled
GHC.
500 501
])
fi
502 503 504
# Despite its similarity in name to TargetPlatform, TargetPlatformFull is used
# in calls to subproject configure scripts and thus must be set to the autoconf
# triple, not the normalized GHC triple that TargetPlatform is set to.
505 506 507 508 509 510 511 512
#
# We use the non-canonicalized triple, target_alias, here since the subproject
# configure scripts will use this triple to construct the names of the toolchain
# executables. If we instead passed down the triple produced by
# AC_CANONICAL_TARGET then it may look for the target toolchain under the wrong
# name (this is a known problem in the case of the Android NDK, which has
# slightly odd triples).
#
513
# It may be better to just do away with the GHC triples altogether. This would
514 515 516
# all be taken care of for us if we configured the subprojects using
# AC_CONFIG_DIR, but unfortunately Cabal needs to be the one to do the
# configuration.
517 518
#
# We also use non-canonicalized triple when install stage1 crosscompiler
519 520 521 522 523 524 525
if test -z "${target_alias}"
then
  # --target wasn't given; use result from AC_CANONICAL_TARGET
  TargetPlatformFull="${target}"
else
  TargetPlatformFull="${target_alias}"
fi
526 527 528 529 530 531 532
if test "$CrossCompiling" = "YES"
then
  # Use value passed by user from --target=
  CrossCompilePrefix="${TargetPlatformFull}-"
else
  CrossCompilePrefix=""
fi
Simon Marlow's avatar
Simon Marlow committed
533
AC_SUBST(CrossCompiling)
534 535
AC_SUBST(CrossCompilePrefix)
AC_SUBST(TargetPlatformFull)
536
AC_SUBST(EnableDistroToolchain)
537

538 539 540
dnl ** Which gcc to use?
dnl --------------------------------------------------------------

541 542 543 544 545
AC_ARG_WITH([gcc],
        AS_HELP_STRING([--with-gcc=ARG], [Use ARG as the path to gcc (obsolete, use CC=ARG instead) [default=autodetect]]),
        AC_MSG_ERROR([--with-gcc=$withval is obsolete (use './configure CC=$withval' or 'CC=$withval ./configure' instead)]))

AC_ARG_WITH([clang],
546
        AS_HELP_STRING([--with-clang=ARG], [Use ARG as the path to clang (obsolete, use CC=ARG instead) [default=autodetect]]),
547 548 549 550
        AC_MSG_ERROR([--with-clang=$withval is obsolete (use './configure CC=$withval' or 'CC=$withval ./configure' instead)]))

dnl detect compiler (prefer gcc over clang) and set $CC (unless CC already set),
dnl later CC is copied to CC_STAGE{1,2,3}
roland's avatar
roland committed
551
AC_PROG_CC([cc gcc clang])
552

553 554
MAYBE_OVERRIDE_STAGE0([ar],[AR_STAGE0])

555 556 557
dnl make extensions visible to allow feature-tests to detect them lateron
AC_USE_SYSTEM_EXTENSIONS

thomie's avatar
thomie committed
558 559 560
dnl ** figure out how to invoke the C preprocessor (i.e. `gcc -E`)
AC_PROG_CPP

561 562
# --with-hs-cpp/--with-hs-cpp-flags
FP_CPP_CMD_WITH_ARGS(HaskellCPPCmd, HaskellCPPArgs)
thomie's avatar
thomie committed
563 564
AC_SUBST([HaskellCPPCmd])
AC_SUBST([HaskellCPPArgs])
565

566 567 568 569 570
FP_SET_CFLAGS_C99([CC],[CFLAGS],[CPPFLAGS])
FP_SET_CFLAGS_C99([CC_STAGE0],[CONF_CC_OPTS_STAGE0],[CONF_CPP_OPTS_STAGE0])
FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE1],[CONF_CPP_OPTS_STAGE1])
FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2])

John Ericson's avatar
John Ericson committed
571
dnl ** Which ld to use
572
dnl --------------------------------------------------------------
573
AC_ARG_VAR(LD,[Use as the path to ld. See also --disable-ld-override.])
574 575 576 577
FIND_LD([$target],[GccUseLdOpt])
CONF_GCC_LINKER_OPTS_STAGE1="$CONF_GCC_LINKER_OPTS_STAGE1 $GccUseLdOpt"
CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2 $GccUseLdOpt"
LdCmd="$LD"
578
LdNoGoldCmd="$LD_NO_GOLD"
579
CFLAGS="$CFLAGS $GccUseLdOpt"
580
AC_SUBST([LdCmd])
581
AC_SUBST([LdNoGoldCmd])
582

John Ericson's avatar
John Ericson committed
583 584 585 586 587
FP_PROG_LD_IS_GNU
FP_PROG_LD_BUILD_ID
FP_PROG_LD_NO_COMPACT_UNWIND
FP_PROG_LD_FILELIST

588 589
dnl ** Which nm to use?
dnl --------------------------------------------------------------
590 591 592 593 594 595 596 597
if test "$HostOS" != "mingw32"; then
    AC_CHECK_TARGET_TOOL([NM], [nm])
    if test "$NM" = ":"; then
        AC_MSG_ERROR([cannot find nm in your PATH])
    fi
fi
NmCmd="$NM"
AC_SUBST([NmCmd])
598 599 600 601

if test "$TargetOS_CPP" = "darwin"
then
    AC_MSG_CHECKING(whether nm program is broken)
602
    # Some versions of Xcode ship a broken version of `nm`. Detect and work
603
    # around this issue. See : https://gitlab.haskell.org/ghc/ghc/issues/11744
604 605 606 607 608 609
    nmver=$(${NM} --version | grep version | sed 's/ //g')
    case "$nmver" in
        LLVMversion7.3.0|LLVMversion7.3.1)
            AC_MSG_RESULT(yes)
            echo "The detected nm program is broken."
            echo
610
            echo "See: https://gitlab.haskell.org/ghc/ghc/issues/11744"
611 612 613
            echo
            echo "Try re-running configure with:"
            echo
Alex Biehl's avatar
Alex Biehl committed
614
            echo '   NM=$(xcrun --find nm-classic) ./configure'
615 616 617 618 619 620 621 622 623
            echo
            exit 1
            ;;
        *)
            AC_MSG_RESULT(no)
            ;;
        esac
fi

624 625
dnl ** Which objdump to use?
dnl --------------------------------------------------------------
626 627
dnl Note: we may not have objdump on OS X, and we only need it on
dnl Windows (for DLL checks), OpenBSD, and AIX
628
case $HostOS_CPP in
629
  cygwin32|mingw32|openbsd|aix)
630 631 632 633
    AC_CHECK_TARGET_TOOL([OBJDUMP], [objdump])
    ;;
esac

634 635 636
ObjdumpCmd="$OBJDUMP"
AC_SUBST([ObjdumpCmd])

637 638
dnl ** Which ranlib to use?
dnl --------------------------------------------------------------
639 640 641 642
AC_PROG_RANLIB
if test "$RANLIB" = ":"; then
    AC_MSG_ERROR([cannot find ranlib in your PATH])
fi
643
RanlibCmd="$RANLIB"
John Ericson's avatar
John Ericson committed
644
AC_SUBST([RanlibCmd])
645

646 647 648 649 650 651 652
dnl ** which strip to use?
dnl --------------------------------------------------------------
AC_CHECK_TARGET_TOOL([STRIP], [strip])
StripCmd="$STRIP"
AC_SUBST([StripCmd])


Moritz Angermann's avatar
Moritz Angermann committed
653 654
dnl ** which libtool to use?
dnl --------------------------------------------------------------
655 656
# The host normalization on Windows breaks autoconf, it no longer
# thinks that target == host so it never checks the unqualified
657
# tools for Windows. See #14274.
658 659 660 661 662 663 664 665 666
if test "$HostOS" = "mingw32"
then
    AC_PATH_PROG([LIBTOOL],[libtool])
    LibtoolCmd="$(cygpath -m $LIBTOOL)"
else
    AC_CHECK_TARGET_TOOL([LIBTOOL], [libtool])
    LibtoolCmd="$LIBTOOL"
fi
AC_SUBST([LibtoolCmd])
667

668 669 670 671
# Here is where we re-target which specific version of the LLVM
# tools we are looking for. In the past, GHC supported a number of
# versions of LLVM simultaneously, but that stopped working around
# 3.5/3.6 release of LLVM.
672
LlvmVersion=9
673
AC_SUBST([LlvmVersion])
674 675
sUPPORTED_LLVM_VERSION=$(echo \($LlvmVersion\) | sed 's/\./,/')
AC_DEFINE_UNQUOTED([sUPPORTED_LLVM_VERSION], ${sUPPORTED_LLVM_VERSION}, [The supported LLVM version number])
676

Moritz Angermann's avatar
Moritz Angermann committed
677 678
dnl ** Which LLVM clang to use?
dnl --------------------------------------------------------------
679
AC_ARG_VAR(CLANG,[Use as the path to clang [default=autodetect]])
Moritz Angermann's avatar
Moritz Angermann committed
680 681 682 683
AC_CHECK_TARGET_TOOL([CLANG], [clang])
ClangCmd="$CLANG"
AC_SUBST([ClangCmd])

684 685
dnl ** Which LLVM llc to use?
dnl --------------------------------------------------------------
686
AC_ARG_VAR(LLC,[Use as the path to LLVM's llc [default=autodetect]])
687
FIND_LLVM_PROG([LLC], [llc], [$LlvmVersion])
688 689 690 691 692
LlcCmd="$LLC"
AC_SUBST([LlcCmd])

dnl ** Which LLVM opt to use?
dnl --------------------------------------------------------------
693
AC_ARG_VAR(OPT,[Use as the path to LLVM's opt [default=autodetect]])
694
FIND_LLVM_PROG([OPT], [opt], [$LlvmVersion])
695 696 697
OptCmd="$OPT"
AC_SUBST([OptCmd])

sof's avatar
sof committed
698 699 700 701
dnl --------------------------------------------------------------
dnl End of configure script option section
dnl --------------------------------------------------------------

702 703 704
dnl ** Copy the files from the "fs" utility into the right folders.
dnl --------------------------------------------------------------
AC_MSG_NOTICE([Creating links for in-tree file handling routines.])
Ben Gamari's avatar
Ben Gamari committed
705 706 707 708 709
ln -f utils/fs/fs.* utils/lndir/
ln -f utils/fs/fs.* utils/unlit/
ln -f utils/fs/fs.* rts/
ln -f utils/fs/fs.h libraries/base/include/
ln -f utils/fs/fs.c libraries/base/cbits/
710
AC_MSG_NOTICE([Routines in place. Packages can now be build normally.])
sof's avatar
sof committed
711 712

dnl --------------------------------------------------------------
713 714 715
dnl ** Can the unix package be built?
dnl --------------------------------------------------------------

716 717
dnl ** does #! work?
AC_SYS_INTERPRETER()
sof's avatar
sof committed
718

rrt's avatar
rrt committed
719 720
dnl ** look for GCC and find out which version
dnl     Figure out which C compiler to use.  Gcc is preferred.
721
dnl     If gcc, make sure it's at least 4.6
rrt's avatar
rrt committed
722
dnl
723
FP_GCC_VERSION
724

Ben Gamari's avatar
Ben Gamari committed
725 726 727
dnl ** See whether gcc supports -no-pie
FP_GCC_SUPPORTS_NO_PIE

728 729 730
dnl ** Used to determine how to compile ghc-prim's atomics.c, used by
dnl    unregisterised, Sparc, and PPC backends.
FP_GCC_SUPPORTS__ATOMICS
731 732 733
if test $CONF_GCC_SUPPORTS__ATOMICS = YES ; then
  AC_DEFINE([HAVE_C11_ATOMICS], [1], [Does GCC support __atomic primitives?])
fi
734

John Ericson's avatar
John Ericson committed
735 736
FP_GCC_EXTRA_FLAGS

737 738 739 740
dnl ** look to see if we have a C compiler using an llvm back end.
dnl
FP_CC_LLVM_BACKEND

741 742 743 744
FPTOOLS_SET_C_LD_FLAGS([target],[CFLAGS],[LDFLAGS],[IGNORE_LINKER_LD_FLAGS],[CPPFLAGS])
FPTOOLS_SET_C_LD_FLAGS([build],[CONF_CC_OPTS_STAGE0],[CONF_GCC_LINKER_OPTS_STAGE0],[CONF_LD_LINKER_OPTS_STAGE0],[CONF_CPP_OPTS_STAGE0])
FPTOOLS_SET_C_LD_FLAGS([target],[CONF_CC_OPTS_STAGE1],[CONF_GCC_LINKER_OPTS_STAGE1],[CONF_LD_LINKER_OPTS_STAGE1],[CONF_CPP_OPTS_STAGE1])
FPTOOLS_SET_C_LD_FLAGS([target],[CONF_CC_OPTS_STAGE2],[CONF_GCC_LINKER_OPTS_STAGE2],[CONF_LD_LINKER_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2])
745
# Stage 3 won't be supported by cross-compilation
746

747 748
# See rules/distdir-way-opts.mk for details.
# Flags passed to the C compiler
749 750 751
AC_SUBST(CONF_CC_OPTS_STAGE0)
AC_SUBST(CONF_CC_OPTS_STAGE1)
AC_SUBST(CONF_CC_OPTS_STAGE2)
752
# Flags passed to the C compiler when we ask it to link
753 754 755
AC_SUBST(CONF_GCC_LINKER_OPTS_STAGE0)
AC_SUBST(CONF_GCC_LINKER_OPTS_STAGE1)
AC_SUBST(CONF_GCC_LINKER_OPTS_STAGE2)
756
# Flags passed to the linker when we ask it to link
757 758 759
AC_SUBST(CONF_LD_LINKER_OPTS_STAGE0)
AC_SUBST(CONF_LD_LINKER_OPTS_STAGE1)
AC_SUBST(CONF_LD_LINKER_OPTS_STAGE2)
760
# Flags passed to the C preprocessor
761 762 763
AC_SUBST(CONF_CPP_OPTS_STAGE0)
AC_SUBST(CONF_CPP_OPTS_STAGE1)
AC_SUBST(CONF_CPP_OPTS_STAGE2)
764 765 766 767
# Flags passed to the Haskell compiler
AC_SUBST(CONF_HC_OPTS_STAGE0)
AC_SUBST(CONF_HC_OPTS_STAGE1)
AC_SUBST(CONF_HC_OPTS_STAGE2)
rrt's avatar
rrt committed
768

769 770 771 772 773
dnl ** Set up the variables for the platform in the settings file.
dnl May need to use gcc to find platform details.
dnl --------------------------------------------------------------
FPTOOLS_SET_HASKELL_PLATFORM_VARS

774
dnl ** figure out how to do context diffs
775
FP_PROG_CONTEXT_DIFF
sof's avatar
sof committed
776

777 778 779
dnl Let's make sure install-sh is executable here.  If we got it from
dnl a darcs repo, it might not be (see bug #978).
chmod +x install-sh
780 781
dnl ** figure out how to do a BSD-ish install
AC_PROG_INSTALL
sof's avatar
sof committed
782

sof's avatar
sof committed
783
dnl ** how to invoke `ar' and `ranlib'
784
FP_PROG_AR_SUPPORTS_ATFILE
785
FP_PROG_AR_NEEDS_RANLIB
sof's avatar
sof committed
786

787
dnl ** Check to see whether ln -s works
sof's avatar
sof committed
788 789
AC_PROG_LN_S

790
FP_SETTINGS
sof's avatar
sof committed
791 792

dnl ** Find the path to sed
Ian Lynagh's avatar
Ian Lynagh committed
793
AC_PATH_PROGS(SedCmd,gsed sed,sed)
sof's avatar
sof committed
794

sof's avatar
sof committed
795 796

dnl ** check for time command
sof's avatar
sof committed
797 798
AC_PATH_PROG(TimeCmd,time)

sof's avatar
sof committed
799 800
dnl ** check for tar
dnl   if GNU tar is named gtar, look for it first.
801
AC_PATH_PROGS(TarCmd,gnutar gtar tar,tar)
sof's avatar
sof committed
802

803 804 805 806 807
dnl ** check for compressors
AC_PATH_PROGS(Bzip2Cmd,bzip2, bzip2)
AC_PATH_PROGS(GzipCmd,gzip, gzip)
AC_PATH_PROGS(XzCmd,pxz xz, xz)

Ian Lynagh's avatar
Ian Lynagh committed
808 809 810 811
dnl ** check for patch
dnl if GNU patch is named gpatch, look for it first
AC_PATH_PROGS(PatchCmd,gpatch patch, patch)

812 813 814
dnl ** check for autoreconf
AC_PATH_PROG(AutoreconfCmd, autoreconf, autoreconf)

815
dnl ** check for dtrace (currently only implemented for Mac OS X)
816 817 818 819 820 821 822
AC_ARG_ENABLE(dtrace,
    [AC_HELP_STRING([--enable-dtrace],
        [Enable DTrace])],
    EnableDtrace=$enableval,
    EnableDtrace=yes
)

823
HaveDtrace=NO
824

825
AC_PATH_PROG(DtraceCmd,dtrace)
826 827 828 829 830 831 832
if test "x$EnableDtrace" = "xyes"; then
  if test -n "$DtraceCmd"; then
    if test "x$TargetOS_CPP-$TargetVendor_CPP" = "xdarwin-apple" \
      -o "x$TargetOS_CPP-$TargetVendor_CPP" = "xfreebsd-portbld" \
      -o "x$TargetOS_CPP-$TargetVendor_CPP" = "xsolaris2-unknown"; then
      HaveDtrace=YES
    fi
833 834 835 836
  fi
fi
AC_SUBST(HaveDtrace)

837
AC_PATH_PROG(HSCOLOUR,HsColour)
838
# HsColour is passed to Cabal, so we need a native path
839
if test "$HostOS"      = "mingw32" && \
840
   test "${OSTYPE}"   != "msys"    && \
841
   test "${HSCOLOUR}" != ""
842 843 844
then
    # Canonicalise to <drive>:/path/to/gcc
    HSCOLOUR=`cygpath -m ${HSCOLOUR}`
845
fi
846

847
dnl ** check for Sphinx toolchain
848 849
AC_PATH_PROG(SPHINXBUILD,sphinx-build)
AC_CACHE_CHECK([for version of sphinx-build], fp_cv_sphinx_version,
850 851
changequote(, )dnl
[if test -n "$SPHINXBUILD"; then
852
  fp_cv_sphinx_version=`"$SPHINXBUILD" --version 2>&1 | sed 's/.* \([0-9]\.[0-9]\.[0-9]\)/\1/' | head -n1`;
853 854 855
fi;
changequote([, ])dnl
])
856 857
FP_COMPARE_VERSIONS([$fp_cv_sphinx_version],-lt,1.0.0,
    [AC_MSG_WARN([Sphinx version 1.0.0 or later is required to build documentation]); SPHINXBUILD=;])
858 859
if test -n "$SPHINXBUILD"; then
  if "$SPHINXBUILD" -b text utils/check-sphinx utils/check-sphinx/dist > /dev/null 2>&1; then true; else
860 861
    AC_MSG_WARN([Sphinx for python3 is required to build documentation.])
    SPHINXBUILD=;
862 863
  fi
fi
864 865 866

dnl ** check for xelatex
AC_PATH_PROG(XELATEX,xelatex)
867

868 869 870
dnl ** check for makeinfo
AC_PATH_PROG(MAKEINFO,makeinfo)

871 872 873
dnl ** check for Python for testsuite driver
FIND_PYTHON

874
dnl ** check for ghc-pkg command
875
FP_PROG_GHC_PKG
876

sof's avatar
sof committed
877
dnl ** check for installed happy binary + version
878 879

AC_ARG_VAR(HAPPY,[Use as the path to happy [default=autodetect]])
sof's avatar
sof committed
880
FPTOOLS_HAPPY
sof's avatar
sof committed
881

882
dnl ** check for installed alex binary + version
883 884

AC_ARG_VAR(ALEX,[Use as the path to alex [default=autodetect]])
885 886
FPTOOLS_ALEX

sof's avatar
sof committed
887 888 889
dnl --------------------------------------------------
dnl ### program checking section ends here ###
dnl --------------------------------------------------
sof's avatar
sof committed
890

sof's avatar
sof committed
891 892 893
dnl --------------------------------------------------
dnl * Platform header file and syscall feature tests
dnl ### checking the state of the local header files and syscalls ###
sof's avatar
sof committed
894

895 896
dnl ** check for full ANSI header (.h) files
AC_HEADER_STDC
sof's avatar
sof committed
897

898 899 900 901
dnl ** Enable large file support.  NB. do this before testing the type of
dnl    off_t, because it will affect the result of that test.
AC_SYS_LARGEFILE

902
dnl ** check for specific header (.h) files that we are interested in
903
AC_CHECK_HEADERS([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/param.h sys/mman.h sys/resource.h sys/select.h sys/time.h sys/timeb.h sys/timerfd.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])
904 905 906 907 908 909 910

dnl sys/cpuset.h needs sys/param.h to be included first on FreeBSD 9.1; #7708
AC_CHECK_HEADERS([sys/cpuset.h], [], [],
[[#if HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
]])
911

912 913
dnl ** check if it is safe to include both <time.h> and <sys/time.h>
AC_HEADER_TIME
sof's avatar
sof committed
914

915
dnl ** do we have long longs?
916
AC_CHECK_TYPES([long long])
917

918
dnl ** what are the sizes of various types
919 920 921 922 923
FP_CHECK_SIZEOF_AND_ALIGNMENT(char)
FP_CHECK_SIZEOF_AND_ALIGNMENT(double)
FP_CHECK_SIZEOF_AND_ALIGNMENT(float)
FP_CHECK_SIZEOF_AND_ALIGNMENT(int)
FP_CHECK_SIZEOF_AND_ALIGNMENT(long)
924
if test "$ac_cv_type_long_long" = yes; then
925
FP_CHECK_SIZEOF_AND_ALIGNMENT(long long)
926
fi
927 928 929 930
FP_CHECK_SIZEOF_AND_ALIGNMENT(short)
FP_CHECK_SIZEOF_AND_ALIGNMENT(unsigned char)
FP_CHECK_SIZEOF_AND_ALIGNMENT(unsigned int)
FP_CHECK_SIZEOF_AND_ALIGNMENT(unsigned long)
931
if test "$ac_cv_type_long_long" = yes; then
932
FP_CHECK_SIZEOF_AND_ALIGNMENT(unsigned long long)
933
fi
934 935 936 937 938 939 940 941 942 943 944 945
FP_CHECK_SIZEOF_AND_ALIGNMENT(unsigned short)
FP_CHECK_SIZEOF_AND_ALIGNMENT(void *)

FP_CHECK_SIZEOF_AND_ALIGNMENT(int8_t)
FP_CHECK_SIZEOF_AND_ALIGNMENT(uint8_t)
FP_CHECK_SIZEOF_AND_ALIGNMENT(int16_t)
FP_CHECK_SIZEOF_AND_ALIGNMENT(uint16_t)
FP_CHECK_SIZEOF_AND_ALIGNMENT(int32_t)
FP_CHECK_SIZEOF_AND_ALIGNMENT(uint32_t)
FP_CHECK_SIZEOF_AND_ALIGNMENT(int64_t)
FP_CHECK_SIZEOF_AND_ALIGNMENT(uint64_t)

946

947
dnl for use in settings file
948
TargetWordSize=$ac_cv_sizeof_void_p
949
if test "x$TargetWordSize" = x8; then
950 951 952 953
  AC_SUBST([Cabal64bit],[True])
else
  AC_SUBST([Cabal64bit],[False])
fi
954
AC_SUBST(TargetWordSize)
955 956 957 958

AC_C_BIGENDIAN([TargetWordBigEndian=YES],[TargetWordBigEndian=NO])
AC_SUBST(TargetWordBigEndian)

959 960
FP_CHECK_FUNC([WinExec],
  [@%:@include <windows.h>], [WinExec("",0)])
961

962 963
FP_CHECK_FUNC([GetModuleFileName],
  [@%:@include <windows.h>], [GetModuleFileName((HMODULE)0,(LPTSTR)0,0)])
964 965

dnl ** check for more functions
966
dnl ** The following have been verified to be used in ghc/, but might be used somewhere else, too.
967
AC_CHECK_FUNCS([getclock getrusage gettimeofday setitimer siginterrupt sysconf times ctime_r sched_setaffinity setlocale])
968

969 970 971 972 973 974 975
dnl ** On OS X 10.4 (at least), time.h doesn't declare ctime_r if
dnl ** _POSIX_C_SOURCE is defined
AC_CHECK_DECLS([ctime_r], , ,
[#define _POSIX_SOURCE 1
#define _POSIX_C_SOURCE 199506L
#include <time.h>])

976
dnl ** check for mingwex library
977 978 979 980 981
AC_CHECK_LIB(
  [mingwex],
  [closedir],
  [AC_SUBST([HaveLibMingwEx],[YES])] [AC_SUBST([CabalMingwex],[True])],
  [AC_SUBST([HaveLibMingwEx],[NO])] [AC_SUBST([CabalMingwex],[False])])
982 983

if test $HaveLibMingwEx = YES ; then
984
  AC_DEFINE([HAVE_MINGWEX], [1], [Define to 1 if you have the mingwex library.])
985 986
fi

987
dnl ** check for math library
988 989 990
dnl    Keep that check as early as possible.
dnl    as we need to know whether we need libm
dnl    for math functions or not
991
dnl    (see https://gitlab.haskell.org/ghc/ghc/issues/3730)
992 993 994 995
AC_CHECK_LIB(m, atan, HaveLibM=YES, HaveLibM=NO)
if test $HaveLibM = YES
then
  AC_DEFINE([HAVE_LIBM], [1], [Define to 1 if you need to link with libm])
996 997 998
  AC_SUBST([CabalHaveLibm],[True])
else
  AC_SUBST([CabalHaveLibm],[False])
999
fi
1000

1001
FP_BFD_SUPPORT
1002

1003 1004 1005 1006
dnl ################################################################
dnl Check for libraries
dnl ################################################################

1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
# system libffi

AC_ARG_WITH([system-libffi],
[AC_HELP_STRING([--with-system-libffi],
  [Use system provided libffi for RTS [default=no]])
])

AS_IF([test "x$with_system_libffi" = "xyes"],
  [UseSystemLibFFI="YES"], [UseSystemLibFFI="NO"]
)

AC_SUBST(UseSystemLibFFI)

AC_ARG_WITH([ffi-includes],
[AC_HELP_STRING([--with-ffi-includes=ARG],
  [Find includes for libffi in ARG [default=system default]])
],
[
 if test "x$UseSystemLibFFI" != "xYES"; then
    AC_MSG_WARN([--with-ffi-includes will be ignored, --with-system-libffi not set])
 else
    FFIIncludeDir="$withval"
    LIBFFI_CFLAGS="-I$withval"
 fi
])

AC_SUBST(FFIIncludeDir)

AC_ARG_WITH([ffi-libraries],
[AC_HELP_STRING([--with-ffi-libraries=ARG],
  [Find libffi in ARG [default=system default]])
],
[
 if test "x$UseSystemLibFFI" != "xYES"; then
    AC_MSG_WARN([--with-ffi-libraries will be ignored, --with-system-libffi not set])
 else
    FFILibDir="$withval" LIBFFI_LDFLAGS="-L$withval"
 fi
])

AC_SUBST(FFILibDir)

1049
AC_SUBST([CabalHaveLibffi],[False])
1050 1051 1052 1053 1054
AS_IF([test "$UseSystemLibFFI" = "YES"], [
 CFLAGS2="$CFLAGS"
 CFLAGS="$LIBFFI_CFLAGS $CFLAGS"
 LDFLAGS2="$LDFLAGS"
 LDFLAGS="$LIBFFI_LDFLAGS $LDFLAGS"
1055 1056 1057 1058 1059 1060 1061 1062 1063
 if test "$HostOS" = "openbsd";
 then
   # OpenBSD's libffi is not directly linked to the libpthread but
   # still requires pthread functionality. This means that any client
   # binary which links with libffi also needs to link with
   # libpthread. If it does not, then linking fails with unresolved
   # symbols.
   LDFLAGS="$LDFLAGS -lpthread"
 fi
1064 1065
 AC_CHECK_LIB(ffi, ffi_call,
  [AC_CHECK_HEADERS([ffi.h], [break], [])
1066 1067
   AC_DEFINE([HAVE_LIBFFI], [1], [Define to 1 if you have libffi.])]
   AC_SUBST([CabalHaveLibffi],[True]),
1068 1069 1070 1071 1072
  [AC_MSG_ERROR([Cannot find system libffi])])
 CFLAGS="$CFLAGS2"
 LDFLAGS="$LDFLAGS2"
])

1073
dnl ** check whether we need -ldl to get dlopen()
1074 1075
AC_CHECK_LIB([dl], [dlopen])
AC_CHECK_LIB([dl], [dlopen], [AC_SUBST([CabalHaveLibdl], [True])], [AC_SUBST([CabalHaveLibdl], [False])])
1076

1077
dnl --------------------------------------------------
sof's avatar
sof committed
1078 1079 1080
dnl * Miscellaneous feature tests
dnl --------------------------------------------------

sof's avatar
sof committed
1081
dnl ** can we get alloca?
1082
AC_FUNC_ALLOCA
sof's avatar
sof committed
1083

1084
dnl ** working vfork?
1085
AC_FUNC_FORK
1086

1087 1088
dnl ** determine whether or not const works
AC_C_CONST
sof's avatar
sof committed
1089

1090 1091
dnl ** are we big endian?
AC_C_BIGENDIAN
1092
FPTOOLS_FLOAT_WORD_ORDER_BIGENDIAN
sof's avatar
sof committed
1093

1094
dnl ** check for leading underscores in symbol names
1095
FP_LEADING_UNDERSCORE
1096

1097 1098
FP_VISIBILITY_HIDDEN

1099
dnl ** check for librt
1100 1101
AC_CHECK_LIB([rt], [clock_gettime])
AC_CHECK_LIB([rt], [clock_gettime], [AC_SUBST([CabalHaveLibrt], [True])], [AC_SUBST([CabalHaveLibrt], [False])])
1102
AC_CHECK_FUNCS(clock_gettime timer_settime)
1103
FP_CHECK_TIMER_CREATE
1104

1105
dnl ** check for Apple's "interesting" long double compatibility scheme
1106 1107
AC_MSG_CHECKING(for printf\$LDBLStub)
AC_TRY_LINK_FUNC(printf\$LDBLStub,
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
    [
        AC_MSG_RESULT(yes)
        AC_DEFINE([HAVE_PRINTF_LDBLSTUB],[1],
            [Define to 1 if we have printf$LDBLStub (Apple Mac OS >= 10.4, PPC).])
    ],
    [
        AC_MSG_RESULT(no)
        AC_DEFINE([HAVE_PRINTF_LDBLSTUB],[0],
            [Define to 1 if we have printf$LDBLStub (Apple Mac OS >= 10.4, PPC).])
    ])

1119 1120 1121 1122 1123 1124 1125 1126 1127
dnl Some platforms (e.g. Android's Bionic) have pthreads support available
dnl without linking against libpthread. Check whether -lpthread is necessary
dnl to use pthreads.
dnl
dnl Note that it is important that this happens before we AC_CHECK_LIB(thread)
AC_MSG_CHECKING(whether -lpthread is needed for pthreads)
AC_CHECK_FUNC(pthread_create,
    [
        AC_MSG_RESULT(no)
1128
        AC_SUBST([CabalNeedLibpthread],[False])
1129 1130 1131 1132 1133 1134
        need_lpthread=0
    ],
    [
        AC_CHECK_LIB(pthread, pthread_create,
            [
                AC_MSG_RESULT(yes)
1135
                AC_SUBST([CabalNeedLibpthread],[True])
1136 1137 1138
                need_lpthread=1
            ],
            [
1139
                AC_SUBST([CabalNeedLibpthread],[False])
1140 1141 1142 1143 1144 1145 1146
                AC_MSG_RESULT([no pthreads support found.])
                need_lpthread=0
            ])
    ])
AC_DEFINE_UNQUOTED([NEED_PTHREAD_LIB], [$need_lpthread],
    [Define 1 if we need to link code using pthreads with -lpthread])

1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
dnl ** pthread_setname_np is a recent addition to glibc, and OS X has
dnl    a different single-argument version.
AC_CHECK_LIB(pthread, pthread_setname_np)
AC_MSG_CHECKING(for pthread_setname_np)
AC_TRY_LINK(
[
#define _GNU_SOURCE
#include <pthread.h>
],
[pthread_setname_np(pthread_self(), "name");],
    AC_MSG_RESULT(yes)
    AC_DEFINE([HAVE_PTHREAD_SETNAME_NP], [1],
      [Define to 1 if you have the glibc version of pthread_setname_np]),
    AC_MSG_RESULT(no)
)

1163 1164 1165 1166
dnl ** check for eventfd which is needed by the I/O manager
AC_CHECK_HEADERS([sys/eventfd.h])
AC_CHECK_FUNCS([eventfd])

1167 1168 1169 1170 1171 1172
dnl ** Check for __thread support in the compiler
AC_MSG_CHECKING(for __thread support)
AC_COMPILE_IFELSE(
  [ AC_LANG_SOURCE([[__thread int tester = 0;]]) ],
  [
   AC_MSG_RESULT(yes)
1173
   AC_DEFINE([CC_SUPPORTS_TLS],[1],[Define to 1 if __thread is supported])
1174 1175 1176
  ],
  [
   AC_MSG_RESULT(no)
1177
   AC_DEFINE([CC_SUPPORTS_TLS],[0],[Define to 1 if __thread is supported])
1178 1179
  ])

1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
dnl large address space support (see includes/rts/storage/MBlock.h)
dnl
dnl Darwin has vm_allocate/vm_protect
dnl Linux has mmap(MAP_NORESERVE)/madv(MADV_DONTNEED)
dnl FreeBSD, Solaris and maybe other have MAP_NORESERVE/MADV_FREE
dnl (They also have MADV_DONTNEED, but it means something else!)
dnl
dnl Windows has VirtualAlloc MEM_RESERVE/MEM_COMMIT, however
dnl it counts page-table space as committed memory, and so quickly
dnl runs out of paging file when we have multiple processes reserving
dnl 1TB of address space, we get the following error:
dnl    VirtualAlloc MEM_RESERVE 1099512676352 bytes failed: The paging file is too small for this operation to complete.
dnl
1193 1194 1195 1196 1197 1198 1199 1200

AC_ARG_ENABLE(large-address-space,
    [AC_HELP_STRING([--enable-large-address-space],
        [Use a single large address space on 64 bit systems (enabled by default on 64 bit platforms)])],
    EnableLargeAddressSpace=$enableval,
    EnableLargeAddressSpace=yes
)

1201 1202
use_large_address_space=no
if test "$ac_cv_sizeof_void_p" -eq 8 ; then
1203 1204 1205
    if test "x$EnableLargeAddressSpace" = "xyes" ; then
        if test "$ghc_host_os" = "darwin" ; then
            use_large_address_space=yes
1206 1207 1208 1209
	elif test "$ghc_host_os" = "openbsd" ; then
	    # as of OpenBSD 5.8 (2015), OpenBSD does not support mmap with MAP_NORESERVE.
	    # The flag MAP_NORESERVE is supported for source compatibility reasons,
	    # but is completely ignored by OS mmap
1210
            use_large_address_space=no
1211
        else
1212
            AC_CHECK_DECLS([MAP_NORESERVE, MADV_FREE, MADV_DONTNEED],[],[],
1213 1214 1215 1216 1217 1218
                [
                #include <unistd.h>
                #include <sys/types.h>
                #include <sys/mman.h>
                #include <fcntl.h>
            ])
1219 1220 1221
            if test "$ac_cv_have_decl_MAP_NORESERVE" = "yes" &&
                test "$ac_cv_have_decl_MADV_FREE" = "yes" ||
                test "$ac_cv_have_decl_MADV_DONTNEED" = "yes" ; then
1222 1223 1224 1225
                    use_large_address_space=yes
            fi
        fi
    fi
1226 1227 1228 1229 1230
fi
if test "$use_large_address_space" = "yes" ; then
   AC_DEFINE([USE_LARGE_ADDRESS_SPACE], [1], [Enable single heap address space support])
fi

1231 1232 1233 1234
dnl ** Use MMAP in the runtime linker?
dnl --------------------------------------------------------------

case ${TargetOS} in
1235
    linux|linux-android|freebsd|dragonfly|netbsd|openbsd|kfreebsdgnu|gnu|solaris2)
1236 1237
        RtsLinkerUseMmap=1
        ;;
1238
    darwin|ios|watchos|tvos)
1239
        RtsLinkerUseMmap=1
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249
        ;;
    *)
        # Windows (which doesn't have mmap) and everything else.
        RtsLinkerUseMmap=0
        ;;
    esac

AC_DEFINE_UNQUOTED([RTS_LINKER_USE_MMAP], [$RtsLinkerUseMmap],
                   [Use mmap in the runtime linker])

1250 1251
dnl ** Have libdw?
dnl --------------------------------------------------------------
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273
AC_ARG_WITH([libdw-libraries],
  [AC_HELP_STRING([--with-libdw-libraries=ARG],
    [Find libraries for libdw in ARG [default=system default]])
  ],
  [
    LibdwLibDir="$withval"
    LIBDW_LDFLAGS="-L$withval"
  ])

AC_SUBST(LibdwLibDir)

AC_ARG_WITH([libdw-includes],
  [AC_HELP_STRING([--with-libdw-includes=ARG],
    [Find includes for libdw in ARG [default=system default]])
  ],
  [
    LibdwIncludeDir="$withval"
    LIBDW_CFLAGS="-I$withval"
  ])

AC_SUBST(LibdwIncludeDir)

1274 1275 1276
UseLibdw=NO
USE_LIBDW=0
AC_ARG_ENABLE(dwarf-unwind,
1277
    [AC_HELP_STRING([--enable-dwarf-unwind],
1278 1279
        [Enable DWARF unwinding support in the runtime system via elfutils' libdw [default=no]])])
if test "$enable_dwarf_unwind" = "yes" ; then
1280 1281 1282 1283 1284
  CFLAGS2="$CFLAGS"
  CFLAGS="$LIBDW_CFLAGS $CFLAGS"
  LDFLAGS2="$LDFLAGS"
  LDFLAGS="$LIBDW_LDFLAGS $LDFLAGS"