[Git][ghc/ghc][wip/supersven/correctly_propagate_host-build-target] 2 commits: Respect user set CFLAGS, CXXFLAGS and LDFLAGS
Sven Tennie pushed to branch wip/supersven/correctly_propagate_host-build-target at Glasgow Haskell Compiler / GHC Commits: 7bffb567 by Sven Tennie at 2026-03-25T17:30:29+01:00 Respect user set CFLAGS, CXXFLAGS and LDFLAGS These were ignored on installs. - - - - - 312deb98 by Sven Tennie at 2026-03-25T17:30:29+01:00 Only add flags if they are new This prevents duplicated when the user already set the arguments in CXXFLAGS or CFLAGS. - - - - - 3 changed files: - distrib/configure.ac.in - utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cpp.hs - utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs Changes: ===================================== distrib/configure.ac.in ===================================== @@ -159,6 +159,24 @@ AC_PROG_CXX([c++ g++ clang++]) MOVE_TO_FLAGS([CC],[CFLAGS]) MOVE_TO_FLAGS([CXX],[CXXFLAGS]) +dnl Save the original user-provided environment variables immediately +dnl before any m4 macros modify them. These will be passed to ghc-toolchain +dnl so it can make independent decisions and reach the same conclusions as autoconf. +USER_CONF_CC_OPTS_STAGE2="$CFLAGS" +USER_CONF_CXX_OPTS_STAGE2="$CXXFLAGS" +USER_CONF_GCC_LINKER_OPTS_STAGE2="$LDFLAGS" +USER_CPP_ARGS="$CPPFLAGS" +USER_HS_CPP_ARGS="$HaskellCPPArgs" +USER_JS_CPP_ARGS="$JavaScriptCPPArgs" +USER_CMM_CPP_ARGS="$CmmCPPArgs" + +dnl Initialize CONF_* variables with user-provided environment variables +dnl so that subsequent configure checks modify them and both autoconf and +dnl ghc-toolchain see the same values +CONF_CC_OPTS_STAGE2="$CFLAGS" +CONF_CXX_OPTS_STAGE2="$CXXFLAGS" +CONF_GCC_LINKER_OPTS_STAGE2="$LDFLAGS" + dnl ** figure out how to invoke the C preprocessor (i.e. `gcc -E`) AC_PROG_CPP ===================================== utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cpp.hs ===================================== @@ -61,7 +61,7 @@ findHsCpp progOpt cc = checking "for Haskell C preprocessor" $ do let rawHsCppProgram = addFlagIfNew "-E" foundHsCppProg -- Always try to add the Haskell-specific CPP flags, regardless of the user options hppArgs <- findHsCppArgs rawHsCppProgram - let hsCppProgram = over _prgFlags (++hppArgs) rawHsCppProgram + let hsCppProgram = foldr addFlagIfNew rawHsCppProgram (reverse hppArgs) return HsCpp{hsCppProgram} -- | 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 -- -- On OpenSolaris uses gnu ld whereas SmartOS appears to use the Solaris -- implementation, which rather uses the -64 flag. - return $ ccLink2 & _prgFlags %++ "-m64" + return $ addFlagIfNew "-m64" ccLink2 ArchOS ArchAlpha _ -> -- For now, to suppress the gcc warning "call-clobbered -- register used for global register variable", we simply -- disable all warnings altogether using the -w flag. Oh well. - return $ ccLink2 & over _prgFlags (++["-w","-mieee","-D_REENTRANT"]) + return $ foldr addFlagIfNew ccLink2 (reverse ["-w","-mieee","-D_REENTRANT"]) -- ArchOS ArchHPPA? _ -> ArchOS ArchARM{} OSFreeBSD -> -- On arm/freebsd, tell gcc to generate Arm -- instructions (ie not Thumb). - return $ ccLink2 & _prgFlags %++ "-Wl,-z,noexecstack" + return $ addFlagIfNew "-Wl,-z,noexecstack" ccLink2 ArchOS ArchARM{} OSLinux -> -- On arm/linux and arm/android, tell gcc to generate Arm -- instructions (ie not Thumb). - return $ ccLink2 & _prgFlags %++ "-Wl,-z,noexecstack" + return $ addFlagIfNew "-Wl,-z,noexecstack" ccLink2 ArchOS ArchAArch64 OSFreeBSD -> - return $ ccLink2 & _prgFlags %++ "-Wl,-z,noexecstack" + return $ addFlagIfNew "-Wl,-z,noexecstack" ccLink2 ArchOS ArchAArch64 OSLinux -> - return $ ccLink2 & _prgFlags %++ "-Wl,-z,noexecstack" + return $ addFlagIfNew "-Wl,-z,noexecstack" ccLink2 ArchOS ArchAArch64 OSNetBSD -> - return $ ccLink2 & _prgFlags %++ "-Wl,-z,noexecstack" + return $ addFlagIfNew "-Wl,-z,noexecstack" ccLink2 ArchOS ArchPPC OSAIX -> -- We need `-D_THREAD_SAFE` to unlock the thread-local `errno`. - return $ ccLink2 & over _prgFlags (++["-D_THREAD_SAFE","-Wl,-bnotextro"]) + return $ foldr addFlagIfNew ccLink2 (reverse ["-D_THREAD_SAFE","-Wl,-bnotextro"]) _ -> return ccLink2 @@ -383,7 +383,7 @@ addOSMinGW32CcFlags archOs cc link -- See Note [Windows stack allocations]. checkFStackCheck :: Cc -> Program -> M Program checkFStackCheck cc link = checking "that -fstack-check works" $ do - let link' = link & _prgFlags %++ "-fstack-check" + let link' = addFlagIfNew "-fstack-check" link checkLinkWorks cc link' return link' @@ -393,7 +393,7 @@ addNoAsNeeded archOs cc ccLink | os <- archOS_OS archOs , osElfTarget os = checking "that --no-as-needed works" $ do - let ccLink' = over _prgFlags (++["-Wl,--no-as-needed"]) ccLink + let ccLink' = addFlagIfNew "-Wl,--no-as-needed" ccLink checkLinkWorks cc ccLink' return ccLink' | otherwise = return ccLink View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/9ce6620f4254da92b848af3e1a3c750... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/9ce6620f4254da92b848af3e1a3c750... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Sven Tennie (@supersven)