Sven Tennie pushed to branch wip/supersven/correctly_propagate_host-build-target at Glasgow Haskell Compiler / GHC

Commits:

3 changed files:

Changes:

  • distrib/configure.ac.in
    ... ... @@ -159,6 +159,24 @@ AC_PROG_CXX([c++ g++ clang++])
    159 159
     MOVE_TO_FLAGS([CC],[CFLAGS])
    
    160 160
     MOVE_TO_FLAGS([CXX],[CXXFLAGS])
    
    161 161
     
    
    162
    +dnl Save the original user-provided environment variables immediately
    
    163
    +dnl before any m4 macros modify them. These will be passed to ghc-toolchain
    
    164
    +dnl so it can make independent decisions and reach the same conclusions as autoconf.
    
    165
    +USER_CONF_CC_OPTS_STAGE2="$CFLAGS"
    
    166
    +USER_CONF_CXX_OPTS_STAGE2="$CXXFLAGS"
    
    167
    +USER_CONF_GCC_LINKER_OPTS_STAGE2="$LDFLAGS"
    
    168
    +USER_CPP_ARGS="$CPPFLAGS"
    
    169
    +USER_HS_CPP_ARGS="$HaskellCPPArgs"
    
    170
    +USER_JS_CPP_ARGS="$JavaScriptCPPArgs"
    
    171
    +USER_CMM_CPP_ARGS="$CmmCPPArgs"
    
    172
    +
    
    173
    +dnl Initialize CONF_* variables with user-provided environment variables
    
    174
    +dnl so that subsequent configure checks modify them and both autoconf and
    
    175
    +dnl ghc-toolchain see the same values
    
    176
    +CONF_CC_OPTS_STAGE2="$CFLAGS"
    
    177
    +CONF_CXX_OPTS_STAGE2="$CXXFLAGS"
    
    178
    +CONF_GCC_LINKER_OPTS_STAGE2="$LDFLAGS"
    
    179
    +
    
    162 180
     dnl ** figure out how to invoke the C preprocessor (i.e. `gcc -E`)
    
    163 181
     AC_PROG_CPP
    
    164 182
     
    

  • utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cpp.hs
    ... ... @@ -61,7 +61,7 @@ findHsCpp progOpt cc = checking "for Haskell C preprocessor" $ do
    61 61
       let rawHsCppProgram = addFlagIfNew "-E" foundHsCppProg
    
    62 62
       -- Always try to add the Haskell-specific CPP flags, regardless of the user options
    
    63 63
       hppArgs <- findHsCppArgs rawHsCppProgram
    
    64
    -  let hsCppProgram = over _prgFlags (++hppArgs) rawHsCppProgram
    
    64
    +  let hsCppProgram = foldr addFlagIfNew rawHsCppProgram (reverse hppArgs)
    
    65 65
       return HsCpp{hsCppProgram}
    
    66 66
     
    
    67 67
     -- | Given a C preprocessor, figure out how it should be invoked to preprocess
    

  • utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs
    ... ... @@ -345,30 +345,30 @@ addPlatformDepLinkFlags archOs cc ccLink0 = do
    345 345
           --
    
    346 346
           -- On OpenSolaris uses gnu ld whereas SmartOS appears to use the Solaris
    
    347 347
           -- implementation, which rather uses the -64 flag.
    
    348
    -      return $ ccLink2 & _prgFlags %++ "-m64"
    
    348
    +      return $ addFlagIfNew "-m64" ccLink2
    
    349 349
         ArchOS ArchAlpha _ ->
    
    350 350
           -- For now, to suppress the gcc warning "call-clobbered
    
    351 351
           -- register used for global register variable", we simply
    
    352 352
           -- disable all warnings altogether using the -w flag. Oh well.
    
    353
    -      return $ ccLink2 & over _prgFlags (++["-w","-mieee","-D_REENTRANT"])
    
    353
    +      return $ foldr addFlagIfNew ccLink2 (reverse ["-w","-mieee","-D_REENTRANT"])
    
    354 354
         -- ArchOS ArchHPPA? _ ->
    
    355 355
         ArchOS ArchARM{} OSFreeBSD ->
    
    356 356
           -- On arm/freebsd, tell gcc to generate Arm
    
    357 357
           -- instructions (ie not Thumb).
    
    358
    -      return $ ccLink2 & _prgFlags %++ "-Wl,-z,noexecstack"
    
    358
    +      return $ addFlagIfNew "-Wl,-z,noexecstack" ccLink2
    
    359 359
         ArchOS ArchARM{} OSLinux ->
    
    360 360
           -- On arm/linux and arm/android, tell gcc to generate Arm
    
    361 361
           -- instructions (ie not Thumb).
    
    362
    -      return $ ccLink2 & _prgFlags %++ "-Wl,-z,noexecstack"
    
    362
    +      return $ addFlagIfNew "-Wl,-z,noexecstack" ccLink2
    
    363 363
         ArchOS ArchAArch64 OSFreeBSD ->
    
    364
    -      return $ ccLink2 & _prgFlags %++ "-Wl,-z,noexecstack"
    
    364
    +      return $ addFlagIfNew "-Wl,-z,noexecstack" ccLink2
    
    365 365
         ArchOS ArchAArch64 OSLinux ->
    
    366
    -      return $ ccLink2 & _prgFlags %++ "-Wl,-z,noexecstack"
    
    366
    +      return $ addFlagIfNew "-Wl,-z,noexecstack" ccLink2
    
    367 367
         ArchOS ArchAArch64 OSNetBSD ->
    
    368
    -      return $ ccLink2 & _prgFlags %++ "-Wl,-z,noexecstack"
    
    368
    +      return $ addFlagIfNew "-Wl,-z,noexecstack" ccLink2
    
    369 369
         ArchOS ArchPPC OSAIX ->
    
    370 370
           -- We need `-D_THREAD_SAFE` to unlock the thread-local `errno`.
    
    371
    -      return $ ccLink2 & over _prgFlags (++["-D_THREAD_SAFE","-Wl,-bnotextro"])
    
    371
    +      return $ foldr addFlagIfNew ccLink2 (reverse ["-D_THREAD_SAFE","-Wl,-bnotextro"])
    
    372 372
         _ ->
    
    373 373
           return ccLink2
    
    374 374
     
    
    ... ... @@ -383,7 +383,7 @@ addOSMinGW32CcFlags archOs cc link
    383 383
     -- See Note [Windows stack allocations].
    
    384 384
     checkFStackCheck :: Cc -> Program -> M Program
    
    385 385
     checkFStackCheck cc link = checking "that -fstack-check works" $ do
    
    386
    -      let link' = link & _prgFlags %++ "-fstack-check"
    
    386
    +      let link' = addFlagIfNew "-fstack-check" link
    
    387 387
           checkLinkWorks cc link'
    
    388 388
           return link'
    
    389 389
     
    
    ... ... @@ -393,7 +393,7 @@ addNoAsNeeded archOs cc ccLink
    393 393
       | os <- archOS_OS archOs
    
    394 394
       , osElfTarget os
    
    395 395
       = checking "that --no-as-needed works" $ do
    
    396
    -      let ccLink' = over _prgFlags (++["-Wl,--no-as-needed"]) ccLink
    
    396
    +      let ccLink' = addFlagIfNew "-Wl,--no-as-needed" ccLink
    
    397 397
           checkLinkWorks cc ccLink'
    
    398 398
           return ccLink'
    
    399 399
       | otherwise = return ccLink