[Git][ghc/ghc][wip/toolchain-selection] configure: Create and validate toolchain target file

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Mon Jun 5 16:46:42 UTC 2023



Rodrigo Mesquita pushed to branch wip/toolchain-selection at Glasgow Haskell Compiler / GHC


Commits:
8ae926d8 by Rodrigo Mesquita at 2023-06-05T17:46:33+01:00
configure: Create and validate toolchain target file

- - - - -


5 changed files:

- configure.ac
- + default.target.in
- m4/ghc_toolchain.m4
- + m4/prep_target_file.m4
- utils/ghc-toolchain/Main.hs


Changes:

=====================================
configure.ac
=====================================
@@ -646,7 +646,6 @@ dnl CONF_CC_OPTS_STAGE[012] accordingly.
 FP_CC_SUPPORTS_TARGET([$CC_STAGE0], [CONF_CC_OPTS_STAGE0], [CONF_CXX_OPTS_STAGE0], [CONF_GCC_LINKER_OPTS_STAGE0])
 FP_CC_SUPPORTS_TARGET([$CC], [CONF_CC_OPTS_STAGE1], [CONF_CXX_OPTS_STAGE1], [CONF_GCC_LINKER_OPTS_STAGE1])
 FP_CC_SUPPORTS_TARGET([$CC], [CONF_CC_OPTS_STAGE2], [CONF_CXX_OPTS_STAGE2], [CONF_GCC_LINKER_OPTS_STAGE2])
-FIND_GHC_TOOLCHAIN
 
 # CPP, CPPFLAGS
 # --with-cpp/-with-cpp-flags
@@ -1170,6 +1169,11 @@ checkMake380() {
 checkMake380 make
 checkMake380 gmake
 
+# Toolchain target files
+PREP_TARGET_FILE
+FIND_GHC_TOOLCHAIN
+VALIDATE_GHC_TOOLCHAIN
+
 AC_CONFIG_FILES(
 [ mk/project.mk
   hadrian/cfg/system.config
@@ -1178,6 +1182,7 @@ AC_CONFIG_FILES(
   hadrian/ghci-stack
   docs/users_guide/ghc_config.py
   distrib/configure.ac
+  default.target
 ])
 
 dnl Create the VERSION file, satisfying #22322.


=====================================
default.target.in
=====================================
@@ -0,0 +1 @@
+Target {tgtArchOs = ArchOS {archOS_arch = @HostArch_CPP@, archOS_OS = @HostOS_CPP@}, tgtSupportsGnuNonexecStack = @TargetHasGnuNonexecStackBool@, tgtSupportsSubsectionsViaSymbols = @TargetHasSubsectionsViaSymbolsBool@, tgtSupportsIdentDirective = @TargetHasIdentDirectiveBool@, tgtWordSize = WS at TargetWordSize@, tgtEndianness = LittleEndian, tgtSymbolsHaveLeadingUnderscore = @LeadingUnderscoreBool@, tgtLlvmTarget = "@HostPlatform@", tgtUnregisterised = @UnregisterisedBool@, tgtTablesNextToCode = @TablesNextToCodeBool@, tgtUseLibffiForAdjustors = @UseLibffiForAdjustorsBool@, tgtCCompiler = Cc {ccProgram = Program {prgPath = "@SettingsCCompilerCommand@", prgFlags = @SettingsCCompilerFlagsList@}}, tgtCxxCompiler = Cxx {cxxProgram = Program {prgPath = "@SettingsCxxCompilerCommand@", prgFlags = @SettingsCxxCompilerFlagsList@}}, tgtCPreprocessor = Cpp {cppProgram = Program {prgPath = "@CPPCmd@", prgFlags = @CPPArgsList@}}, tgtHsCPreprocessor = HsCpp {hsCppProgram = Program {prgPath = "@HaskellCPPCmd@", prgFlags = @HaskellCPPArgsList@}}, tgtCCompilerLink = CcLink {ccLinkProgram = Program {prgPath = "@SettingsCCompilerCommand@", prgFlags = @SettingsCCompilerLinkFlagsList@}, ccLinkSupportsNoPie = @SettingsCCompilerSupportsNoPieBool@, ccLinkSupportsCompactUnwind = @LdHasNoCompactUnwindBool@, ccLinkSupportsFilelist = @LdHasFilelistBool@, ccLinkSupportsResponseFiles = @LdSupportsResponseFilesBool@, ccLinkIsGnu = @LdIsGNULdBool@}, tgtAr = Ar {arMkArchive = Program {prgPath = "@AR@", prgFlags = @ArArgsList@}, arIsGnu = False, arSupportsAtFile = @ArSupportsAtFileBool@, arSupportsDashL = @ArSupportsDashLBool@, arNeedsRanlib = False}, tgtRanlib = @REAL_RANLIB_CMD@, tgtNm = Nm {nmProgram = Program {prgPath = "@NmCmd@", prgFlags = []}}, tgtMergeObjs = Just (MergeObjs {mergeObjsProgram = Program {prgPath = "@SettingsMergeObjectsCommand@", prgFlags = @SettingsMergeObjectsFlagsList@}}), tgtDllwrap = Nothing, tgtWindres = Nothing}


=====================================
m4/ghc_toolchain.m4
=====================================
@@ -66,8 +66,21 @@ AC_DEFUN([FIND_GHC_TOOLCHAIN],
     ) <acargs || exit 1
 
     cat acargs
-    cat default.target
+    cat default.ghc-toolchain.target
 
     #rm -Rf acargs acghc-toolchain actmp-ghc-toolchain
 ])
 
