[Git][ghc/ghc][wip/rts-configure] 3 commits: Configure scripts: `checkOS`: Make a bit more robust

John Ericson (@Ericson2314) gitlab at gitlab.haskell.org
Sat Sep 23 05:12:15 UTC 2023



John Ericson pushed to branch wip/rts-configure at Glasgow Haskell Compiler / GHC


Commits:
c01f0f89 by John Ericson at 2023-09-23T01:11:12-04:00
Configure scripts: `checkOS`: Make a bit more robust

`mingw64` and `mingw32` are now both accepted for `OSMinGW32`. This
allows us to cope with configs/triples that we haven't normalized extra
being what GNU `config.sub` does.

- - - - -
ad64a343 by John Ericson at 2023-09-23T01:11:15-04:00
Generate `ghcplatform.h` from RTS configure

We create a new cabal flag to facilitate this.

- - - - -
6f2602e7 by John Ericson at 2023-09-23T01:11:15-04:00
Get rid of all mention of `mk/config.h`

The RTS configure script is now solely responsible for managing its
headers; the top level configure script does not help.

- - - - -


11 changed files:

- .gitignore
- configure.ac
- distrib/cross-port
- hadrian/src/Rules/Generate.hs
- hadrian/src/Rules/Lint.hs
- hadrian/src/Rules/Register.hs
- m4/fptools_set_haskell_platform_vars.m4
- rts/configure.ac
- + rts/ghcplatform.h.bottom
- + rts/ghcplatform.h.top.in
- rts/rts.cabal.in


Changes:

=====================================
.gitignore
=====================================
@@ -184,8 +184,8 @@ _darcs/
 /linter.log
 /mk/are-validating.mk
 /mk/build.mk
-/mk/config.h
-/mk/config.h.in
+/mk/unused.h
+/mk/unused.h.in
 /mk/config.mk
 /mk/config.mk.old
 /mk/system-cxx-std-lib-1.0.conf


=====================================
configure.ac
=====================================
@@ -32,8 +32,8 @@ AC_CONFIG_MACRO_DIRS([m4])
 # checkout), then we ship a file 'VERSION' containing the full version
 # when the source distribution was created.
 
-if test ! -f mk/config.h.in; then
-   echo "mk/config.h.in doesn't exist: perhaps you haven't run 'python3 boot'?"
+if test ! -f rts/ghcautoconf.h.autoconf.in; then
+   echo "rts/ghcautoconf.h.autoconf.in doesn't exist: perhaps you haven't run 'python3 boot'?"
    exit 1
 fi
 
@@ -99,8 +99,8 @@ AC_PREREQ([2.69])
 # Prepare to generate the following header files
 #
 
-# This one is autogenerated by autoheader.
-AC_CONFIG_HEADER(mk/config.h)
+dnl so the next one doesn't get mangled
+AC_CONFIG_HEADER(mk/unused.h)
 # This one is manually maintained.
 AC_CONFIG_HEADER(compiler/ghc-llvm-version.h)
 dnl manually outputted above, for reasons described there.


=====================================
distrib/cross-port
=====================================
@@ -28,7 +28,7 @@ if [ ! -f b1-stamp ]; then
 
    # For cross-compilation, at this stage you may want to set up a source
    # tree on the target machine, run the configure script there, and bring
-   # the resulting mk/config.h file back into this tree before building
+   # the resulting rts/ghcautoconf.h.autoconf file back into this tree before building
    # the libraries.
 
    touch mk/build.mk


=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -155,10 +155,10 @@ generatePackageCode context@(Context stage pkg _ _) = do
     when (pkg == rts) $ do
         root -/- "**" -/- dir -/- "cmm/AutoApply.cmm" %> \file ->
             build $ target context GenApply [] [file]
-        let go gen file = generate file (semiEmptyTarget stage) gen
         root -/- "**" -/- dir -/- "include/ghcautoconf.h" %> \_ ->
             need . pure =<< pkgSetupConfigFile context
