1# Extra autoconf macros for the Glasgow fptools 2# 3# To be a good autoconf citizen, names of local macros have prefixed with FP_ to 4# ensure we don't clash with any pre-supplied autoconf ones. 5 6m4_include([m4/ax_compare_version.m4]) 7 8# FPTOOLS_WRITE_FILE 9# ------------------ 10# Write $2 to the file named $1. 11AC_DEFUN([FPTOOLS_WRITE_FILE], 12[ 13cat >$1 <<ACEOF 14$2 15ACEOF 16]) 17 18AC_DEFUN([GHC_SELECT_FILE_EXTENSIONS], 19[ 20 $2='' 21 $3='.so' 22 case $1 in 23 *-unknown-cygwin32) 24 AC_MSG_WARN([GHC does not support the Cygwin target at the moment]) 25 AC_MSG_WARN([I'm assuming you wanted to build for i386-unknown-mingw32]) 26 exit 1 27 ;; 28 # examples: i386-unknown-mingw32, i686-w64-mingw32, x86_64-w64-mingw32 29 *-mingw32) 30 windows=YES 31 $2='.exe' 32 $3='.dll' 33 ;; 34 # apple platform uses .dylib (macOS, iOS, ...) 35 *-apple-*) 36 $3='.dylib' 37 ;; 38 esac 39]) 40 41# FPTOOLS_SET_PLATFORM_VARS 42# ---------------------------------- 43# Set the platform variables 44AC_DEFUN([FPTOOLS_SET_PLATFORM_VARS], 45[ 46 # If no argument was given for a configuration variable, then discard 47 # the guessed canonical system and use the configuration of the 48 # bootstrapping ghc. If an argument was given, map it from gnu format 49 # to ghc format. 50 # 51 # For why we do it this way, see: #3637, #1717, #2951 52 # 53 # In bindists, we haven't called AC_CANONICAL_{BUILD,HOST,TARGET} 54 # so this justs uses $bootstrap_target. 55 56 if test "$build_alias" = "" 57 then 58 if test "$bootstrap_target" != "" 59 then 60 build=$bootstrap_target 61 echo "Build platform inferred as: $build" 62 else 63 echo "Can't work out build platform" 64 exit 1 65 fi 66 67 BuildArch=`echo "$build" | sed 's/-.*//'` 68 BuildVendor=`echo "$build" | sed -e 's/.*-\(.*\)-.*/\1/'` 69 BuildOS=`echo "$build" | sed 's/.*-//'` 70 else 71 GHC_CONVERT_CPU([$build_cpu], [BuildArch]) 72 GHC_CONVERT_VENDOR([$build_vendor], [BuildVendor]) 73 GHC_CONVERT_OS([$build_os], [$BuildArch], [BuildOS]) 74 fi 75 76 if test "$host_alias" = "" 77 then 78 if test "$bootstrap_target" != "" 79 then 80 host=$bootstrap_target 81 echo "Host platform inferred as: $host" 82 else 83 echo "Can't work out host platform" 84 exit 1 85 fi 86 87 HostArch=`echo "$host" | sed 's/-.*//'` 88 HostVendor=`echo "$host" | sed -e 's/.*-\(.*\)-.*/\1/'` 89 HostOS=`echo "$host" | sed 's/.*-//'` 90 else 91 GHC_CONVERT_CPU([$host_cpu], [HostArch]) 92 GHC_CONVERT_VENDOR([$host_vendor], [HostVendor]) 93 GHC_CONVERT_OS([$host_os], [$HostArch], [HostOS]) 94 fi 95 96 if test "$target_alias" = "" 97 then 98 if test "$host_alias" != "" 99 then 100 GHC_CONVERT_CPU([$host_cpu], [TargetArch]) 101 GHC_CONVERT_VENDOR([$host_vendor], [TargetVendor]) 102 GHC_CONVERT_OS([$host_os], [$TargetArch],[TargetOS]) 103 else 104 if test "$bootstrap_target" != "" 105 then 106 target=$bootstrap_target 107 echo "Target platform inferred as: $target" 108 else 109 echo "Can't work out target platform" 110 exit 1 111 fi 112 113 TargetArch=`echo "$target" | sed 's/-.*//'` 114 TargetVendor=`echo "$target" | sed -e 's/.*-\(.*\)-.*/\1/'` 115 TargetOS=`echo "$target" | sed 's/.*-//'` 116 fi 117 else 118 GHC_CONVERT_CPU([$target_cpu], [TargetArch]) 119 GHC_CONVERT_VENDOR([$target_vendor], [TargetVendor]) 120 GHC_CONVERT_OS([$target_os], [$TargetArch], [TargetOS]) 121 fi 122 123 GHC_LLVM_TARGET([$target],[$target_cpu],[$target_vendor],[$target_os],[LlvmTarget]) 124 125 GHC_SELECT_FILE_EXTENSIONS([$host], [exeext_host], [soext_host]) 126 GHC_SELECT_FILE_EXTENSIONS([$target], [exeext_target], [soext_target]) 127 windows=NO 128 case $host in 129 *-unknown-mingw32) 130 windows=YES 131 ;; 132 esac 133 134 BuildPlatform="$BuildArch-$BuildVendor-$BuildOS" 135 BuildPlatform_CPP=`echo "$BuildPlatform" | sed -e 's/\./_/g' -e 's/-/_/g'` 136 BuildArch_CPP=` echo "$BuildArch" | sed -e 's/\./_/g' -e 's/-/_/g'` 137 BuildVendor_CPP=` echo "$BuildVendor" | sed -e 's/\./_/g' -e 's/-/_/g'` 138 BuildOS_CPP=` echo "$BuildOS" | sed -e 's/\./_/g' -e 's/-/_/g'` 139 140 HostPlatform="$HostArch-$HostVendor-$HostOS" 141 HostPlatform_CPP=`echo "$HostPlatform" | sed -e 's/\./_/g' -e 's/-/_/g'` 142 HostArch_CPP=` echo "$HostArch" | sed -e 's/\./_/g' -e 's/-/_/g'` 143 HostVendor_CPP=` echo "$HostVendor" | sed -e 's/\./_/g' -e 's/-/_/g'` 144 HostOS_CPP=` echo "$HostOS" | sed -e 's/\./_/g' -e 's/-/_/g'` 145 146 TargetPlatform="$TargetArch-$TargetVendor-$TargetOS" 147 TargetPlatform_CPP=`echo "$TargetPlatform" | sed -e 's/\./_/g' -e 's/-/_/g'` 148 TargetArch_CPP=` echo "$TargetArch" | sed -e 's/\./_/g' -e 's/-/_/g'` 149 TargetVendor_CPP=` echo "$TargetVendor" | sed -e 's/\./_/g' -e 's/-/_/g'` 150 TargetOS_CPP=` echo "$TargetOS" | sed -e 's/\./_/g' -e 's/-/_/g'` 151 152 # we intend to pass trough --targets to llvm as is. 153 LLVMTarget_CPP=` echo "$LlvmTarget"` 154 155 echo "GHC build : $BuildPlatform" 156 echo "GHC host : $HostPlatform" 157 echo "GHC target : $TargetPlatform" 158 echo "LLVM target: $LlvmTarget" 159 160 AC_SUBST(BuildPlatform) 161 AC_SUBST(HostPlatform) 162 AC_SUBST(TargetPlatform) 163 AC_SUBST(HostPlatform_CPP) 164 AC_SUBST(BuildPlatform_CPP) 165 AC_SUBST(TargetPlatform_CPP) 166 167 AC_SUBST(HostArch_CPP) 168 AC_SUBST(BuildArch_CPP) 169 AC_SUBST(TargetArch_CPP) 170 171 AC_SUBST(HostOS_CPP) 172 AC_SUBST(BuildOS_CPP) 173 AC_SUBST(TargetOS_CPP) 174 AC_SUBST(LLVMTarget_CPP) 175 176 AC_SUBST(HostVendor_CPP) 177 AC_SUBST(BuildVendor_CPP) 178 AC_SUBST(TargetVendor_CPP) 179 180 AC_SUBST(exeext_host) 181 AC_SUBST(exeext_target) 182 AC_SUBST(soext_host) 183 AC_SUBST(soext_target) 184]) 185 186 187# FPTOOLS_SET_HASKELL_PLATFORM_VARS 188# ---------------------------------- 189# Set the Haskell platform variables 190AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS], 191[ 192 checkArch() { 193 case [$]1 in 194 i386) 195 test -z "[$]2" || eval "[$]2=ArchX86" 196 ;; 197 x86_64|amd64) 198 test -z "[$]2" || eval "[$]2=ArchX86_64" 199 ;; 200 powerpc) 201 test -z "[$]2" || eval "[$]2=ArchPPC" 202 ;; 203 powerpc64) 204 test -z "[$]2" || eval "[$]2=\"ArchPPC_64 {ppc_64ABI = ELF_V1}\"" 205 ;; 206 powerpc64le) 207 test -z "[$]2" || eval "[$]2=\"ArchPPC_64 {ppc_64ABI = ELF_V2}\"" 208 ;; 209 s390x) 210 test -z "[$]2" || eval "[$]2=ArchS390X" 211 ;; 212 sparc) 213 test -z "[$]2" || eval "[$]2=ArchSPARC" 214 ;; 215 sparc64) 216 test -z "[$]2" || eval "[$]2=ArchSPARC64" 217 ;; 218 arm) 219 GET_ARM_ISA() 220 test -z "[$]2" || eval "[$]2=\"ArchARM {armISA = \$ARM_ISA, armISAExt = \$ARM_ISA_EXT, armABI = \$ARM_ABI}\"" 221 ;; 222 aarch64) 223 test -z "[$]2" || eval "[$]2=ArchAArch64" 224 ;; 225 alpha) 226 test -z "[$]2" || eval "[$]2=ArchAlpha" 227 ;; 228 mips|mipseb) 229 test -z "[$]2" || eval "[$]2=ArchMipseb" 230 ;; 231 mipsel) 232 test -z "[$]2" || eval "[$]2=ArchMipsel" 233 ;; 234 hppa|hppa1_1|ia64|m68k|nios2|riscv32|riscv64|rs6000|s390|sh4|vax) 235 test -z "[$]2" || eval "[$]2=ArchUnknown" 236 ;; 237 *) 238 echo "Unknown arch [$]1" 239 exit 1 240 ;; 241 esac 242 } 243 244 checkVendor() { 245 case [$]1 in 246 dec|none|unknown|hp|apple|next|sun|sgi|ibm|montavista|portbld|alpine) 247 ;; 248 *) 249 AC_MSG_WARN([Unknown vendor [$]1]) 250 ;; 251 esac 252 } 253 254 checkOS() { 255 case [$]1 in 256 linux|linux-android) 257 test -z "[$]2" || eval "[$]2=OSLinux" 258 ;; 259 darwin|ios|watchos|tvos) 260 test -z "[$]2" || eval "[$]2=OSDarwin" 261 ;; 262 solaris2) 263 test -z "[$]2" || eval "[$]2=OSSolaris2" 264 ;; 265 mingw32) 266 test -z "[$]2" || eval "[$]2=OSMinGW32" 267 ;; 268 freebsd) 269 test -z "[$]2" || eval "[$]2=OSFreeBSD" 270 ;; 271 dragonfly) 272 test -z "[$]2" || eval "[$]2=OSDragonFly" 273 ;; 274 kfreebsdgnu) 275 test -z "[$]2" || eval "[$]2=OSKFreeBSD" 276 ;; 277 openbsd) 278 test -z "[$]2" || eval "[$]2=OSOpenBSD" 279 ;; 280 netbsd) 281 test -z "[$]2" || eval "[$]2=OSNetBSD" 282 ;; 283 haiku) 284 test -z "[$]2" || eval "[$]2=OSHaiku" 285 ;; 286 nto-qnx) 287 test -z "[$]2" || eval "[$]2=OSQNXNTO" 288 ;; 289 dragonfly|hpux|linuxaout|freebsd2|nextstep2|nextstep3|sunos4|ultrix) 290 test -z "[$]2" || eval "[$]2=OSUnknown" 291 ;; 292 aix) 293 test -z "[$]2" || eval "[$]2=OSAIX" 294 ;; 295 gnu) 296 test -z "[$]2" || eval "[$]2=OSHurd" 297 ;; 298 *) 299 echo "Unknown OS '[$]1'" 300 exit 1 301 ;; 302 esac 303 } 304 305 dnl Note [autoconf assembler checks and -flto] 306 dnl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 307 dnl 308 dnl Autoconf's AC_COMPILE_IFELSE macro is fragile in the case of checks 309 dnl which require that the assembler is run. Specifically, GCC does not run 310 dnl the assembler if invoked with `-c -flto`; it merely dumps its internal 311 dnl AST to the object file, to be compiled and assembled during the final 312 dnl link. 313 dnl 314 dnl This can cause configure checks like that for the 315 dnl .subsections_via_symbols directive to pass unexpected (see #16440), 316 dnl leading the build system to incorrectly conclude that the directive is 317 dnl supported. 318 dnl 319 dnl For this reason, it is important that configure checks that rely on the 320 dnl assembler failing use AC_LINK_IFELSE rather than AC_COMPILE_IFELSE, 321 dnl ensuring that the assembler sees the check. 322 dnl 323 324 dnl ** check for Apple-style dead-stripping support 325 dnl (.subsections-via-symbols assembler directive) 326 327 AC_MSG_CHECKING(for .subsections_via_symbols) 328 dnl See Note [autoconf assembler checks and -flto] 329 AC_LINK_IFELSE( 330 [AC_LANG_PROGRAM([], [__asm__ (".subsections_via_symbols");])], 331 [AC_MSG_RESULT(yes) 332 if test x"$TargetArch" = xaarch64; then 333 dnl subsections via symbols is busted on arm64 (aarch64-darwin) 334 dnl see #19379 335 TargetHasSubsectionsViaSymbols=NO 336 else 337 TargetHasSubsectionsViaSymbols=YES 338 AC_DEFINE([HAVE_SUBSECTIONS_VIA_SYMBOLS],[1], 339 [Define to 1 if Apple-style dead-stripping is supported.]) 340 fi 341 ], 342 [TargetHasSubsectionsViaSymbols=NO 343 AC_MSG_RESULT(no)]) 344 345 dnl ** check for .ident assembler directive 346 347 AC_MSG_CHECKING(whether your assembler supports .ident directive) 348 dnl See Note [autoconf assembler checks and -flto] 349 AC_LINK_IFELSE( 350 [AC_LANG_PROGRAM([__asm__ (".ident \"GHC x.y.z\"");], [])], 351 [AC_MSG_RESULT(yes) 352 TargetHasIdentDirective=YES], 353 [AC_MSG_RESULT(no) 354 TargetHasIdentDirective=NO]) 355 356 dnl *** check for GNU non-executable stack note support (ELF only) 357 dnl (.section .note.GNU-stack,"",@progbits) 358 359 dnl This test doesn't work with "gcc -g" in gcc 4.4 (GHC trac #3889: 360 dnl Error: can't resolve `.note.GNU-stack' {.note.GNU-stack section} - `.Ltext0' {.text section} 361 dnl so we empty CFLAGS while running this test 362 CFLAGS2="$CFLAGS" 363 CFLAGS= 364 case $TargetArch in 365 arm) 366 dnl See #13937. 367 progbits="%progbits" 368 ;; 369 *) 370 progbits="@progbits" 371 ;; 372 esac 373 AC_MSG_CHECKING(for GNU non-executable stack support) 374 dnl See Note [autoconf assembler checks and -flto] 375 AC_LINK_IFELSE( 376 dnl the `main` function is placed after the .note.GNU-stack directive 377 dnl so we need to ensure that the active segment is correctly set, 378 dnl otherwise `main` will be placed in the wrong segment. 379 [AC_LANG_PROGRAM([ 380 __asm__ (".section .note.GNU-stack,\"\",$progbits"); 381 __asm__ (".section .text"); 382 ], [0])], 383 [AC_MSG_RESULT(yes) 384 TargetHasGnuNonexecStack=YES], 385 [AC_MSG_RESULT(no) 386 TargetHasGnuNonexecStack=NO]) 387 CFLAGS="$CFLAGS2" 388 389 checkArch "$BuildArch" "HaskellBuildArch" 390 checkVendor "$BuildVendor" 391 checkOS "$BuildOS" "" 392 393 checkArch "$HostArch" "HaskellHostArch" 394 checkVendor "$HostVendor" 395 checkOS "$HostOS" "HaskellHostOs" 396 397 checkArch "$TargetArch" "HaskellTargetArch" 398 checkVendor "$TargetVendor" 399 checkOS "$TargetOS" "HaskellTargetOs" 400 401 AC_SUBST(HaskellHostArch) 402 AC_SUBST(HaskellHostOs) 403 AC_SUBST(HaskellTargetArch) 404 AC_SUBST(HaskellTargetOs) 405 AC_SUBST(TargetHasSubsectionsViaSymbols) 406 AC_SUBST(TargetHasIdentDirective) 407 AC_SUBST(TargetHasGnuNonexecStack) 408]) 409 410 411# GET_ARM_ISA 412# ---------------------------------- 413# Get info about the ISA on the ARM arch 414AC_DEFUN([GET_ARM_ISA], 415[ 416 AC_COMPILE_IFELSE([ 417 AC_LANG_PROGRAM( 418 [], 419 [#if defined(__ARM_ARCH_2__) || \ 420 defined(__ARM_ARCH_3__) || \ 421 defined(__ARM_ARCH_3M__) || \ 422 defined(__ARM_ARCH_4__) || \ 423 defined(__ARM_ARCH_4T__) || \ 424 defined(__ARM_ARCH_5__) || \ 425 defined(__ARM_ARCH_5T__) || \ 426 defined(__ARM_ARCH_5E__) || \ 427 defined(__ARM_ARCH_5TE__) 428 return 0; 429 #else 430 not pre arm v6 431 #endif] 432 )], 433 [AC_DEFINE(arm_HOST_ARCH_PRE_ARMv6, 1, [ARM pre v6]) 434 AC_DEFINE(arm_HOST_ARCH_PRE_ARMv7, 1, [ARM pre v7]) 435 changequote(, )dnl 436 ARM_ISA=ARMv5 437 ARM_ISA_EXT="[]" 438 changequote([, ])dnl 439 ], 440 [ 441 AC_COMPILE_IFELSE([ 442 AC_LANG_PROGRAM( 443 [], 444 [#if defined(__ARM_ARCH_6__) || \ 445 defined(__ARM_ARCH_6J__) || \ 446 defined(__ARM_ARCH_6T2__) || \ 447 defined(__ARM_ARCH_6Z__) || \ 448 defined(__ARM_ARCH_6ZK__) || \ 449 defined(__ARM_ARCH_6K__) || \ 450 defined(__ARM_ARCH_6KZ__) || \ 451 defined(__ARM_ARCH_6M__) 452 return 0; 453 #else 454 not pre arm v7 455 #endif] 456 )], 457 [AC_DEFINE(arm_HOST_ARCH_PRE_ARMv7, 1, [ARM pre v7]) 458 ARM_ISA=ARMv6 459 AC_COMPILE_IFELSE([ 460 AC_LANG_PROGRAM( 461 [], 462 [#if defined(__VFP_FP__) 463 return 0; 464 #else 465 no vfp 466 #endif] 467 )], 468 [changequote(, )dnl 469 ARM_ISA_EXT="[VFPv2]" 470 changequote([, ])dnl 471 ], 472 [changequote(, )dnl 473 ARM_ISA_EXT="[]" 474 changequote([, ])dnl 475 ] 476 )], 477 [changequote(, )dnl 478 ARM_ISA=ARMv7 479 ARM_ISA_EXT="[VFPv3,NEON]" 480 changequote([, ])dnl 481 ]) 482 ]) 483 484 AC_COMPILE_IFELSE( 485 [AC_LANG_PROGRAM( 486 [], 487 [#if defined(__SOFTFP__) 488 return 0; 489 #else 490 not softfp 491 #endif] 492 )], 493 [changequote(, )dnl 494 ARM_ABI="SOFT" 495 changequote([, ])dnl 496 ], 497 [AC_COMPILE_IFELSE( 498 [AC_LANG_PROGRAM( 499 [], 500 [#if defined(__ARM_PCS_VFP) 501 return 0; 502 #else 503 no hard float ABI 504 #endif] 505 )], 506 [ARM_ABI="HARD"], 507 [ARM_ABI="SOFTFP"] 508 )] 509 ) 510 511 AC_SUBST(ARM_ISA) 512]) 513 514 515# FP_SETTINGS 516# ---------------------------------- 517# Set the variables used in the settings file 518# See Note [tooldir: How GHC finds mingw on Windows] 519AC_DEFUN([FP_SETTINGS], 520[ 521 if test "$windows" = YES -a "$EnableDistroToolchain" = "NO" 522 then 523 mingw_bin_prefix='$$tooldir/mingw/bin/' 524 SettingsCCompilerCommand="${mingw_bin_prefix}gcc.exe" 525 SettingsHaskellCPPCommand="${mingw_bin_prefix}gcc.exe" 526 SettingsHaskellCPPFlags="$HaskellCPPArgs" 527 SettingsLdCommand="${mingw_bin_prefix}ld.exe" 528 # Overrides FIND_MERGE_OBJECTS in order to avoid hard-coding linker 529 # path on Windows (#18550). 530 SettingsMergeObjectsCommand="${SettingsLdCommand}" 531 SettingsMergeObjectsFlags="-r --oformat=pe-bigobj-x86-64" 532 SettingsArCommand="${mingw_bin_prefix}ar.exe" 533 SettingsRanlibCommand="${mingw_bin_prefix}ranlib.exe" 534 SettingsDllWrapCommand="${mingw_bin_prefix}dllwrap.exe" 535 SettingsWindresCommand="${mingw_bin_prefix}windres.exe" 536 SettingsTouchCommand='$$topdir/bin/touchy.exe' 537 elif test "$EnableDistroToolchain" = "YES" 538 then 539 SettingsCCompilerCommand="$(basename $CC)" 540 SettingsCCompilerFlags="$CONF_CC_OPTS_STAGE2" 541 SettingsCxxCompilerFlags="$CONF_CXX_OPTS_STAGE2" 542 SettingsHaskellCPPCommand="$(basename $HaskellCPPCmd)" 543 SettingsHaskellCPPFlags="$HaskellCPPArgs" 544 SettingsLdCommand="$(basename $LdCmd)" 545 SettingsMergeObjectsCommand="$(basename $MergeObjsCmd)" 546 SettingsMergeObjectsFlags="$MergeObjsArgs" 547 SettingsArCommand="$(basename $ArCmd)" 548 SettingsDllWrapCommand="$(basename $DllWrapCmd)" 549 SettingsWindresCommand="$(basename $WindresCmd)" 550 SettingsTouchCommand='$$topdir/bin/touchy.exe' 551 else 552 SettingsCCompilerCommand="$CC" 553 SettingsHaskellCPPCommand="$HaskellCPPCmd" 554 SettingsHaskellCPPFlags="$HaskellCPPArgs" 555 SettingsLdCommand="$LdCmd" 556 SettingsMergeObjectsCommand="$MergeObjsCmd" 557 SettingsMergeObjectsFlags="$MergeObjsArgs" 558 SettingsArCommand="$ArCmd" 559 SettingsRanlibCommand="$RanlibCmd" 560 if test -z "$DllWrapCmd" 561 then 562 SettingsDllWrapCommand="/bin/false" 563 else 564 SettingsDllWrapCommand="$DllWrapCmd" 565 fi 566 if test -z "$WindresCmd" 567 then 568 SettingsWindresCommand="/bin/false" 569 else 570 SettingsWindresCommand="$WindresCmd" 571 fi 572 SettingsTouchCommand='touch' 573 fi 574 if test -z "$LibtoolCmd" 575 then 576 SettingsLibtoolCommand="libtool" 577 else 578 SettingsLibtoolCommand="$LibtoolCmd" 579 fi 580 if test -z "$ClangCmd" 581 then 582 SettingsClangCommand="clang" 583 else 584 SettingsClangCommand="$ClangCmd" 585 fi 586 if test -z "$LlcCmd" 587 then 588 SettingsLlcCommand="llc" 589 else 590 SettingsLlcCommand="$LlcCmd" 591 fi 592 if test -z "$OptCmd" 593 then 594 SettingsOptCommand="opt" 595 else 596 SettingsOptCommand="$OptCmd" 597 fi 598 if test -z "$OtoolCmd" 599 then 600 SettingsOtoolCommand="otool" 601 else 602 SettingsOtoolCommand="$OtoolCmd" 603 fi 604 if test -z "$InstallNameToolCmd" 605 then 606 SettingsInstallNameToolCommand="install_name_tool" 607 else 608 SettingsInstallNameToolCommand="$InstallNameToolCmd" 609 fi 610 SettingsCCompilerFlags="$CONF_CC_OPTS_STAGE2" 611 SettingsCxxCompilerFlags="$CONF_CXX_OPTS_STAGE2" 612 SettingsCCompilerLinkFlags="$CONF_GCC_LINKER_OPTS_STAGE2" 613 SettingsCCompilerSupportsNoPie="$CONF_GCC_SUPPORTS_NO_PIE" 614 SettingsLdFlags="$CONF_LD_LINKER_OPTS_STAGE2" 615 SettingsUseDistroMINGW="$EnableDistroToolchain" 616 AC_SUBST(SettingsCCompilerCommand) 617 AC_SUBST(SettingsHaskellCPPCommand) 618 AC_SUBST(SettingsHaskellCPPFlags) 619 AC_SUBST(SettingsCCompilerFlags) 620 AC_SUBST(SettingsCxxCompilerFlags) 621 AC_SUBST(SettingsCCompilerLinkFlags) 622 AC_SUBST(SettingsCCompilerSupportsNoPie) 623 AC_SUBST(SettingsLdCommand) 624 AC_SUBST(SettingsLdFlags) 625 AC_SUBST(SettingsMergeObjectsCommand) 626 AC_SUBST(SettingsMergeObjectsFlags) 627 AC_SUBST(SettingsArCommand) 628 AC_SUBST(SettingsRanlibCommand) 629 AC_SUBST(SettingsOtoolCommand) 630 AC_SUBST(SettingsInstallNameToolCommand) 631 AC_SUBST(SettingsDllWrapCommand) 632 AC_SUBST(SettingsWindresCommand) 633 AC_SUBST(SettingsLibtoolCommand) 634 AC_SUBST(SettingsTouchCommand) 635 AC_SUBST(SettingsClangCommand) 636 AC_SUBST(SettingsLlcCommand) 637 AC_SUBST(SettingsOptCommand) 638 AC_SUBST(SettingsUseDistroMINGW) 639]) 640 641# Helper for cloning a shell variable's state 642AC_DEFUN([FP_COPY_SHELLVAR], 643[if test -n "${$1+set}"; then $2="$$1"; else unset $2; fi ]) 644 645# FP_SET_CFLAGS_C99 646# ---------------------------------- 647# figure out which CFLAGS are needed to place the compiler into C99 mode 648# $1 is name of CC variable (unmodified) 649# $2 is name of CC flags variable (augmented if needed) 650# $3 is name of CPP flags variable (augmented if needed) 651AC_DEFUN([FP_SET_CFLAGS_C99], 652[ 653 dnl save current state of AC_PROG_CC_C99 654 FP_COPY_SHELLVAR([CC],[fp_save_CC]) 655 FP_COPY_SHELLVAR([CFLAGS],[fp_save_CFLAGS]) 656 FP_COPY_SHELLVAR([CPPFLAGS],[fp_save_CPPFLAGS]) 657 FP_COPY_SHELLVAR([ac_cv_prog_cc_c99],[fp_save_cc_c99]) 658 dnl set local state 659 CC="$$1" 660 CFLAGS="$$2" 661 CPPFLAGS="$$3" 662 unset ac_cv_prog_cc_c99 663 dnl perform detection 664 AC_PROG_CC_C99 665 fp_cc_c99="$ac_cv_prog_cc_c99" 666 case "x$ac_cv_prog_cc_c99" in 667 x) ;; # noop 668 xno) AC_MSG_ERROR([C99-compatible compiler needed]) ;; 669 *) $2="$$2 $ac_cv_prog_cc_c99" 670 $3="$$3 $ac_cv_prog_cc_c99" 671 ;; 672 esac 673 dnl restore saved state 674 FP_COPY_SHELLVAR([fp_save_CC],[CC]) 675 FP_COPY_SHELLVAR([fp_save_CFLAGS],[CFLAGS]) 676 FP_COPY_SHELLVAR([fp_save_CPPFLAGS],[CPPFLAGS]) 677 FP_COPY_SHELLVAR([fp_save_cc_c99],[ac_cv_prog_cc_c99]) 678 dnl cleanup 679 unset fp_save_CC 680 unset fp_save_CFLAGS 681 unset fp_save_cc_c99 682]) 683 684# FPTOOLS_SET_C_LD_FLAGS 685# ---------------------------------- 686# Set the C, LD and CPP flags for a given platform. 687# $1 is the platform 688# $2 is the name of the CC flags variable 689# $3 is the name of the linker flags variable when linking with gcc 690# $4 is the name of the linker flags variable when linking with ld 691# $5 is the name of the CPP flags variable 692AC_DEFUN([FPTOOLS_SET_C_LD_FLAGS], 693[ 694 AC_MSG_CHECKING([Setting up $2, $3, $4 and $5]) 695 case $$1 in 696 i386-*) 697 # Workaround for #7799 698 $2="$$2 -U__i686" 699 ;; 700 esac 701 702 case $$1 in 703 i386-unknown-mingw32) 704 $2="$$2 -march=i686" 705 ;; 706 i386-portbld-freebsd*) 707 $2="$$2 -march=i686" 708 ;; 709 x86_64-unknown-solaris2) 710 $2="$$2 -m64" 711 $3="$$3 -m64" 712 $4="$$4 -m64" 713 $5="$$5 -m64" 714 ;; 715 alpha-*) 716 # For now, to suppress the gcc warning "call-clobbered 717 # register used for global register variable", we simply 718 # disable all warnings altogether using the -w flag. Oh well. 719 $2="$$2 -w -mieee -D_REENTRANT" 720 $3="$$3 -w -mieee -D_REENTRANT" 721 $5="$$5 -w -mieee -D_REENTRANT" 722 ;; 723 hppa*) 724 # ___HPUX_SOURCE, not _HPUX_SOURCE, is #defined if -ansi! 725 # (very nice, but too bad the HP /usr/include files don't agree.) 726 $2="$$2 -D_HPUX_SOURCE" 727 $3="$$3 -D_HPUX_SOURCE" 728 $5="$$5 -D_HPUX_SOURCE" 729 ;; 730 731 arm*freebsd*) 732 # On arm/freebsd, tell gcc to generate Arm 733 # instructions (ie not Thumb). 734 $2="$$2 -marm" 735 $3="$$3 -Wl,-z,noexecstack" 736 $4="$$4 -z noexecstack" 737 ;; 738 arm*linux*) 739 # On arm/linux and arm/android, tell gcc to generate Arm 740 # instructions (ie not Thumb). 741 $2="$$2 -marm" 742 $3="$$3 -Wl,-z,noexecstack" 743 $4="$$4 -z noexecstack" 744 ;; 745 746 aarch64*freebsd*) 747 $3="$$3 -Wl,-z,noexecstack" 748 $4="$$4 -z noexecstack" 749 ;; 750 aarch64*linux*) 751 $3="$$3 -Wl,-z,noexecstack" 752 $4="$$4 -z noexecstack" 753 ;; 754 755 powerpc-ibm-aix*) 756 # We need `-D_THREAD_SAFE` to unlock the thread-local `errno`. 757 $2="$$2 -D_THREAD_SAFE" 758 $3="$$3 -D_THREAD_SAFE -Wl,-bnotextro" 759 $4="$$4 -bnotextro" 760 $5="$$5 -D_THREAD_SAFE" 761 ;; 762 763 x86_64-*-openbsd*) 764 # We need -z wxneeded at least to link ghc-stage2 to workaround 765 # W^X issue in GHCi on OpenBSD current (as of Aug 2016) 766 $3="$$3 -Wl,-z,wxneeded" 767 $4="$$4 -z wxneeded" 768 ;; 769 770 esac 771 772 AC_MSG_RESULT([done]) 773]) 774 775 776# FP_VISIBILITY_HIDDEN 777# ---------------------------------- 778# Is the visibility hidden attribute supported? 779AC_DEFUN([FP_VISIBILITY_HIDDEN], 780[ 781 AC_MSG_CHECKING([whether __attribute__((visibility("hidden"))) is supported]) 782 echo '__attribute__((visibility("hidden"))) void foo(void) {}' > conftest.c 783 if $CC -Wall -Werror -c conftest.c > /dev/null 2>&1 784 then 785 AC_MSG_RESULT([yes]) 786 AC_DEFINE(HAS_VISIBILITY_HIDDEN, 1, [Has visibility hidden]) 787 else 788 AC_MSG_RESULT([no]) 789 fi 790 rm -f conftest.c conftest.o 791]) 792 793 794# FPTOOLS_FLOAT_WORD_ORDER_BIGENDIAN 795# ---------------------------------- 796# Little endian ARM on Linux with some ABIs has big endian word order 797# in doubles. Define FLOAT_WORDS_BIGENDIAN if this is the case. 798AC_DEFUN([FPTOOLS_FLOAT_WORD_ORDER_BIGENDIAN], 799 [AC_CACHE_CHECK([whether float word order is big endian], [fptools_cv_float_word_order_bigendian], 800 [AC_COMPILE_IFELSE( 801 [AC_LANG_PROGRAM( 802 [#include <endian.h>], 803 [#if defined(__FLOAT_WORD_ORDER) && __FLOAT_WORD_ORDER == BIG_ENDIAN 804 return 0; 805 #else 806 not float word order big endian 807 #endif] 808 )], 809 [fptools_cv_float_word_order_bigendian=yes], 810 [fptools_cv_float_word_order_bigendian=no]) 811 ]) 812 case $fptools_cv_float_word_order_bigendian in 813 yes) 814 AC_DEFINE([FLOAT_WORDS_BIGENDIAN], 1, 815 [Define to 1 if your processor stores words of floats with 816 the most significant byte first]) ;; 817 esac 818]) 819 820 821# FP_PROG_CONTEXT_DIFF 822# -------------------- 823# Figure out how to do context diffs. Sets the output variable ContextDiffCmd. 824# 825# Note: NeXTStep thinks diff'ing a file against itself is "trouble". 826AC_DEFUN([FP_PROG_CONTEXT_DIFF], 827[AC_CACHE_CHECK([for a working context diff], [fp_cv_context_diff], 828[echo foo > conftest1 829echo foo > conftest2 830fp_cv_context_diff=no 831for fp_var in '-U 1' '-u1' '-C 1' '-c1' 832do 833 if diff $fp_var conftest1 conftest2 > /dev/null 2>&1; then 834 fp_cv_context_diff="diff $fp_var" 835 break 836 fi 837done]) 838if test x"$fp_cv_context_diff" = xno; then 839 AC_MSG_ERROR([cannot figure out how to do context diffs]) 840fi 841AC_SUBST(ContextDiffCmd, [$fp_cv_context_diff]) 842])# FP_PROG_CONTEXT_DIFF 843 844 845# FP_COMPUTE_INT(EXPRESSION, VARIABLE, INCLUDES, IF-FAILS) 846# -------------------------------------------------------- 847# Assign VARIABLE the value of the compile-time EXPRESSION using INCLUDES for 848# compilation. Execute IF-FAILS when unable to determine the value. Works for 849# cross-compilation, too. 850# 851# Implementation note: We are lazy and use an internal autoconf macro, but it 852# is supported in autoconf versions 2.50 up to the actual 2.57, so there is 853# little risk. 854AC_DEFUN([FP_COMPUTE_INT], 855[AC_COMPUTE_INT([$2], [$1], [$3], [$4])[]dnl 856])# FP_COMPUTE_INT 857 858 859# FP_CHECK_ALIGNMENT(TYPE, [IGNORED], [INCLUDES = DEFAULT-INCLUDES]) 860# ------------------------------------------------------------------ 861# A variation of AC_CHECK_SIZEOF for computing the alignment restrictions of a 862# given type. Defines ALIGNMENT_TYPE. 863AC_DEFUN([FP_CHECK_ALIGNMENT], 864[AS_LITERAL_IF(m4_translit([[$1]], [*], [p]), [], 865 [AC_FATAL([$0: requires literal arguments])])[]dnl 866AC_CHECK_TYPE([$1], [], [], [$3])[]dnl 867m4_pushdef([fp_Cache], [AS_TR_SH([fp_cv_alignment_$1])])[]dnl 868AC_CACHE_CHECK([alignment of $1], [fp_Cache], 869[if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then 870 FP_COMPUTE_INT([offsetof(struct { char c; $1 ty; },ty)], 871 [fp_Cache], 872 [AC_INCLUDES_DEFAULT([$3])], 873 [AC_MSG_ERROR([cannot compute alignment ($1) 874See `config.log' for more details.], [77])]) 875else 876 fp_Cache=0 877fi])[]dnl 878AC_DEFINE_UNQUOTED(AS_TR_CPP(alignment_$1), $fp_Cache, [The alignment of a `$1'.])[]dnl 879m4_popdef([fp_Cache])[]dnl 880])# FP_CHECK_ALIGNMENT 881 882 883 884# FP_CHECK_SIZEOF_AND_ALIGNMENT(TYPE) 885# ------------------------------------------------------------------ 886# Combines AC_CHECK_SIZEOF and FP_CHECK_ALIGNMENT. 887AC_DEFUN([FP_CHECK_SIZEOF_AND_ALIGNMENT], 888[AC_CHECK_SIZEOF([$1]) 889FP_CHECK_ALIGNMENT([$1]) 890])# FP_CHECK_SIZEOF_AND_ALIGNMENT 891 892# FP_DEFAULT_CHOICE_OVERRIDE_CHECK( 893# flag, name, anti name, var name, help string, 894# [var true val], [var false val], [flag true val]) 895# --------------------------------------------------- 896# Helper for when there is a automatic detection and an explicit flag for the 897# user to override disable a feature, but not override enable a feature. 898# 899# $1 = flag of feature 900# $2 = name of feature 901# $3 = name of anti feature 902# $4 = name of variable 903# $5 = help string 904# $6 = when true 905# $7 = when false 906# $8 = default explicit case (yes/no). Used for handle "backwards" legacy 907# options where enabling makes fewer assumptions than disabling. 908AC_DEFUN( 909 [FP_DEFAULT_CHOICE_OVERRIDE_CHECK], 910 [AC_ARG_ENABLE( 911 [$1], 912 [AS_HELP_STRING( 913 [--enable-$1], 914 [$5])], 915 [AS_IF( 916 [test x"$enableval" = x"m4_default([$8],yes)"], 917 [AS_CASE( 918 [x"$$4Default"], 919 [x"m4_default([$6],YES)"], 920 [AC_MSG_NOTICE([user chose $2 matching default for platform])], 921 [x"m4_default([$7],NO)"], 922 [AC_MSG_ERROR([user chose $2 overriding only supported option for platform])], 923 [AC_MSG_ERROR([invalid default])]) 924 $4=m4_default([$6],YES)], 925 [AS_CASE( 926 [x"$$4Default"], 927 [x"m4_default([$6],YES)"], 928 [AC_MSG_NOTICE([user chose $3 overriding for platform])], 929 [x"m4_default([$7],NO)"], 930 [AC_MSG_NOTICE([user chose $3 matching default for platform])], 931 [AC_MSG_ERROR([invalid default])]) 932 $4=m4_default([$7],NO)])], 933 [$4="$$4Default"])]) 934 935# FP_LEADING_UNDERSCORE 936# --------------------- 937# Test for determining whether symbol names have a leading underscore. We assume 938# that they _haven't_ if anything goes wrong. Sets the output variable 939# LeadingUnderscore to YES or NO and defines LEADING_UNDERSCORE correspondingly. 940# 941# Some nlist implementations seem to try to be compatible by ignoring a leading 942# underscore sometimes (eg. FreeBSD). We therefore have to work around this by 943# checking for *no* leading underscore first. Sigh. --SDM 944# 945# Similarly on OpenBSD, but this test doesn't help. -- dons 946# 947AC_DEFUN([FP_LEADING_UNDERSCORE], 948[AC_CHECK_LIB([elf], [nlist], [LIBS="-lelf $LIBS"]) 949AC_CACHE_CHECK([leading underscore in symbol names], [fptools_cv_leading_underscore], [ 950# Hack!: nlist() under Digital UNIX insist on there being an _, 951# but symbol table listings shows none. What is going on here?!? 952case $TargetPlatform in 953 # Apples mach-o platforms use leading underscores 954 *-apple-*) fptools_cv_leading_underscore=yes;; 955 *linux-android*) fptools_cv_leading_underscore=no;; 956 *openbsd*) # x86 openbsd is ELF from 3.4 >, meaning no leading uscore 957 case $build in 958 i386-*2\.@<:@0-9@:>@ | i386-*3\.@<:@0-3@:>@ ) fptools_cv_leading_underscore=yes ;; 959 *) fptools_cv_leading_underscore=no ;; 960 esac ;; 961 i386-unknown-mingw32) fptools_cv_leading_underscore=yes;; 962 x86_64-unknown-mingw32) fptools_cv_leading_underscore=no;; 963 *) AC_RUN_IFELSE([AC_LANG_SOURCE([[#if defined(HAVE_NLIST_H) 964#include <nlist.h> 965struct nlist xYzzY1[] = {{"xYzzY1", 0},{0}}; 966struct nlist xYzzY2[] = {{"_xYzzY2", 0},{0}}; 967#endif 968 969int main(argc, argv) 970int argc; 971char **argv; 972{ 973#if defined(HAVE_NLIST_H) 974 if(nlist(argv[0], xYzzY1) == 0 && xYzzY1[0].n_value != 0) 975 exit(1); 976 if(nlist(argv[0], xYzzY2) == 0 && xYzzY2[0].n_value != 0) 977 exit(0); 978#endif 979 exit(1); 980}]])],[fptools_cv_leading_underscore=yes],[fptools_cv_leading_underscore=no],[fptools_cv_leading_underscore=no]) 981;; 982esac]); 983AC_SUBST([LeadingUnderscore], [`echo $fptools_cv_leading_underscore | sed 'y/yesno/YESNO/'`]) 984if test x"$fptools_cv_leading_underscore" = xyes; then 985 AC_SUBST([CabalLeadingUnderscore],[True]) 986 AC_DEFINE([LEADING_UNDERSCORE], [1], [Define to 1 if C symbols have a leading underscore added by the compiler.]) 987else 988 AC_SUBST([CabalLeadingUnderscore],[False]) 989fi 990])# FP_LEADING_UNDERSCORE 991 992 993# FP_COMPARE_VERSIONS(VERSION1, TEST, VERSION2, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) 994# ---------------------------------------------------------------------------------- 995# Compare dotted version numbers VERSION1 and VERSION2 lexicographically according 996# to TEST (one of -eq, -ne, -lt, -le, -gt, or -ge). 997AC_DEFUN([FP_COMPARE_VERSIONS], 998[fp_version1=$1; fp_version2=$3 999fp_save_IFS=$IFS; IFS='.' 1000while test x"$fp_version1" != x || test x"$fp_version2" != x 1001do 1002 1003 set dummy $fp_version1; shift 1004 fp_num1="" 1005 test $[@%:@] = 0 || { fp_num1="[$]1"; shift; } 1006 test x"$fp_num1" = x && fp_num1="0" 1007 fp_version1="[$]*" 1008 1009 set dummy $fp_version2; shift 1010 fp_num2="" 1011 test $[@%:@] = 0 || { fp_num2="[$]1"; shift; } 1012 test x"$fp_num2" = x && fp_num2="0" 1013 fp_version2="[$]*" 1014 1015 test "$fp_num1" = "$fp_num2" || break; 1016done 1017IFS=$fp_save_IFS 1018AS_IF([test "$fp_num1" $2 "$fp_num2"], [$4], [$5])[]dnl 1019])# FP_COMPARE_VERSIONS 1020 1021 1022dnl 1023dnl Check for Happy and version: 1024dnl 1025dnl 1. Use happy specified in env var HAPPY 1026dnl 2. Find happy in path 1027dnl 3. Check happy version 1028dnl 1029dnl If you increase the minimum version requirement, please also update: 1030dnl https://gitlab.haskell.org/ghc/ghc/wikis/building/preparation/tools 1031dnl 1032AC_DEFUN([FPTOOLS_HAPPY], 1033[AC_PATH_PROG(HAPPY,[happy],) 1034AC_SUBST(HappyCmd,$HAPPY) 1035AC_CACHE_CHECK([for version of happy], fptools_cv_happy_version, 1036changequote(, )dnl 1037[ 1038if test x"$HappyCmd" != x; then 1039 fptools_cv_happy_version=`"$HappyCmd" -v | 1040 grep 'Happy Version' | sed -e 's/Happy Version \([^ ]*\).*/\1/g'` ; 1041else 1042 fptools_cv_happy_version=""; 1043fi; 1044changequote([, ])dnl 1045]) 1046if test ! -f compiler/parser/Parser.hs || test ! -f compiler/cmm/CmmParse.hs 1047then 1048 FP_COMPARE_VERSIONS([$fptools_cv_happy_version],[-lt],[1.19.10], 1049 [AC_MSG_ERROR([Happy version 1.19.10 or later is required to compile GHC.])])[] 1050 FP_COMPARE_VERSIONS([$fptools_cv_happy_version],[-ge],[1.20.0], 1051 [AC_MSG_ERROR([Happy version 1.19 is required to compile GHC.])])[] 1052fi 1053HappyVersion=$fptools_cv_happy_version; 1054AC_SUBST(HappyVersion) 1055]) 1056 1057dnl 1058dnl Check for Alex and version. 1059dnl 1060dnl 1. Use alex specified in env var ALEX 1061dnl 2. Find alex in path 1062dnl 3. Check alex version 1063dnl 1064dnl If you increase the minimum version requirement, please also update: 1065dnl https://gitlab.haskell.org/ghc/ghc/wikis/building/preparation/tools 1066dnl 1067AC_DEFUN([FPTOOLS_ALEX], 1068[AC_PATH_PROG(ALEX,[alex],) 1069AC_SUBST(AlexCmd,$ALEX) 1070AC_CACHE_CHECK([for version of alex], fptools_cv_alex_version, 1071changequote(, )dnl 1072[if test x"$AlexCmd" != x; then 1073 fptools_cv_alex_version=`"$AlexCmd" -v | 1074 grep 'Alex [Vv]ersion' | sed -e 's/Alex [Vv]ersion \([0-9\.]*\).*/\1/g'` ; 1075else 1076 fptools_cv_alex_version=""; 1077fi; 1078changequote([, ])dnl 1079]) 1080if test ! -f compiler/parser/Lexer.hs 1081then 1082 FP_COMPARE_VERSIONS([$fptools_cv_alex_version],[-lt],[3.1.7], 1083 [AC_MSG_ERROR([Alex version 3.1.7 or later is required to compile GHC.])])[] 1084fi 1085AlexVersion=$fptools_cv_alex_version; 1086AC_SUBST(AlexVersion) 1087]) 1088 1089 1090# FP_PROG_LD_FLAG 1091# --------------- 1092# Sets the output variable $2 to $1 if ld supports the $1 flag. 1093# Otherwise the variable's value is empty. 1094AC_DEFUN([FP_PROG_LD_FLAG], 1095[ 1096AC_CACHE_CHECK([whether ld understands $1], [fp_cv_$2], 1097[echo 'int foo() { return 0; }' > conftest.c 1098${CC-cc} -c conftest.c 1099if ${LdCmd} -r $1 -o conftest2.o conftest.o > /dev/null 2>&1; then 1100 fp_cv_$2=$1 1101else 1102 fp_cv_$2= 1103fi 1104rm -rf conftest*]) 1105$2=$fp_cv_$2 1106])# FP_PROG_LD_FLAG 1107 1108 1109# FP_PROG_LD_BUILD_ID 1110# ------------ 1111 1112# Sets the output variable LdHasBuildId to YES if ld supports 1113# --build-id, or NO otherwise. 1114AC_DEFUN([FP_PROG_LD_BUILD_ID], 1115[ 1116AC_CACHE_CHECK([whether ld understands --build-id], [fp_cv_ld_build_id], 1117[echo 'int foo() { return 0; }' > conftest.c 1118${CC-cc} -c conftest.c 1119if ${LdCmd} -r --build-id=none -o conftest2.o conftest.o > /dev/null 2>&1; then 1120 fp_cv_ld_build_id=yes 1121else 1122 fp_cv_ld_build_id=no 1123fi 1124rm -rf conftest*]) 1125if test "$fp_cv_ld_build_id" = yes; then 1126 LdHasBuildId=YES 1127else 1128 LdHasBuildId=NO 1129fi 1130AC_SUBST([LdHasBuildId]) 1131])# FP_PROG_LD_BUILD_ID 1132 1133 1134# FP_PROG_LD_IS_GNU 1135# ----------------- 1136# Sets the output variable LdIsGNULd to YES or NO, depending on whether it is 1137# GNU ld or not. 1138AC_DEFUN([FP_PROG_LD_IS_GNU],[ 1139AC_CACHE_CHECK([whether ld is GNU ld], [fp_cv_gnu_ld], 1140[[if ${LdCmd} --version 2> /dev/null | grep "GNU" > /dev/null 2>&1; then 1141 fp_cv_gnu_ld=YES 1142else 1143 fp_cv_gnu_ld=NO 1144fi]]) 1145AC_SUBST([LdIsGNULd],["$fp_cv_gnu_ld"]) 1146])# FP_PROG_LD_IS_GNU 1147 1148 1149# FP_PROG_LD_NO_COMPACT_UNWIND 1150# ---------------------------- 1151 1152# Sets the output variable LdHasNoCompactUnwind to YES if ld supports 1153# -no_compact_unwind, or NO otherwise. 1154AC_DEFUN([FP_PROG_LD_NO_COMPACT_UNWIND], 1155[ 1156AC_CACHE_CHECK([whether ld understands -no_compact_unwind], [fp_cv_ld_no_compact_unwind], 1157[echo 'int foo() { return 0; }' > conftest.c 1158${CC-cc} -c conftest.c 1159if ${LdCmd} -r -no_compact_unwind -o conftest2.o conftest.o > /dev/null 2>&1; then 1160 fp_cv_ld_no_compact_unwind=yes 1161else 1162 fp_cv_ld_no_compact_unwind=no 1163fi 1164rm -rf conftest*]) 1165if test "$fp_cv_ld_no_compact_unwind" = yes; then 1166 LdHasNoCompactUnwind=YES 1167else 1168 LdHasNoCompactUnwind=NO 1169fi 1170AC_SUBST([LdHasNoCompactUnwind]) 1171])# FP_PROG_LD_NO_COMPACT_UNWIND 1172 1173 1174# FP_PROG_LD_FILELIST 1175# ------------------- 1176 1177# Sets the output variable LdHasFilelist to YES if ld supports 1178# -filelist, or NO otherwise. 1179AC_DEFUN([FP_PROG_LD_FILELIST], 1180[ 1181AC_CACHE_CHECK([whether ld understands -filelist], [fp_cv_ld_has_filelist], 1182[ 1183 echo 'int foo() { return 0; }' > conftest1.c 1184 echo 'int bar() { return 0; }' > conftest2.c 1185 ${CC-cc} -c conftest1.c 1186 ${CC-cc} -c conftest2.c 1187 echo conftest1.o > conftest.o-files 1188 echo conftest2.o >> conftest.o-files 1189 if ${LdCmd} -r -filelist conftest.o-files -o conftest.o > /dev/null 2>&1 1190 then 1191 fp_cv_ld_has_filelist=yes 1192 else 1193 fp_cv_ld_has_filelist=no 1194 fi 1195 rm -rf conftest* 1196]) 1197if test "$fp_cv_ld_has_filelist" = yes; then 1198 LdHasFilelist=YES 1199else 1200 LdHasFilelist=NO 1201fi 1202AC_SUBST([LdHasFilelist]) 1203])# FP_PROG_LD_FILELIST 1204 1205 1206# FP_PROG_AR 1207# ---------- 1208# Sets fp_prog_ar to a path to ar. Exits if no ar can be found 1209# The host normalization on Windows breaks autoconf, it no longer 1210# thinks that target == host so it never checks the unqualified 1211# tools for Windows. See #14274. 1212AC_DEFUN([FP_PROG_AR], 1213[if test -z "$fp_prog_ar"; then 1214 if test "$HostOS" = "mingw32" 1215 then 1216 AC_PATH_PROG([fp_prog_ar], [ar]) 1217 if test -n "$fp_prog_ar"; then 1218 fp_prog_ar=$(cygpath -m $fp_prog_ar) 1219 fi 1220 else 1221 AC_CHECK_TARGET_TOOL([fp_prog_ar], [ar]) 1222 fi 1223fi 1224if test -z "$fp_prog_ar"; then 1225 AC_MSG_ERROR([cannot find ar in your PATH, no idea how to make a library]) 1226fi 1227])# FP_PROG_AR 1228 1229 1230# FP_PROG_AR_IS_GNU 1231# ----------------- 1232# Sets fp_prog_ar_is_gnu to yes or no, depending on whether it is GNU ar or not. 1233AC_DEFUN([FP_PROG_AR_IS_GNU], 1234[AC_REQUIRE([FP_PROG_AR]) 1235AC_CACHE_CHECK([whether $fp_prog_ar is GNU ar], [fp_cv_prog_ar_is_gnu], 1236[if "$fp_prog_ar" --version 2> /dev/null | grep "GNU" > /dev/null 2>&1; then 1237 fp_cv_prog_ar_is_gnu=yes 1238else 1239 fp_cv_prog_ar_is_gnu=no 1240fi]) 1241fp_prog_ar_is_gnu=$fp_cv_prog_ar_is_gnu 1242AC_SUBST([ArIsGNUAr], [`echo $fp_prog_ar_is_gnu | tr 'a-z' 'A-Z'`]) 1243])# FP_PROG_AR_IS_GNU 1244 1245 1246# FP_PROG_AR_SUPPORTS_ATFILE 1247# ----------------- 1248# Sets fp_prog_ar_supports_atfile to yes or no, depending on whether 1249# or not it supports the @file syntax 1250AC_DEFUN([FP_PROG_AR_SUPPORTS_ATFILE], 1251[AC_REQUIRE([FP_PROG_AR]) 1252 AC_REQUIRE([FP_PROG_AR_ARGS]) 1253AC_CACHE_CHECK([whether $fp_prog_ar supports @file], [fp_cv_prog_ar_supports_atfile], 1254[ 1255rm -f conftest* 1256touch conftest.file 1257echo conftest.file > conftest.atfile 1258echo conftest.file >> conftest.atfile 1259"$fp_prog_ar" $fp_prog_ar_args conftest.a @conftest.atfile > /dev/null 2>&1 1260fp_prog_ar_supports_atfile_tmp=`"$fp_prog_ar" t conftest.a 2> /dev/null | grep -c conftest.file` 1261rm -f conftest* 1262if test "$fp_prog_ar_supports_atfile_tmp" -eq 2 1263then 1264 fp_cv_prog_ar_supports_atfile=yes 1265else 1266 fp_cv_prog_ar_supports_atfile=no 1267fi]) 1268fp_prog_ar_supports_atfile=$fp_cv_prog_ar_supports_atfile 1269AC_SUBST([ArSupportsAtFile], [`echo $fp_prog_ar_supports_atfile | tr 'a-z' 'A-Z'`]) 1270])# FP_PROG_AR_SUPPORTS_ATFILE 1271 1272# FP_PROG_AR_ARGS 1273# --------------- 1274# Sets fp_prog_ar_args to the arguments for ar and the output variable ArCmd 1275# to an invocation of ar including these arguments. 1276AC_DEFUN([FP_PROG_AR_ARGS], 1277[AC_REQUIRE([FP_PROG_AR_IS_GNU]) 1278AC_CACHE_CHECK([for ar arguments], [fp_cv_prog_ar_args], 1279[ 1280# GNU ar needs special treatment: it appears to have problems with 1281# object files with the same name if you use the 's' modifier, but 1282# simple 'ar q' works fine, and doesn't need a separate ranlib. 1283if test $fp_prog_ar_is_gnu = yes; then 1284 fp_cv_prog_ar_args="q" 1285else 1286 touch conftest.dummy 1287 for fp_var in qclsZ qcls qcs qcl qc ; do 1288 rm -f conftest.a 1289 if "$fp_prog_ar" $fp_var conftest.a conftest.dummy > /dev/null 2> /dev/null ; then 1290 # Also check that a result was created; it seems some llvm-ar versions 1291 # exit with code zero even if they fail to parse the command line. 1292 if test -f conftest.a ; then 1293 fp_cv_prog_ar_args=$fp_var 1294 break 1295 fi 1296 fi 1297 done 1298 rm -f conftest* 1299 if test -z "$fp_cv_prog_ar_args"; then 1300 AC_MSG_ERROR([cannot figure out how to use your $fp_prog_ar]) 1301 fi 1302fi]) 1303fp_prog_ar_args=$fp_cv_prog_ar_args 1304AC_SUBST([ArCmd], ["$fp_prog_ar"]) 1305AC_SUBST([ArArgs], ["$fp_prog_ar_args"]) 1306 1307])# FP_PROG_AR_ARGS 1308 1309 1310# FP_PROG_AR_NEEDS_RANLIB 1311# ----------------------- 1312# Sets the output variable RANLIB_CMD to "ranlib" if it is needed and 1313# found, to "true" otherwise. Sets REAL_RANLIB_CMD to the ranlib program, 1314# even if we don't need ranlib (libffi might still need it). 1315AC_DEFUN([FP_PROG_AR_NEEDS_RANLIB],[ 1316 AC_REQUIRE([FP_PROG_AR_IS_GNU]) 1317 AC_REQUIRE([FP_PROG_AR_ARGS]) 1318 AC_REQUIRE([AC_PROG_CC]) 1319 1320 AC_PROG_RANLIB 1321 1322 if test $fp_prog_ar_is_gnu = yes 1323 then 1324 fp_cv_prog_ar_needs_ranlib=no 1325 elif test "$TargetVendor_CPP" = "apple" 1326 then 1327 # It's quite tedious to check for Apple's crazy timestamps in 1328 # .a files, so we hardcode it. 1329 fp_cv_prog_ar_needs_ranlib=yes 1330 else 1331 case $fp_prog_ar_args in 1332 *s*) 1333 fp_cv_prog_ar_needs_ranlib=no;; 1334 *) 1335 fp_cv_prog_ar_needs_ranlib=yes;; 1336 esac 1337 fi 1338 1339 # workaround for AC_PROG_RANLIB which sets RANLIB to `:' when 1340 # ranlib is missing on the target OS. The problem is that 1341 # ghc-cabal cannot execute `:' which is a shell built-in but can 1342 # execute `true' which is usually simple program supported by the 1343 # OS. 1344 # Fixes #8795 1345 if test "$RANLIB" = ":" 1346 then 1347 RANLIB="true" 1348 fi 1349 REAL_RANLIB_CMD="$RANLIB" 1350 if test $fp_cv_prog_ar_needs_ranlib = yes 1351 then 1352 RANLIB_CMD="$RANLIB" 1353 else 1354 RANLIB_CMD="true" 1355 fi 1356 AC_SUBST([REAL_RANLIB_CMD]) 1357 AC_SUBST([RANLIB_CMD]) 1358])# FP_PROG_AR_NEEDS_RANLIB 1359 1360 1361# FP_GCC_VERSION 1362# ----------- 1363# Extra testing of the result AC_PROG_CC, testing the gcc version no. Sets the 1364# (unsubstituted) output variable GccVersion. 1365AC_DEFUN([FP_GCC_VERSION], [ 1366 AC_REQUIRE([AC_PROG_CC]) 1367 if test -z "$CC"; then 1368 AC_MSG_ERROR([C compiler is required]) 1369 fi 1370 1371 if $CC --version | grep --quiet gcc; then 1372 AC_CACHE_CHECK([version of gcc], [fp_cv_gcc_version], 1373 [ 1374 # Be sure only to look at the first occurrence of the "version " string; 1375 # Some Apple compilers emit multiple messages containing this string. 1376 AC_MSG_CHECKING([version of gcc]) 1377 fp_cv_gcc_version="`$CC -v 2>&1 | sed -n -e '1,/version /s/.*version [[^0-9]]*\([[0-9.]]*\).*/\1/p'`" 1378 AC_MSG_RESULT([$fp_cv_gcc_version]) 1379 FP_COMPARE_VERSIONS([$fp_cv_gcc_version], [-lt], [4.6], 1380 [AC_MSG_ERROR([Need at least gcc version 4.6 (4.7+ recommended)])]) 1381 ]) 1382 AC_SUBST([GccVersion], [$fp_cv_gcc_version]) 1383 else 1384 AC_MSG_NOTICE([\$CC is not gcc; assuming it's a reasonably new C compiler]) 1385 fi 1386])# FP_GCC_VERSION 1387 1388dnl Check to see if the C compiler is clang or llvm-gcc 1389dnl 1390AC_DEFUN([FP_CC_LLVM_BACKEND], 1391 [AC_REQUIRE([AC_PROG_CC]) 1392 AC_MSG_CHECKING([whether C compiler has an LLVM back end]) 1393 $CC -x c /dev/null -dM -E > conftest.txt 2>&1 1394 if grep "__llvm__" conftest.txt >/dev/null 2>&1; then 1395 AC_DEFINE([CC_LLVM_BACKEND], [1], [Define (to 1) if C compiler has an LLVM back end]) 1396 CcLlvmBackend=YES 1397 AC_MSG_RESULT([yes]) 1398 else 1399 CcLlvmBackend=NO 1400 AC_MSG_RESULT([no]) 1401 fi 1402 AC_SUBST(CcLlvmBackend) 1403 1404 rm -f conftest.txt 1405]) 1406 1407# FP_GCC_SUPPORTS__ATOMICS 1408# ------------------------ 1409# Does gcc support the __atomic_* family of builtins? 1410AC_DEFUN([FP_GCC_SUPPORTS__ATOMICS], 1411[ 1412 AC_REQUIRE([AC_PROG_CC]) 1413 AC_MSG_CHECKING([whether GCC supports __atomic_ builtins]) 1414 echo 'int test(int *x) { int y; __atomic_load(x, &y, __ATOMIC_SEQ_CST); return y; }' > conftest.c 1415 if $CC -c conftest.c > /dev/null 2>&1; then 1416 CONF_GCC_SUPPORTS__ATOMICS=YES 1417 AC_MSG_RESULT([yes]) 1418 else 1419 CONF_GCC_SUPPORTS__ATOMICS=NO 1420 AC_MSG_RESULT([no]) 1421 fi 1422 rm -f conftest.c conftest.o 1423]) 1424 1425# FP_GCC_SUPPORTS_NO_PIE 1426# ---------------------- 1427# Does gcc support the -no-pie option? If so we should pass it to gcc when 1428# joining objects since -pie may be enabled by default. 1429AC_DEFUN([FP_GCC_SUPPORTS_NO_PIE], 1430[ 1431 AC_REQUIRE([AC_PROG_CC]) 1432 AC_MSG_CHECKING([whether GCC supports -no-pie]) 1433 echo 'int main() { return 0; }' > conftest.c 1434 # Some GCC versions only warn when passed an unrecognized flag. 1435 if $CC -no-pie -Werror -x c /dev/null -dM -E > conftest.txt 2>&1 && ! grep -i unrecognized conftest.txt > /dev/null 2>&1; then 1436 CONF_GCC_SUPPORTS_NO_PIE=YES 1437 AC_MSG_RESULT([yes]) 1438 else 1439 CONF_GCC_SUPPORTS_NO_PIE=NO 1440 AC_MSG_RESULT([no]) 1441 fi 1442 rm -f conftest.c conftest.o conftest 1443]) 1444 1445 1446# FP_CHECK_PROG(VARIABLE, PROG-TO-CHECK-FOR, 1447# [VALUE-IF-NOT-FOUND], [PATH], [REJECT]) 1448# ----------------------------------------------------- 1449# HACK: A small wrapper around AC_CHECK_PROG, setting VARIABLE to the full path 1450# of PROG-TO-CHECK-FOR when found. 1451AC_DEFUN([FP_CHECK_PROG], 1452[AC_CHECK_PROG([$1], [$2], [$as_dir/$ac_word$ac_exec_ext], [$3], [$4], [$5])][]dnl 1453)# FP_CHECK_PROC 1454 1455 1456# FP_PROG_FIND 1457# ------------ 1458# Find a non-WinDoze version of the "find" utility. 1459AC_DEFUN([FP_PROG_FIND], 1460[AC_PATH_PROGS([fp_prog_find], [gfind find], find) 1461echo foo > conftest.txt 1462$fp_prog_find conftest.txt -print > conftest.out 2>&1 1463if grep '^conftest.txt$' conftest.out > /dev/null 2>&1 ; then 1464 # OK, looks like a real "find". 1465 FindCmd="$fp_prog_find" 1466else 1467 # Found a poor WinDoze version of "find", ignore it. 1468 AC_MSG_WARN([$fp_prog_find looks like a non-*nix find, ignoring it]) 1469 FP_CHECK_PROG([FindCmd], [find], [], [], [$fp_prog_find]) 1470fi 1471rm -f conftest.txt conftest.out 1472AC_SUBST([FindCmd])[]dnl 1473])# FP_PROG_FIND 1474 1475 1476# FP_PROG_SORT 1477# ------------ 1478# Find a Unix-like sort 1479AC_DEFUN([FP_PROG_SORT], 1480[AC_PATH_PROG([fp_prog_sort], [sort]) 1481echo conwip > conftest.txt 1482$fp_prog_sort -f conftest.txt > conftest.out 2>&1 1483if grep 'conwip' conftest.out > /dev/null 2>&1 ; then 1484 # The goods 1485 SortCmd="$fp_prog_sort" 1486else 1487 # Summink else..pick next one. 1488 AC_MSG_WARN([$fp_prog_sort looks like a non-*nix sort, ignoring it]) 1489 FP_CHECK_PROG([SortCmd], [sort], [], [], [$fp_prog_sort]) 1490fi 1491rm -f conftest.txt conftest.out 1492AC_SUBST([SortCmd])[]dnl 1493])# FP_PROG_SORT 1494 1495 1496dnl 1497dnl FPTOOLS_NOCACHE_CHECK prints a message, then sets the 1498dnl values of the second argument to the result of running 1499dnl the commands given by the third. It does not cache its 1500dnl result, so it is suitable for checks which should be 1501dnl run every time. 1502dnl 1503AC_DEFUN([FPTOOLS_NOCACHE_CHECK], 1504[AC_MSG_CHECKING([$1]) 1505 $3 1506 AC_MSG_RESULT([$][$2]) 1507]) 1508 1509dnl 1510dnl FPTOOLS_GHC_VERSION(version) 1511dnl FPTOOLS_GHC_VERSION(major, minor [, patchlevel]) 1512dnl FPTOOLS_GHC_VERSION(version, major, minor, patchlevel) 1513dnl 1514dnl Test for version of installed ghc. Uses $GHC. 1515dnl [original version pinched from c2hs] 1516dnl 1517AC_DEFUN([FPTOOLS_GHC_VERSION], 1518[FPTOOLS_NOCACHE_CHECK([version of ghc], [fptools_version_of_ghc], 1519["${WithGhc-ghc}" --version > conftestghc 2>&1 1520 cat conftestghc >&AS_MESSAGE_LOG_FD 1521#Useless Use Of cat award... 1522 fptools_version_of_ghc=`cat conftestghc | sed -n -e 's/, patchlevel *\([[0-9]]\)/.\1/;s/.* version \([[0-9]][[0-9.]]*\).*/\1/p'` 1523 rm -fr conftest* 1524 if test "[$]fptools_version_of_ghc" = "" 1525 then 1526 fptools_version_of_ghc='unknown' 1527 fi 1528fptools_version_of_ghc[_major]=`echo [$]fptools_version_of_ghc | sed -e 's/^\([[0-9]]\).*/\1/'` 1529fptools_version_of_ghc[_minor]=`echo [$]fptools_version_of_ghc | sed -e 's/^[[0-9]]\.\([[0-9]]*\).*/\1/'` 1530fptools_version_of_ghc[_pl]=`echo [$]fptools_version_of_ghc | sed -n -e 's/^[[0-9]]\.[[0-9]]*\.\([[0-9]]*\)/\1/p'` 1531# 1532if test "[$]fptools_version_of_ghc[_pl]" = "" 1533then 1534 fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor]" 1535 fptools_version_of_ghc[_pl]="0" 1536else 1537 fptools_version_of_ghc[_all]="[$]fptools_version_of_ghc[_major].[$]fptools_version_of_ghc[_minor].[$]fptools_version_of_ghc[_pl]" 1538fi 1539# 1540ifelse($#, [1], [dnl 1541[$1]="[$]fptools_version_of_ghc[_all]" 1542], $#, [2], [dnl 1543[$1]="[$]fptools_version_of_ghc[_major]" 1544[$2]="[$]fptools_version_of_ghc[_minor]" 1545], $#, [3], [dnl 1546[$1]="[$]fptools_version_of_ghc[_major]" 1547[$2]="[$]fptools_version_of_ghc[_minor]" 1548[$3]="[$]fptools_version_of_ghc[_pl]" 1549], $#, [4], [dnl 1550[$1]="[$]fptools_version_of_ghc[_all]" 1551[$2]="[$]fptools_version_of_ghc[_major]" 1552[$3]="[$]fptools_version_of_ghc[_minor]" 1553[$4]="[$]fptools_version_of_ghc[_pl]" 1554]) 1555]) 1556])dnl 1557 1558 1559# FP_CHECK_FUNC(FUNCTION, PROLOGUE, BODY, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) 1560# --------------------------------------------------------------------------------- 1561# A variant of AC_CHECK_FUNCS, limited to a single FUNCTION, but with the 1562# additional flexibility of specifying the PROLOGUE and BODY. 1563AC_DEFUN([FP_CHECK_FUNC], 1564[AS_VAR_PUSHDEF([fp_func], [fp_cv_func_$1])dnl 1565AC_CACHE_CHECK([for $1], fp_func, 1566[AC_LINK_IFELSE([AC_LANG_PROGRAM([$2], [$3])], 1567 [AS_VAR_SET(fp_func, yes)], 1568 [AS_VAR_SET(fp_func, no)])]) 1569AS_IF([test AS_VAR_GET(fp_func) = yes], 1570 [AC_DEFINE(AS_TR_CPP(HAVE_$1), [1], 1571 [Define to 1 if you have the `]$1[' function.]) $4], 1572 [$5])dnl 1573AS_VAR_POPDEF([fp_func])dnl 1574])# FP_CHECK_FUNC 1575 1576# FP_PROG_GHC_PKG 1577# ---------------- 1578# Try to find a ghc-pkg matching the ghc mentioned in the environment variable 1579# WithGhc. Sets the output variable GhcPkgCmd. 1580AC_DEFUN([FP_PROG_GHC_PKG], 1581[AC_CACHE_CHECK([for ghc-pkg matching $WithGhc], fp_cv_matching_ghc_pkg, 1582[ 1583# If we are told to use ghc-stage2, then we're using an in-tree 1584# compiler. In this case, we just want ghc-pkg, not ghc-pkg-stage2, 1585# so we sed off -stage[0-9]$. However, if we are told to use 1586# ghc-6.12.1 then we want to use ghc-pkg-6.12.1, so we keep any 1587# other suffix. 1588fp_ghc_pkg_guess=`echo "$WithGhc" | sed -e 's/-stage@<:@0-9@:>@$//' -e 's,ghc\(@<:@^/\\@:>@*\)$,ghc-pkg\1,'` 1589if "$fp_ghc_pkg_guess" list > /dev/null 2>&1; then 1590 fp_cv_matching_ghc_pkg=$fp_ghc_pkg_guess 1591else 1592 AC_MSG_ERROR([Cannot find matching ghc-pkg]) 1593fi]) 1594GhcPkgCmd=$fp_cv_matching_ghc_pkg 1595AC_SUBST([GhcPkgCmd]) 1596])# FP_PROG_GHC_PKG 1597 1598 1599# FP_GCC_EXTRA_FLAGS 1600# ------------------ 1601# Determine which extra flags we need to pass gcc when we invoke it 1602# to compile .hc code. 1603# 1604# -fwrapv is needed for gcc to emit well-behaved code in the presence of 1605# integer wrap around. (#952) 1606# 1607AC_DEFUN([FP_GCC_EXTRA_FLAGS], 1608[AC_REQUIRE([FP_GCC_VERSION]) 1609AC_CACHE_CHECK([for extra options to pass gcc when compiling via C], [fp_cv_gcc_extra_opts], 1610[ 1611 if test "$Unregisterised" = "YES"; then 1612 # These used to be conditioned on gcc version but we no longer support 1613 # GCC versions which lack support for these flags 1614 fp_cv_gcc_extra_opts="-fwrapv -fno-builtin" 1615 fi 1616]) 1617AC_SUBST([GccExtraViaCOpts],$fp_cv_gcc_extra_opts) 1618]) 1619 1620 1621# FP_SETUP_PROJECT_VERSION 1622# --------------------- 1623AC_DEFUN([FP_SETUP_PROJECT_VERSION], 1624[ 1625if test "$RELEASE" = "NO"; then 1626 AC_MSG_CHECKING([for GHC version date]) 1627 if test -f VERSION_DATE; then 1628 PACKAGE_VERSION=${PACKAGE_VERSION}.`cat VERSION_DATE` 1629 AC_MSG_RESULT(given $PACKAGE_VERSION) 1630 elif test -e .git; then 1631 changequote(, )dnl 1632 ver_posixtime=`git log -1 --pretty=format:%ct` 1633 ver_date=`perl -MPOSIX -e "print strftime('%Y%m%d', gmtime($ver_posixtime));"` 1634 if echo $ver_date | grep '^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$' 2>&1 >/dev/null; then true; else 1635 changequote([, ])dnl 1636 AC_MSG_ERROR([failed to detect version date: check that git and perl are in your path]) 1637 fi 1638 PACKAGE_VERSION=${PACKAGE_VERSION}.$ver_date 1639 AC_MSG_RESULT(inferred $PACKAGE_VERSION) 1640 elif test -f VERSION; then 1641 PACKAGE_VERSION=`cat VERSION` 1642 AC_MSG_RESULT(given $PACKAGE_VERSION) 1643 else 1644 AC_MSG_WARN([cannot determine snapshot version: no .git directory and no VERSION file]) 1645 dnl We'd really rather this case didn't happen, but it might 1646 dnl do (in particular, people using lndir trees may find that 1647 dnl the build system can't find any other date). If it does 1648 dnl happen, then we use the current date. 1649 dnl This way we get some idea about how recent a build is. 1650 dnl It also means that packages built for 2 different builds 1651 dnl will probably use different version numbers, so things are 1652 dnl less likely to go wrong. 1653 PACKAGE_VERSION=${PACKAGE_VERSION}.`date +%Y%m%d` 1654 fi 1655fi 1656 1657 AC_MSG_CHECKING([for GHC Git commit id]) 1658 if test -e .git; then 1659 git_commit_id=`git rev-parse HEAD` 1660 if test -n "$git_commit_id" 2>&1 >/dev/null; then true; else 1661 AC_MSG_ERROR([failed to detect revision: check that git is in your path]) 1662 fi 1663 PACKAGE_GIT_COMMIT_ID=$git_commit_id 1664 AC_MSG_RESULT(inferred $PACKAGE_GIT_COMMIT_ID) 1665 elif test -f GIT_COMMIT_ID; then 1666 PACKAGE_GIT_COMMIT_ID=`cat GIT_COMMIT_ID` 1667 AC_MSG_RESULT(given $PACKAGE_GIT_COMMIT_ID) 1668 else 1669 AC_MSG_WARN([cannot determine snapshot revision: no .git directory and no 'GIT_COMMIT_ID' file]) 1670 PACKAGE_GIT_COMMIT_ID="0000000000000000000000000000000000000000" 1671 fi 1672 1673 1674# Some renamings 1675AC_SUBST([ProjectName], [$PACKAGE_NAME]) 1676AC_SUBST([ProjectVersion], [$PACKAGE_VERSION]) 1677AC_SUBST([ProjectGitCommitId], [$PACKAGE_GIT_COMMIT_ID]) 1678 1679# Split PACKAGE_VERSION into (possibly empty) parts 1680VERSION_MAJOR=`echo $PACKAGE_VERSION | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\1'/` 1681VERSION_TMP=`echo $PACKAGE_VERSION | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\3'/` 1682VERSION_MINOR=`echo $VERSION_TMP | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\1'/` 1683ProjectPatchLevel=`echo $VERSION_TMP | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\3'/` 1684 1685# Calculate project version as an integer, using 2 digits for minor version 1686case $VERSION_MINOR in 1687 ?) ProjectVersionInt=${VERSION_MAJOR}0${VERSION_MINOR} ;; 1688 ??) ProjectVersionInt=${VERSION_MAJOR}${VERSION_MINOR} ;; 1689 *) AC_MSG_ERROR([bad minor version in $PACKAGE_VERSION]) ;; 1690esac 1691AC_SUBST([ProjectVersionInt]) 1692 1693# The project patchlevel is zero unless stated otherwise 1694test -z "$ProjectPatchLevel" && ProjectPatchLevel=0 1695 1696# Save split version of ProjectPatchLevel 1697ProjectPatchLevel1=`echo $ProjectPatchLevel | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\1/'` 1698ProjectPatchLevel2=`echo $ProjectPatchLevel | sed 's/^\(@<:@^.@:>@*\)\(\.\{0,1\}\(.*\)\)$/\3/'` 1699 1700AC_SUBST([ProjectPatchLevel1]) 1701AC_SUBST([ProjectPatchLevel2]) 1702 1703# Remove dots from the patch level; this allows us to have versions like 6.4.1.20050508 1704ProjectPatchLevel=`echo $ProjectPatchLevel | sed 's/\.//'` 1705 1706AC_SUBST([ProjectPatchLevel]) 1707 1708# The version of the GHC package changes every day, since the 1709# patchlevel is the current date. We don't want to force 1710# recompilation of the entire compiler when this happens, so for 1711# GHC HEAD we omit the patchlevel from the package version number. 1712# 1713# The ProjectPatchLevel1 > 20000000 iff GHC HEAD. If it's for a stable 1714# release like 7.10.1 or for a release candidate such as 7.10.1.20141224 1715# then we don't omit the patchlevel components. 1716 1717ProjectVersionMunged="$ProjectVersion" 1718if test "$ProjectPatchLevel1" -gt 20000000; then 1719 ProjectVersionMunged="${VERSION_MAJOR}.${VERSION_MINOR}" 1720fi 1721AC_SUBST([ProjectVersionMunged]) 1722])# FP_SETUP_PROJECT_VERSION 1723 1724# Check for a working timer_create(). We need a pretty detailed check 1725# here, because there exist partially-working implementations of 1726# timer_create() in certain versions of Linux (see bug #1933). 1727# 1728AC_DEFUN([FP_CHECK_TIMER_CREATE],[ 1729AC_CHECK_FUNC([timer_create],[HAVE_timer_create=yes],[HAVE_timer_create=no]) 1730 1731if test "$HAVE_timer_create" = "yes" 1732then 1733 if test "$cross_compiling" = "yes" 1734 then 1735 # We can't test timer_create when we're cross-compiling, so we 1736 # optimistiaclly assume that it actually works properly. 1737 AC_DEFINE([USE_TIMER_CREATE], 1, [Define to 1 if we can use timer_create(CLOCK_REALTIME,...)]) 1738 else 1739 AC_CACHE_CHECK([for a working timer_create(CLOCK_REALTIME)], 1740 [fptools_cv_timer_create_works], 1741 [AC_TRY_RUN([ 1742#include <stdio.h> 1743#if defined(HAVE_STDLIB_H) 1744#include <stdlib.h> 1745#endif 1746#if defined(HAVE_TIME_H) 1747#include <time.h> 1748#endif 1749#if defined(HAVE_SIGNAL_H) 1750#include <signal.h> 1751#endif 1752#if defined(HAVE_UNISTD_H) 1753#include <unistd.h> 1754#endif 1755 1756static volatile int tock = 0; 1757static void handler(int i) 1758{ 1759 tock = 1; 1760} 1761 1762static void timeout(int i) 1763{ 1764 // timer_settime() has been known to hang, so just in case 1765 // we install a 1-second timeout (see #2257) 1766 exit(99); 1767} 1768 1769int main(int argc, char *argv[]) 1770{ 1771 1772 struct sigevent ev; 1773 timer_t timer; 1774 struct itimerspec it; 1775 struct sigaction action; 1776 int m,n,count = 0; 1777 1778 ev.sigev_notify = SIGEV_SIGNAL; 1779 ev.sigev_signo = SIGVTALRM; 1780 1781 action.sa_handler = handler; 1782 action.sa_flags = 0; 1783 sigemptyset(&action.sa_mask); 1784 if (sigaction(SIGVTALRM, &action, NULL) == -1) { 1785 fprintf(stderr,"SIGVTALRM problem\n"); 1786 exit(3); 1787 } 1788 1789 action.sa_handler = timeout; 1790 action.sa_flags = 0; 1791 sigemptyset(&action.sa_mask); 1792 if (sigaction(SIGALRM, &action, NULL) == -1) { 1793 fprintf(stderr,"SIGALRM problem\n"); 1794 exit(3); 1795 } 1796 alarm(1); 1797 1798 if (timer_create(CLOCK_REALTIME, &ev, &timer) != 0) { 1799 fprintf(stderr,"No CLOCK_REALTIME timer\n"); 1800 exit(2); 1801 } 1802 1803 tock = 0; 1804 1805 it.it_value.tv_sec = 0; 1806 it.it_value.tv_nsec = 1000000; // 1ms 1807 it.it_interval = it.it_value; 1808 if (timer_settime(timer, 0, &it, NULL) != 0) { 1809 fprintf(stderr,"settime problem\n"); 1810 exit(4); 1811 } 1812 1813 // some environments have coarse scheduler/timer granularity of ~10ms and worse 1814 usleep(100000); // 100ms 1815 1816 if (!tock) { 1817 fprintf(stderr,"no CLOCK_REALTIME signal\n"); 1818 exit(5); 1819 } 1820 1821 timer_delete(timer); 1822 1823 exit(0); 1824} 1825 ], 1826 [fptools_cv_timer_create_works=yes], 1827 [fptools_cv_timer_create_works=no]) 1828 ]) 1829case $fptools_cv_timer_create_works in 1830 yes) AC_DEFINE([USE_TIMER_CREATE], 1, 1831 [Define to 1 if we can use timer_create(CLOCK_REALTIME,...)]);; 1832esac 1833 fi 1834fi 1835]) 1836 1837# FP_ICONV 1838# ------------- 1839AC_DEFUN([FP_ICONV], 1840[ 1841 dnl-------------------------------------------------------------------- 1842 dnl * Deal with arguments telling us iconv is somewhere odd 1843 dnl-------------------------------------------------------------------- 1844 1845 dnl Note: ICONV_LIB_DIRS and ICONV_INCLUDE_DIRS are not predefined 1846 dnl to the empty string to allow them to be overridden from the 1847 dnl environment. 1848 1849 AC_ARG_WITH([iconv-includes], 1850 [AS_HELP_STRING([--with-iconv-includes], 1851 [directory containing iconv.h])], 1852 [ICONV_INCLUDE_DIRS=$withval]) 1853 1854 AC_ARG_WITH([iconv-libraries], 1855 [AS_HELP_STRING([--with-iconv-libraries], 1856 [directory containing iconv library])], 1857 [ICONV_LIB_DIRS=$withval]) 1858 1859 AC_SUBST(ICONV_INCLUDE_DIRS) 1860 AC_SUBST(ICONV_LIB_DIRS) 1861])# FP_ICONV 1862 1863# FP_GMP 1864# ------------- 1865AC_DEFUN([FP_GMP], 1866[ 1867 dnl-------------------------------------------------------------------- 1868 dnl * Deal with arguments telling us gmp is somewhere odd 1869 dnl-------------------------------------------------------------------- 1870 1871 AC_ARG_WITH([gmp-includes], 1872 [AS_HELP_STRING([--with-gmp-includes], 1873 [directory containing gmp.h])], 1874 [GMP_INCLUDE_DIRS=$withval]) 1875 1876 AC_ARG_WITH([gmp-libraries], 1877 [AS_HELP_STRING([--with-gmp-libraries], 1878 [directory containing gmp library])], 1879 [GMP_LIB_DIRS=$withval]) 1880 1881 AC_ARG_WITH([intree-gmp], 1882 [AS_HELP_STRING([--with-intree-gmp], 1883 [force using the in-tree GMP])], 1884 [GMP_FORCE_INTREE=YES], 1885 [GMP_FORCE_INTREE=NO]) 1886 1887 AC_ARG_WITH([gmp-framework-preferred], 1888 [AS_HELP_STRING([--with-gmp-framework-preferred], 1889 [on OSX, prefer the GMP framework to the gmp lib])], 1890 [GMP_PREFER_FRAMEWORK=YES], 1891 [GMP_PREFER_FRAMEWORK=NO]) 1892 1893 AC_SUBST(GMP_INCLUDE_DIRS) 1894 AC_SUBST(GMP_LIB_DIRS) 1895 AC_SUBST(GMP_FORCE_INTREE) 1896 AC_SUBST(GMP_PREFER_FRAMEWORK) 1897])# FP_GMP 1898 1899# FP_CURSES 1900# ------------- 1901AC_DEFUN([FP_CURSES], 1902[ 1903 dnl-------------------------------------------------------------------- 1904 dnl * Deal with arguments telling us curses is somewhere odd 1905 dnl-------------------------------------------------------------------- 1906 1907 AC_ARG_WITH([curses-libraries], 1908 [AS_HELP_STRING([--with-curses-libraries], 1909 [directory containing curses libraries])], 1910 [CURSES_LIB_DIRS=$withval]) 1911 1912 AC_SUBST(CURSES_INCLUDE_DIRS) 1913 AC_SUBST(CURSES_LIB_DIRS) 1914 1915 AC_ARG_WITH([curses-libraries-stage0], 1916 [AC_HELP_STRING([--with-curses-libraries-stage0], 1917 [directory containing build-platform curses libraries (for stage0 build)])], 1918 [CURSES_LIB_DIRS_STAGE0=$withval], 1919 [CURSES_LIB_DIRS_STAGE0=$CURSES_LIB_DIRS]) 1920 1921 AC_SUBST(CURSES_LIB_DIRS_STAGE0) 1922 1923])# FP_CURSES 1924 1925# -------------------------------------------------------------- 1926# Calculate absolute path to build tree 1927# -------------------------------------------------------------- 1928 1929AC_DEFUN([FP_FIND_ROOT],[ 1930AC_MSG_CHECKING(for path to top of build tree) 1931 if test "$windows" = YES 1932 then 1933 dnl Make sure this is a c:/foo/bar (mixed) style path. Some parts of 1934 dnl the build system might depend on it (such as the sed expression 1935 dnl `"s|$(TOP)/||i"` in addCFileDeps in rules/build-dependencies.mk). 1936 hardtop=$(cygpath -m "$(pwd)") 1937 else 1938 hardtop=$(pwd) 1939 fi 1940 1941 dnl Remove common automounter nonsense 1942 hardtop=`echo $hardtop | sed 's|^/tmp_mnt.*\(/local/.*\)$|\1|' | sed 's|^/tmp_mnt/|/|'` 1943 1944 if ! test -d "$hardtop"; then 1945 AC_MSG_ERROR([cannot determine current directory]) 1946 fi 1947 1948 dnl We don't support building in directories with spaces. 1949 case "$hardtop" in 1950 *' '*) 1951 AC_MSG_ERROR([ 1952 The build system does not support building in a directory 1953 containing space characters. 1954 Suggestion: move the build tree somewhere else.]) 1955 ;; 1956 esac 1957 1958 AC_SUBST(hardtop) 1959 1960 AC_MSG_RESULT($hardtop) 1961]) 1962 1963# GHC_CONVERT_CPU(cpu, target_var) 1964# -------------------------------- 1965# converts cpu from gnu to ghc naming, and assigns the result to $target_var 1966AC_DEFUN([GHC_CONVERT_CPU],[ 1967case "$1" in 1968 aarch64*|arm64*) 1969 $2="aarch64" 1970 ;; 1971 alpha*) 1972 $2="alpha" 1973 ;; 1974 arm*) 1975 $2="arm" 1976 ;; 1977 hppa1.1*) 1978 $2="hppa1_1" 1979 ;; 1980 hppa*) 1981 $2="hppa" 1982 ;; 1983 i386|i486|i586|i686) 1984 $2="i386" 1985 ;; 1986 ia64) 1987 $2="ia64" 1988 ;; 1989 m68k*) 1990 $2="m68k" 1991 ;; 1992 mipseb*) 1993 $2="mipseb" 1994 ;; 1995 mipsel*) 1996 $2="mipsel" 1997 ;; 1998 mips*) 1999 $2="mips" 2000 ;; 2001 nios2) 2002 $2="nios2" 2003 ;; 2004 powerpc64le*) 2005 $2="powerpc64le" 2006 ;; 2007 powerpc64*) 2008 $2="powerpc64" 2009 ;; 2010 powerpc*) 2011 $2="powerpc" 2012 ;; 2013 riscv64*) 2014 $2="riscv64" 2015 ;; 2016 riscv|riscv32*) 2017 $2="riscv32" 2018 ;; 2019 rs6000) 2020 $2="rs6000" 2021 ;; 2022 s390x*) 2023 $2="s390x" 2024 ;; 2025 s390*) 2026 $2="s390" 2027 ;; 2028 sh4) 2029 $2="sh4" 2030 ;; 2031 sparc64*) 2032 $2="sparc64" 2033 ;; 2034 sparc*) 2035 $2="sparc" 2036 ;; 2037 vax) 2038 $2="vax" 2039 ;; 2040 x86_64|amd64) 2041 $2="x86_64" 2042 ;; 2043 *) 2044 echo "Unknown CPU $1" 2045 exit 1 2046 ;; 2047 esac 2048]) 2049 2050# GHC_LLVM_TARGET(target, target_cpu, target_vendor, target_os, llvm_target_var) 2051# -------------------------------- 2052# converts the canonicalized target into someting llvm can understand 2053AC_DEFUN([GHC_LLVM_TARGET], [ 2054 llvm_target_cpu=$2 2055 case "$1" in 2056 *-freebsd*-gnueabihf) 2057 llvm_target_vendor="unknown" 2058 llvm_target_os="freebsd-gnueabihf" 2059 ;; 2060 *-hardfloat-*eabi) 2061 llvm_target_vendor="unknown" 2062 llvm_target_os="$4""hf" 2063 ;; 2064 *-mingw32|*-mingw64|*-msys) 2065 llvm_target_vendor="unknown" 2066 llvm_target_os="windows" 2067 ;; 2068 # apple is a bit about their naming scheme for 2069 # aarch64; and clang on macOS doesn't know that 2070 # aarch64 would be arm64. So for LLVM we'll need 2071 # to call it arm64; while we'll refer to it internally 2072 # as aarch64 for consistency and sanity. 2073 aarch64-apple-*|arm64-apple-*) 2074 llvm_target_cpu="arm64" 2075 GHC_CONVERT_VENDOR([$3],[llvm_target_vendor]) 2076 GHC_CONVERT_OS([$4],[$2],[llvm_target_os]) 2077 ;; 2078 *) 2079 GHC_CONVERT_VENDOR([$3],[llvm_target_vendor]) 2080 GHC_CONVERT_OS([$4],[$2],[llvm_target_os]) 2081 ;; 2082 esac 2083 case "$4" in 2084 # retain any android and gnueabi linux flavours 2085 # for the LLVM Target. Otherwise these would be 2086 # turned into just `-linux` and fail to be found 2087 # in the `llvm-targets` file. 2088 *-android*|*-gnueabi*|*-musleabi*) 2089 GHC_CONVERT_VENDOR([$3],[llvm_target_vendor]) 2090 llvm_target_os="$4" 2091 ;; 2092 esac 2093 $5="$llvm_target_cpu-$llvm_target_vendor-$llvm_target_os" 2094]) 2095 2096 2097# GHC_CONVERT_VENDOR(vendor, target_var) 2098# -------------------------------- 2099# converts vendor from gnu to ghc naming, and assigns the result to $target_var 2100AC_DEFUN([GHC_CONVERT_VENDOR],[ 2101 case "$1" in 2102 pc|gentoo|w64) # like i686-pc-linux-gnu, i686-gentoo-freebsd8, x86_64-w64-mingw32 2103 $2="unknown" 2104 ;; 2105 softfloat) # like armv5tel-softfloat-linux-gnueabi 2106 $2="unknown" 2107 ;; 2108 hardfloat) # like armv7a-hardfloat-linux-gnueabi 2109 $2="unknown" 2110 ;; 2111 *) 2112 #pass thru by default 2113 $2="$1" 2114 ;; 2115 esac 2116]) 2117 2118# GHC_CONVERT_OS(os, converted_cpu, target_var) 2119# -------------------------------- 2120# converts os from gnu to ghc naming, and assigns the result to $target_var 2121AC_DEFUN([GHC_CONVERT_OS],[ 2122 case "$1" in 2123 gnu*) # e.g. i686-unknown-gnu0.9 2124 $3="gnu" 2125 ;; 2126 # watchos and tvos are ios variants as of May 2017. 2127 ios|watchos|tvos) 2128 $3="ios" 2129 ;; 2130 linux-android*) 2131 $3="linux-android" 2132 ;; 2133 linux-*|linux) 2134 $3="linux" 2135 ;; 2136 openbsd*) 2137 $3="openbsd" 2138 ;; 2139 # As far as I'm aware, none of these have relevant variants 2140 freebsd|netbsd|dragonfly|hpux|linuxaout|kfreebsdgnu|freebsd2|mingw32|darwin|nextstep2|nextstep3|sunos4|ultrix|haiku) 2141 $3="$1" 2142 ;; 2143 msys) 2144 AC_MSG_ERROR([Building GHC using the msys toolchain is not supported; please use mingw instead. Perhaps you need to set 'MSYSTEM=MINGW64 or MINGW32?']) 2145 ;; 2146 aix*) # e.g. powerpc-ibm-aix7.1.3.0 2147 $3="aix" 2148 ;; 2149 darwin*) # e.g. aarch64-apple-darwin14 2150 $3="darwin" 2151 ;; 2152 solaris2*) 2153 $3="solaris2" 2154 ;; 2155 freebsd*) # like i686-gentoo-freebsd7 2156 # i686-gentoo-freebsd8 2157 # i686-gentoo-freebsd8.2 2158 $3="freebsd" 2159 ;; 2160 nto-qnx*) 2161 $3="nto-qnx" 2162 ;; 2163 *) 2164 echo "Unknown OS $1" 2165 exit 1 2166 ;; 2167 esac 2168]) 2169 2170# BOOTSTRAPPING_GHC_INFO_FIELD 2171# -------------------------------- 2172# Set the variable $1 to the value of the ghc --info field $2. 2173AC_DEFUN([BOOTSTRAPPING_GHC_INFO_FIELD],[ 2174$1=`"$WithGhc" --info | grep "^ ,(\"$2\"," | sed -e 's/.*","//' -e 's/")$//'` 2175tmp=${$1#\$topdir/} 2176if test "${$1}" != "$tmp" 2177then 2178 topdir=`"$WithGhc" --print-libdir | sed 's#\\\\#/#g'` 2179 $1="$topdir/$tmp" 2180fi 2181AC_SUBST($1) 2182]) 2183 2184# LIBRARY_VERSION(lib, [cabal_file]) 2185# -------------------------------- 2186# Gets the version number of a library. 2187# If $1 is ghc-prim, then we define LIBRARY_ghc_prim_VERSION as 1.2.3 2188# $2 points to the directory under libraries/ 2189AC_DEFUN([LIBRARY_VERSION],[ 2190cabal_file=m4_default([$2],[$1/$1.cabal]) 2191LIBRARY_[]translit([$1], [-], [_])[]_VERSION=`grep -i "^version:" libraries/${cabal_file} | sed "s/.* //"` 2192AC_SUBST(LIBRARY_[]translit([$1], [-], [_])[]_VERSION) 2193]) 2194 2195# XCODE_VERSION() 2196# -------------------------------- 2197# Gets the version number of Xcode, if on a Mac 2198AC_DEFUN([XCODE_VERSION],[ 2199 if test "$TargetVendor_CPP" = "apple" 2200 then 2201 AC_MSG_CHECKING(Xcode version) 2202 XcodeVersion=`(xcode-select -p >& /dev/null && xcodebuild -version) | grep Xcode | sed "s/Xcode //"` 2203 # Old Xcode versions don't actually give the Xcode version 2204 if test "$XcodeVersion" = "" 2205 then 2206 AC_MSG_RESULT(not found (too old?)) 2207 XcodeVersion1=0 2208 XcodeVersion2=0 2209 else 2210 AC_MSG_RESULT($XcodeVersion) 2211 XcodeVersion1=`echo "$XcodeVersion" | sed 's/\..*//'` 2212 changequote(, )dnl 2213 XcodeVersion2=`echo "$XcodeVersion" | sed 's/[^.]*\.\([^.]*\).*/\1/'` 2214 changequote([, ])dnl 2215 AC_MSG_NOTICE(Xcode version component 1: $XcodeVersion1) 2216 AC_MSG_NOTICE(Xcode version component 2: $XcodeVersion2) 2217 fi 2218 fi 2219]) 2220 2221# FIND_LLVM_PROG() 2222# -------------------------------- 2223# Find where the llvm tools are. We have a special function to handle when they 2224# are installed with a version suffix (e.g., llc-7, llc-7.0, llc70) and without (e.g. 2225# llc). 2226# 2227# $1 = the variable to set 2228# $2 = the command to look for 2229# $3 = the lower bound version of the command to look for 2230# $4 = the upper bound version of the command to look for. 2231# 2232AC_DEFUN([FIND_LLVM_PROG],[ 2233 # Test for program with and without version name. 2234 PROG_VERSION_CANDIDATES=$(for llvmVersion in `seq $4 -1 $3`; do echo "$2-$llvmVersion $2-$llvmVersion.0 $2$llvmVersion $2$llvmVersion0"; done) 2235 AC_CHECK_TOOLS([$1], [$PROG_VERSION_CANDIDATES $2], []) 2236 AS_IF([test x"$$1" != x],[ 2237 PROG_VERSION=`$$1 --version | awk '/.*version [[0-9\.]]+/{for(i=1;i<=NF;i++){ if(\$i ~ /^[[0-9\.]]+$/){print \$i}}}'` 2238 AS_IF([test x"$PROG_VERSION" == x], 2239 [AC_MSG_RESULT(no) 2240 $1="" 2241 AC_MSG_NOTICE([We only support llvm $3 to $4 (no version found).])], 2242 [AC_MSG_CHECKING([$$1 version ($PROG_VERSION) is between $3 and $4]) 2243 AX_COMPARE_VERSION([$PROG_VERSION], [lt], [$3], 2244 [AC_MSG_RESULT(no) 2245 $1="" 2246 AC_MSG_NOTICE([We only support llvm $3 to $4 (found $PROG_VERSION).])], 2247 [AX_COMPARE_VERSION([$PROG_VERSION], [ge], [$4], 2248 [AC_MSG_RESULT(no) 2249 $1="" 2250 AC_MSG_NOTICE([We only support llvm $3 to $4 (found $PROG_VERSION).])], 2251 [AC_MSG_RESULT(yes)])])])]) 2252]) 2253 2254# CHECK_LD_COPY_BUG() 2255# ------------------- 2256# Check for binutils bug #16177 present in some versions of the bfd ld 2257# implementation affecting ARM relocations. 2258# https://sourceware.org/bugzilla/show_bug.cgi?id=16177 2259# 2260# $1 = the platform 2261# 2262AC_DEFUN([CHECK_LD_COPY_BUG],[ 2263 case $1 in 2264 arm*linux*) 2265 AC_CHECK_TARGET_TOOL([READELF], [readelf]) 2266 AC_CHECK_TARGET_TOOL([AS], [as]) 2267 AC_MSG_CHECKING([for ld bug 16177]) 2268 cat >actest.s <<-EOF 2269 .globl _start 2270 .p2align 4 2271 _start: 2272 bkpt 2273 2274 .data 2275 .globl data_object 2276 object_reference: 2277 .long data_object 2278 .size object_reference, 4 2279EOF 2280 2281 cat >aclib.s <<-EOF 2282 .data 2283 .globl data_object 2284 .type data_object, %object 2285 .size data_object, 4 2286 data_object: 2287 .long 123 2288EOF 2289 2290 $AS -o aclib.o aclib.s 2291 $LD -shared -o aclib.so aclib.o 2292 2293 $AS -o actest.o actest.s 2294 $LD -o actest actest.o aclib.so 2295 2296 if $READELF -r actest | grep R_ARM_COPY > /dev/null; then 2297 AC_MSG_RESULT([affected]) 2298 AC_MSG_ERROR( 2299 [Your linker is affected by binutils #16177, which 2300 critically breaks linkage of GHC objects. Please either upgrade 2301 binutils or supply a different linker with the LD environment 2302 variable.]) 2303 else 2304 AC_MSG_RESULT([unaffected]) 2305 fi 2306 2307 rm -f aclib.s aclib.o aclib.so actest.s actest.o actest 2308 ;; 2309 *) 2310 ;; 2311 esac 2312]) 2313 2314# FIND_GHC_BOOTSTRAP_PROG() 2315# -------------------------------- 2316# Parse the bootstrap GHC's compier settings file for the location of things 2317# like the `llc` and `opt` commands. 2318# 2319# $1 = the variable to set 2320# $2 = The bootstrap compiler. 2321# $3 = The string to grep for to find the correct line. 2322# 2323AC_DEFUN([FIND_GHC_BOOTSTRAP_PROG],[ 2324 BootstrapTmpCmd=`grep $3 $($2 --print-libdir)/settings 2>/dev/null | sed 's/.*", "//;s/".*//'` 2325 if test -n "$BootstrapTmpCmd" && test `basename $BootstrapTmpCmd` = $BootstrapTmpCmd ; then 2326 AC_PATH_PROG([$1], [$BootstrapTmpCmd], "") 2327 else 2328 $1=$BootstrapTmpCmd 2329 fi 2330]) 2331 2332 2333AC_DEFUN([MAYBE_OVERRIDE_STAGE0],[ 2334 if test ! -z "$With_$1" -a "$CrossCompiling" != "YES"; then 2335 AC_MSG_NOTICE([Not cross-compiling, so --with-$1 also sets $2]) 2336 $2=$With_$1 2337 fi 2338]) 2339 2340 2341# FP_CPP_CMD_WITH_ARGS() 2342# ---------------------- 2343# sets CPP command and its arguments 2344# 2345# $1 = the variable to set to CPP command 2346# $2 = the variable to set to CPP command arguments 2347 2348AC_DEFUN([FP_CPP_CMD_WITH_ARGS],[ 2349dnl ** what cpp to use? 2350dnl -------------------------------------------------------------- 2351AC_ARG_WITH(hs-cpp, 2352[AS_HELP_STRING([--with-hs-cpp=ARG], 2353 [Path to the (C) preprocessor for Haskell files [default=autodetect]])], 2354[ 2355 if test "$HostOS" = "mingw32" 2356 then 2357 AC_MSG_WARN([Request to use $withval will be ignored]) 2358 else 2359 HS_CPP_CMD=$withval 2360 fi 2361], 2362[ 2363 2364 # We can't use $CPP here, since HS_CPP_CMD is expected to be a single 2365 # command (no flags), and AC_PROG_CPP defines CPP as "/usr/bin/gcc -E". 2366 HS_CPP_CMD=$CC 2367 2368 SOLARIS_GCC_CPP_BROKEN=NO 2369 SOLARIS_FOUND_GOOD_CPP=NO 2370 case $host in 2371 i386-*-solaris2) 2372 GCC_MAJOR_MINOR=`$CC --version|grep "gcc (GCC)"|cut -d ' ' -f 3-3|cut -d '.' -f 1-2` 2373 if test "$GCC_MAJOR_MINOR" != "3.4"; then 2374 # this is not 3.4.x release so with broken CPP 2375 SOLARIS_GCC_CPP_BROKEN=YES 2376 fi 2377 ;; 2378 esac 2379 2380 if test "$SOLARIS_GCC_CPP_BROKEN" = "YES"; then 2381 # let's try to find if GNU C 3.4.x is installed 2382 if test -x /usr/sfw/bin/gcc; then 2383 # something executable is in expected path so let's 2384 # see if it's really GNU C 2385 NEW_GCC_MAJOR_MINOR=`/usr/sfw/bin/gcc --version|grep "gcc (GCC)"|cut -d ' ' -f 3-3|cut -d '.' -f 1-2` 2386 if test "$NEW_GCC_MAJOR_MINOR" = "3.4"; then 2387 # this is GNU C 3.4.x which provides non-broken CPP on Solaris 2388 # let's use it as CPP then. 2389 HS_CPP_CMD=/usr/sfw/bin/gcc 2390 SOLARIS_FOUND_GOOD_CPP=YES 2391 fi 2392 fi 2393 if test "$SOLARIS_FOUND_GOOD_CPP" = "NO"; then 2394 AC_MSG_WARN([Your GNU C provides broken CPP and you do not have GNU C 3.4.x installed.]) 2395 AC_MSG_WARN([Please install GNU C 3.4.x to solve this issue. It will be used as CPP only.]) 2396 fi 2397 fi 2398] 2399) 2400 2401 2402 2403dnl ** what cpp flags to use? 2404dnl ----------------------------------------------------------- 2405AC_ARG_WITH(hs-cpp-flags, 2406 [AS_HELP_STRING([--with-hs-cpp-flags=ARG], 2407 [Flags to the (C) preprocessor for Haskell files [default=autodetect]])], 2408 [ 2409 if test "$HostOS" = "mingw32" 2410 then 2411 AC_MSG_WARN([Request to use $withval will be ignored]) 2412 else 2413 HS_CPP_ARGS=$withval 2414 fi 2415 ], 2416[ 2417 $HS_CPP_CMD -x c /dev/null -dM -E > conftest.txt 2>&1 2418 if grep "__clang__" conftest.txt >/dev/null 2>&1; then 2419 HS_CPP_ARGS="-E -undef -traditional -Wno-invalid-pp-token -Wno-unicode -Wno-trigraphs" 2420 else 2421 $HS_CPP_CMD -v > conftest.txt 2>&1 2422 if grep "gcc" conftest.txt >/dev/null 2>&1; then 2423 HS_CPP_ARGS="-E -undef -traditional" 2424 else 2425 $HS_CPP_CMD --version > conftest.txt 2>&1 2426 if grep "cpphs" conftest.txt >/dev/null 2>&1; then 2427 HS_CPP_ARGS="--cpp -traditional" 2428 else 2429 AC_MSG_WARN([configure can't recognize your CPP program, you may need to set --with-hs-cpp-flags=FLAGS explicitly]) 2430 HS_CPP_ARGS="" 2431 fi 2432 fi 2433 fi 2434 ] 2435) 2436 2437$1=$HS_CPP_CMD 2438$2=$HS_CPP_ARGS 2439 2440]) 2441 2442# FP_BFD_SUPPORT() 2443# ---------------------- 2444# whether to use libbfd for debugging RTS 2445AC_DEFUN([FP_BFD_SUPPORT], [ 2446 AC_SUBST([CabalHaveLibbfd], [False]) 2447 AC_ARG_ENABLE(bfd-debug, 2448 [AS_HELP_STRING([--enable-bfd-debug], 2449 [Enable symbol resolution for -debug rts ('+RTS -Di') via binutils' libbfd [default=no]])], 2450 [ 2451 # don't pollute general LIBS environment 2452 save_LIBS="$LIBS" 2453 AC_CHECK_HEADERS([bfd.h]) 2454 dnl ** check whether this machine has BFD and libiberty installed (used for debugging) 2455 dnl the order of these tests matters: bfd needs libiberty 2456 AC_CHECK_LIB(iberty, xmalloc) 2457 dnl 'bfd_init' is a rare non-macro in libbfd 2458 AC_CHECK_LIB(bfd, bfd_init) 2459 2460 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <bfd.h>]], 2461 [[ 2462 /* mimic our rts/Printer.c */ 2463 bfd* abfd; 2464 const char * name; 2465 char **matching; 2466 2467 name = "some.executable"; 2468 bfd_init(); 2469 abfd = bfd_openr(name, "default"); 2470 bfd_check_format_matches (abfd, bfd_object, &matching); 2471 { 2472 long storage_needed; 2473 storage_needed = bfd_get_symtab_upper_bound (abfd); 2474 } 2475 { 2476 asymbol **symbol_table; 2477 long number_of_symbols; 2478 symbol_info info; 2479 2480 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table); 2481 bfd_get_symbol_info(abfd,symbol_table[0],&info); 2482 } 2483 ]])], 2484 [AC_SUBST([CabalHaveLibbfd], [True])],dnl bfd seems to work 2485 [AC_MSG_ERROR([can't use 'bfd' library])]) 2486 LIBS="$save_LIBS" 2487 ] 2488 ) 2489]) 2490 2491 2492# FP_CC_LINKER_FLAG_TRY() 2493# -------------------- 2494# Try a particular linker to see whether we can use it. In particular, determine 2495# whether we can convince gcc to use it via a -fuse-ld=... flag. 2496# 2497# $1 = the name of the linker to try 2498# $2 = the variable to set with the appropriate GHC flag if the linker is 2499# found to be usable 2500AC_DEFUN([FP_CC_LINKER_FLAG_TRY], [ 2501 AC_MSG_CHECKING([whether C compiler supports -fuse-ld=$1]) 2502 echo 'int main(void) {return 0;}' > conftest.c 2503 if $CC -o conftest.o -fuse-ld=$1 conftest.c > /dev/null 2>&1 2504 then 2505 $2="-fuse-ld=$1" 2506 AC_MSG_RESULT([yes]) 2507 else 2508 AC_MSG_RESULT([no]) 2509 fi 2510 rm -f conftest.c conftest.o 2511]) 2512 2513# FIND_LD 2514# --------- 2515# Find the version of `ld` to use and figure out how to get gcc to use it for 2516# linking (if --enable-ld-override is enabled). This is used in both in the top 2517# level configure.ac and in distrib/configure.ac.in. 2518# 2519# $1 = the platform 2520# $2 = the variable to set with GHC options to configure gcc to use the chosen linker 2521# 2522AC_DEFUN([FIND_LD],[ 2523 AC_ARG_ENABLE(ld-override, 2524 [AS_HELP_STRING([--disable-ld-override], 2525 [Prevent GHC from overriding the default linker used by gcc. If ld-override is enabled GHC will try to tell gcc to use whichever linker is selected by the LD environment variable. [default=override enabled]])], 2526 [], 2527 [enable_ld_override=yes]) 2528 2529 find_ld() { 2530 # Make sure the user didn't specify LD manually. 2531 if test "z$LD" != "z"; then 2532 AC_CHECK_TARGET_TOOL([LD], [ld]) 2533 return 2534 fi 2535 2536 # Manually iterate over possible names since we want to ensure that, e.g., 2537 # if ld.lld is installed but gcc doesn't support -fuse-ld=lld, that we 2538 # then still try ld.gold and -fuse-ld=gold. 2539 for possible_ld in ld.lld ld.gold ld; do 2540 TmpLd="" # In case the user set LD 2541 AC_CHECK_TARGET_TOOL([TmpLd], [$possible_ld]) 2542 if test "x$TmpLd" = "x"; then continue; fi 2543 2544 out=`$TmpLd --version` 2545 case $out in 2546 "GNU ld"*) 2547 FP_CC_LINKER_FLAG_TRY(bfd, $2) ;; 2548 "GNU gold"*) 2549 FP_CC_LINKER_FLAG_TRY(gold, $2) 2550 if test "$cross_compiling" = "yes"; then 2551 AC_MSG_NOTICE([Using ld.gold and assuming that it is not affected by binutils issue 22266]); 2552 fi 2553 ;; 2554 "LLD"*) 2555 FP_CC_LINKER_FLAG_TRY(lld, $2) ;; 2556 *) AC_MSG_NOTICE([unknown linker version $out]) ;; 2557 esac 2558 if test "z$$2" = "z"; then 2559 AC_MSG_NOTICE([unable to convince '$CC' to use linker '$TmpLd']) 2560 # a terrible hack to prevent autoconf from caching the previous 2561 # AC_CHECK_TARGET_TOOL result since next time we'll be looking 2562 # for another ld variant. 2563 $as_unset ac_cv_prog_ac_ct_TmpLd 2564 else 2565 LD="$TmpLd" 2566 return 2567 fi 2568 done 2569 2570 # Fallback 2571 AC_CHECK_TARGET_TOOL([LD], [ld]) 2572 } 2573 2574 if test "x$enable_ld_override" = "xyes"; then 2575 find_ld 2576 else 2577 AC_CHECK_TARGET_TOOL([LD], [ld]) 2578 fi 2579 2580 CHECK_LD_COPY_BUG([$1]) 2581]) 2582 2583 2584# CHECK_FOR_GOLD_T22266 2585# ---------------------- 2586# 2587# Test for binutils #22266. This bug manifested as GHC bug #14328 (see also: 2588# #14675, #14291). 2589# Uses test from 2590# https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=033bfb739b525703bfe23f151d09e9beee3a2afe 2591# 2592# $1 = linker to test 2593# Sets $result to 0 if not affected, 1 otherwise 2594AC_DEFUN([CHECK_FOR_GOLD_T22266],[ 2595 AC_MSG_CHECKING([for ld.gold object merging bug (binutils 22266)]) 2596 if ! $1 --version | grep -q "GNU gold"; then 2597 # Not gold 2598 result=0 2599 elif test "$cross_compiling" = "yes"; then 2600 AC_MSG_RESULT([cross-compiling, assuming LD can merge objects correctly.]) 2601 result=0 2602 else 2603 FPTOOLS_WRITE_FILE([conftest.a.c], [ 2604 __attribute__((section(".data.a"))) 2605 static int int_from_a_1 = 0x11223344; 2606 2607 __attribute__((section(".data.rel.ro.a"))) 2608 int *p_int_from_a_2 = &int_from_a_1; 2609 2610 const char *hello (void); 2611 2612 const char * 2613 hello (void) 2614 { 2615 return "XXXHello, world!" + 3; 2616 } 2617 ]) 2618 2619 FPTOOLS_WRITE_FILE([conftest.main.c], [ 2620 #include <stdlib.h> 2621 #include <string.h> 2622 2623 extern int *p_int_from_a_2; 2624 extern const char *hello (void); 2625 2626 int main (void) { 2627 if (*p_int_from_a_2 != 0x11223344) 2628 abort (); 2629 if (strcmp(hello(), "Hello, world!") != 0) 2630 abort (); 2631 return 0; 2632 } 2633 ]) 2634 2635 FPTOOLS_WRITE_FILE([conftest.t], [ 2636 SECTIONS 2637 { 2638 .text : { 2639 *(.text*) 2640 } 2641 .rodata : 2642 { 2643 *(.rodata .rodata.* .gnu.linkonce.r.*) 2644 } 2645 .data.rel.ro : { 2646 *(.data.rel.ro*) 2647 } 2648 .data : { 2649 *(.data*) 2650 } 2651 .bss : { 2652 *(.bss*) 2653 } 2654 } 2655 ]) 2656 2657 $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test]) 2658 $MergeObjsCmd $MergeObjsArgs -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object]) 2659 2660 $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver]) 2661 $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver]) 2662 2663 if ./conftest; then 2664 AC_MSG_RESULT([not affected]) 2665 result=0 2666 else 2667 AC_MSG_RESULT([affected]) 2668 result=1 2669 fi 2670 rm -f conftest.a.o conftest.a.c conttest.ar.o conftest.main.c conftest.main.o conftest 2671 fi 2672]) 2673 2674# FIND_MERGE_OBJECTS 2675# ------------------ 2676# Find which linker to use to merge object files. 2677# 2678# See Note [Merging object files for GHCi] in GHC.Driver.Pipeline. 2679AC_DEFUN([FIND_MERGE_OBJECTS],[ 2680 AC_REQUIRE([FIND_LD]) 2681 2682 if test -z "$MergeObjsCmd"; then 2683 MergeObjsCmd="$LD" 2684 fi 2685 if test -z "$MergeObjsArgs"; then 2686 MergeObjsArgs="-r" 2687 fi 2688 2689 CHECK_FOR_GOLD_T22266($MergeObjsCmd) 2690 if test "$result" = "1"; then 2691 AC_MSG_NOTICE([$MergeObjsCmd is broken due to binutils 22266, looking for another linker...]) 2692 MergeObjsCmd="" 2693 AC_CHECK_TARGET_TOOL([MergeObjsCmd], [ld]) 2694 CHECK_FOR_GOLD_T22266($MergeObjsCmd) 2695 if test "$result" = "1"; then 2696 AC_MSG_ERROR([Linker is affected by binutils 22266 but couldn't find another unaffected linker. Please set the MergeObjsCmd variable to a functional linker.]) 2697 fi 2698 fi 2699 2700 AC_SUBST([MergeObjsCmd]) 2701 AC_SUBST([MergeObjsArgs]) 2702]) 2703 2704# FIND_PYTHON 2705# ----------- 2706# Find the version of `python` to use (for the testsuite driver) 2707# 2708AC_DEFUN([FIND_PYTHON],[ 2709 dnl Prefer the mingw64 distribution on Windows due to #17483. 2710 AC_PATH_PROG([PYTHON], [python3], [], [/mingw64/bin $PATH]) 2711 PythonCmd="$PYTHON" 2712 AC_SUBST([PythonCmd]) 2713]) 2714 2715# LocalWords: fi 2716