+
+AC_DEFUN([VALIDATE_GHC_TOOLCHAIN],[
+    A="default.target"
+    B="default.ghc-toolchain.target"
+    cat $A | tr ' ' '\n' > $A.diffable
+    cat $B | tr ' ' '\n' > $B.diffable
+    diff_output=`diff "$A.diffable" "$B.diffable" 2>&1`
+    if test -z "$diff_output"; then
+      true
+    else
+      AC_MSG_WARN([Differences found between $A and $B: $diff_output])
+    fi
+])


=====================================
m4/prep_target_file.m4
=====================================
@@ -0,0 +1,71 @@
+# PREP_BOOLEAN
+# ============
+#
+# Issue a substitution with True/False of [$1Bool] when $1 has YES/NO value
+# $1 = boolean variable to substitute
+AC_DEFUN([PREP_BOOLEAN],[
+    case "$$1" in
+        YES)
+          $1Bool=True
+          ;;
+        NO)
+          $1Bool=False
+          ;;
+        *)
+          AC_MSG_ERROR([Expecting YES/NO but got $$1 in $1])
+          ;;
+    esac
+    AC_SUBST([$1Bool])
+])
+
+# PREP_LIST
+# ============
+#
+# Issue a substitution with ["list","of","args"] of [$1List] when $1 is a
+# space-separated list of args
+# $1 = list variable to substitute
+dnl In autoconf, '@<:@' stands for '[', and '@:>@' for ']'.
+AC_DEFUN([PREP_LIST],[
+    TMP_ARR=($$1)
+    $1List="@<:@"
+    if test -z "$TMP_ARR"; then
+        true
+    else
+        $1List="${$1List}\"${TMP_ARR@<:@0@:>@}\""
+        for arg in "${TMP_ARR@<:@@@:>@:1}"
+        do
+            $1List="${$1List},\"$arg\""
+        done
+    fi
+    $1List="${$1List}@:>@"
+    AC_SUBST([$1List])
+    unset TMP_ARR
+])
+
+# Eventually: PREP_BUILD_TARGET_FILE, PREP_HOST_TARGET_FILE, PREP_TARGET_TARGET_FILE
+# Prepares required substitutions to generate the target file
+AC_DEFUN([PREP_TARGET_FILE],[
+    PREP_BOOLEAN([LdSupportsResponseFiles])
+    PREP_BOOLEAN([TargetHasGnuNonexecStack])
+    PREP_BOOLEAN([LeadingUnderscore])
+    PREP_BOOLEAN([ArSupportsAtFile])
+    PREP_BOOLEAN([ArSupportsDashL])
+    PREP_BOOLEAN([TargetHasIdentDirective])
+    PREP_BOOLEAN([SettingsCCompilerSupportsNoPie])
+    PREP_BOOLEAN([LdHasFilelist])
+    PREP_BOOLEAN([LdIsGNULd])
+    PREP_BOOLEAN([LdHasNoCompactUnwind])
+    PREP_BOOLEAN([TargetHasSubsectionsViaSymbols])
+    PREP_BOOLEAN([Unregisterised])
+    PREP_BOOLEAN([TablesNextToCode])
+    PREP_BOOLEAN([UseLibffiForAdjustors])
+    PREP_LIST([SettingsMergeObjectsFlags])
+    PREP_LIST([ArArgs])
+    PREP_LIST([SettingsCCompilerLinkFlags])
+    PREP_LIST([HaskellCPPArgs])
+    PREP_LIST([CPPArgs])
+    PREP_LIST([SettingsCxxCompilerFlags])
+    PREP_LIST([SettingsCCompilerFlags])
+])
+
+AC_DEFUN()


=====================================
utils/ghc-toolchain/Main.hs
=====================================
@@ -216,7 +216,9 @@ run :: Opts -> M ()
 run opts = do
     tgt <- mkTarget opts
     logDebug $ "Final Target: " ++ show tgt
-    writeFile "default.target" (show tgt)
+    let file = "default.ghc-toolchain.target"
+    writeFile file (show tgt)
+    appendFile file "\n" -- eol
 
 optional :: M a -> M (Maybe a)
 optional k = fmap Just k <|> pure Nothing



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8ae926d85b86770b3d0971c52a70e92e80acf4df

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8ae926d85b86770b3d0971c52a70e92e80acf4df
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230605/594c0d13/attachment-0001.html>


More information about the ghc-commits mailing list