-        root -/- "**" -/- dir -/- "include/ghcplatform.h" %> go generateGhcPlatformH
+        root -/- "**" -/- dir -/- "include/ghcplatform.h" %> \_ ->
+            need . pure =<< pkgSetupConfigFile context
         root -/- "**" -/- dir -/- "include/DerivedConstants.h" %> genPlatformConstantsHeader context
         root -/- "**" -/- dir -/- "include/rts/EventLogConstants.h" %> genEventTypes "--event-types-defines"
         root -/- "**" -/- dir -/- "include/rts/EventTypes.h" %> genEventTypes "--event-types-array"
@@ -305,6 +305,7 @@ rtsCabalFlags = mconcat
     , flag "CabalUseSystemLibFFI" UseSystemFfi
     , targetFlag "CabalLibffiAdjustors" tgtUseLibffiForAdjustors
     , targetFlag "CabalLeadingUnderscore" tgtSymbolsHaveLeadingUnderscore
+    , targetFlag "CabalUnregisterised" tgtUnregisterised
     , targetFlag "CabalTablesNextToCode" tgtTablesNextToCode
     ]
   where
@@ -370,62 +371,6 @@ ghcWrapper stage  = do
                                      else [])
                                ++ [ "$@" ]
 
--- | Given a 'String' replace characters '.' and '-' by underscores ('_') so that
--- the resulting 'String' is a valid C preprocessor identifier.
-cppify :: String -> String
-cppify = replaceEq '-' '_' . replaceEq '.' '_'
-
--- | Generate @ghcplatform.h@ header.
--- ROMES:TODO: For the runtime-retargetable GHC, these will eventually have to
--- be determined at runtime, and no longer hardcoded to a file (passed as -D
--- flags to the preprocessor, probably)
-generateGhcPlatformH :: Expr String
-generateGhcPlatformH = do
-    trackGenerateHs
-    stage    <- getStage
-    let chooseSetting x y = case stage of { Stage0 {} -> x; _ -> y }
-    buildPlatform  <- chooseSetting (queryBuild targetPlatformTriple) (queryHost targetPlatformTriple)
-    buildArch      <- chooseSetting (queryBuild queryArch)   (queryHost queryArch)
-    buildOs        <- chooseSetting (queryBuild queryOS)     (queryHost queryOS)
-    buildVendor    <- chooseSetting (queryBuild queryVendor) (queryHost queryVendor)
-    hostPlatform   <- chooseSetting (queryHost targetPlatformTriple) (queryTarget targetPlatformTriple)
-    hostArch       <- chooseSetting (queryHost queryArch)    (queryTarget queryArch)
-    hostOs         <- chooseSetting (queryHost queryOS)      (queryTarget queryOS)
-    hostVendor     <- chooseSetting (queryHost queryVendor)  (queryTarget queryVendor)
-    ghcUnreg       <- queryTarget tgtUnregisterised
-    return . unlines $
-        [ "#if !defined(__GHCPLATFORM_H__)"
-        , "#define __GHCPLATFORM_H__"
-        , ""
-        , "#define BuildPlatform_TYPE  " ++ cppify buildPlatform
-        , "#define HostPlatform_TYPE   " ++ cppify hostPlatform
-        , ""
-        , "#define " ++ cppify buildPlatform   ++ "_BUILD 1"
-        , "#define " ++ cppify hostPlatform ++ "_HOST 1"
-        , ""
-        , "#define " ++ buildArch   ++ "_BUILD_ARCH 1"
-        , "#define " ++ hostArch ++ "_HOST_ARCH 1"
-        , "#define BUILD_ARCH " ++ show buildArch
-        , "#define HOST_ARCH "  ++ show hostArch
-        , ""
-        , "#define " ++ buildOs   ++ "_BUILD_OS 1"
-        , "#define " ++ hostOs ++ "_HOST_OS 1"
-        , "#define BUILD_OS " ++ show buildOs
-        , "#define HOST_OS "  ++ show hostOs
-        , ""
-        , "#define " ++ buildVendor   ++ "_BUILD_VENDOR 1"
-        , "#define " ++ hostVendor ++ "_HOST_VENDOR 1"
-        , "#define BUILD_VENDOR " ++ show buildVendor
-        , "#define HOST_VENDOR "  ++ show hostVendor
-        , ""
-        ]
-        ++
-        [ "#define UnregisterisedCompiler 1" | ghcUnreg ]
-        ++
-        [ ""
-        , "#endif /* __GHCPLATFORM_H__ */"
-        ]
-
 generateSettings :: Expr String
 generateSettings = do
     ctx <- getContext


=====================================
hadrian/src/Rules/Lint.hs
=====================================
@@ -22,6 +22,8 @@ lintRules = do
       cmd_ (Cwd "libraries/base") "./configure"
   "rts" -/- "include" -/- "ghcautoconf.h" %> \_ ->
       cmd_ (Cwd "rts") "./configure"
+  "rts" -/- "include" -/- "ghcplatform.h" %> \_ ->
+      cmd_ (Cwd "rts") "./configure"
 
 lint :: Action () -> Action ()
 lint lintAction = do
@@ -68,7 +70,6 @@ base = do
   let includeDirs =
         [ "rts/include"
         , "libraries/base/include"
-        , stage1RtsInc
         ]
   runHLint includeDirs [] "libraries/base"
 


=====================================
hadrian/src/Rules/Register.hs
=====================================
@@ -51,12 +51,6 @@ configurePackageRules = do
           isGmp <- (== "gmp") <$> interpretInContext ctx getBignumBackend
           when isGmp $
             need [buildP -/- "include/ghc-gmp.h"]
-        when (pkg == rts) $ do
-          -- Rts.h is a header listed in the cabal file, and configuring
-          -- therefore wants to ensure that the header "works" post-configure.
-          -- But it (transitively) includes this, so we must ensure it exists
-          -- for that check to work.
-          need [buildP -/- "include/ghcplatform.h"]
         Cabal.configurePackage ctx
 
     root -/- "**/autogen/cabal_macros.h" %> \out -> do


=====================================
m4/fptools_set_haskell_platform_vars.m4
=====================================
@@ -82,7 +82,7 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS_SHELL_FUNCTIONS],
         solaris2)
             test -z "[$]2" || eval "[$]2=OSSolaris2"
             ;;
-        mingw32|windows)
+        mingw32|mingw64|windows)
             test -z "[$]2" || eval "[$]2=OSMinGW32"
             ;;
         freebsd)


=====================================
rts/configure.ac
=====================================
@@ -22,6 +22,8 @@ dnl     #define SIZEOF_CHAR 0
 dnl   recently.
 AC_PREREQ([2.69])
 
+AC_CONFIG_FILES([ghcplatform.h.top])
+
 AC_CONFIG_HEADERS([ghcautoconf.h.autoconf])
 
 AC_ARG_ENABLE(asserts-all-ways,
@@ -79,6 +81,10 @@ FP_CC_LLVM_BACKEND
 AS_IF([test x"$CcLlvmBackend" = x"YES"],
   [AC_DEFINE([CC_LLVM_BACKEND], [1], [Define (to 1) if C compiler has an LLVM back end])])
 
+GHC_CONVERT_PLATFORM_PARTS([build], [Build])
+FPTOOLS_SET_PLATFORM_VARS([build],[Build])
+FPTOOLS_SET_HASKELL_PLATFORM_VARS([Build])
+
 GHC_CONVERT_PLATFORM_PARTS([host], [Host])
 FPTOOLS_SET_PLATFORM_VARS([host], [Host])
 FPTOOLS_SET_HASKELL_PLATFORM_VARS([Host])
@@ -350,19 +356,41 @@ dnl --------------------------------------------------------------
 AC_OUTPUT
 
 dnl ######################################################################
-dnl Generate ghcautoconf.h
+dnl Generate ghcplatform.h
 dnl ######################################################################
 
 [
 mkdir -p include
+
+touch include/ghcplatform.h
+> include/ghcplatform.h
+
+cat ghcplatform.h.top                          >> include/ghcplatform.h
+]
+
+dnl ** Do an unregisterised build?
+dnl --------------------------------------------------------------
+AS_IF(
+  [test "$CABAL_FLAG_unregisterised" = 1],
+  [echo "#define UnregisterisedCompiler 1"     >> include/ghcplatform.h])
+
+[
+cat $srcdir/ghcplatform.h.bottom               >> include/ghcplatform.h
+]
+
+dnl ######################################################################
+dnl Generate ghcautoconf.h
+dnl ######################################################################
+
+[
 touch include/ghcautoconf.h
 > include/ghcautoconf.h
 
 echo "#if !defined(__GHCAUTOCONF_H__)" >> include/ghcautoconf.h
 echo "#define __GHCAUTOCONF_H__" >> include/ghcautoconf.h
-# Copy the contents of $srcdir/../mk/config.h, turning '#define PACKAGE_FOO
+# Copy the contents of ghcautoconf.h.autoconf, turning '#define PACKAGE_FOO
 # "blah"' into '/* #undef PACKAGE_FOO */' to avoid clashes.
-cat $srcdir/../mk/config.h ghcautoconf.h.autoconf | sed \
+cat ghcautoconf.h.autoconf | sed \
    -e 's,^\([	 ]*\)#[	 ]*define[	 ][	 ]*\(PACKAGE_[A-Z]*\)[	 ][ 	]*".*".*$,\1/* #undef \2 */,' \
    -e '/__GLASGOW_HASKELL/d' \
    -e '/REMOVE ME/d' \


=====================================
rts/ghcplatform.h.bottom
=====================================
@@ -0,0 +1,2 @@
+
+#endif /* __GHCPLATFORM_H__ */


=====================================
rts/ghcplatform.h.top.in
=====================================
@@ -0,0 +1,23 @@
+#if !defined(__GHCPLATFORM_H__)
+#define __GHCPLATFORM_H__
+
+#define BuildPlatform_TYPE  @BuildPlatform_CPP@
+#define HostPlatform_TYPE   @HostPlatform_CPP@
+
+#define @BuildPlatform_CPP at _BUILD  1
+#define @HostPlatform_CPP at _HOST  1
+
+#define @BuildArch_CPP at _BUILD_ARCH  1
+#define @HostArch_CPP at _HOST_ARCH  1
+#define BUILD_ARCH  "@BuildArch_CPP@"
+#define HOST_ARCH  "@HostArch_CPP@"
+
+#define @BuildOS_CPP at _BUILD_OS  1
+#define @HostOS_CPP at _HOST_OS  1
+#define BUILD_OS  "@BuildOS_CPP@"
+#define HOST_OS  "@HostOS_CPP@"
+
+#define @BuildVendor_CPP at _BUILD_VENDOR  1
+#define @HostVendor_CPP at _HOST_VENDOR  1
+#define BUILD_VENDOR  "@BuildVendor_CPP@"
+#define HOST_VENDOR  "@HostVendor_CPP@"


=====================================
rts/rts.cabal.in
=====================================
@@ -54,6 +54,8 @@ flag static-libzstd
   default: @CabalStaticLibZstd@
 flag leading-underscore
   default: @CabalLeadingUnderscore@
+flag unregisterised
+  default: @CabalUnregisterised@
 flag tables-next-to-code
   default: @CabalTablesNextToCode@
 flag smp
@@ -234,7 +236,7 @@ library
 
       include-dirs: include
       includes: Rts.h
-      autogen-includes: ghcautoconf.h
+      autogen-includes: ghcautoconf.h ghcplatform.h
       install-includes: Cmm.h HsFFI.h MachDeps.h Rts.h RtsAPI.h Stg.h
                         ghcautoconf.h ghcconfig.h ghcplatform.h ghcversion.h
                         -- ^ from include



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ba6b3083c8550a6deb4d2ef6f667dc3e90dfa415...6f2602e77dc912a775c169027bad7d3e0d5519f5

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ba6b3083c8550a6deb4d2ef6f667dc3e90dfa415...6f2602e77dc912a775c169027bad7d3e0d5519f5
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/20230923/d17c2213/attachment-0001.html>


More information about the ghc-commits mailing list