[Git][ghc/ghc][wip/toolchain-selection] Handle passing CPP cmd and flags from configure to ghc-toolchain

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Fri May 12 12:48:14 UTC 2023



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


Commits:
ef11d608 by Rodrigo Mesquita at 2023-05-12T13:48:08+01:00
Handle passing CPP cmd and flags from configure to ghc-toolchain

- - - - -


3 changed files:

- configure.ac
- − m4/fp_cpp_cmd_with_args.m4
- m4/ghc_toolchain.m4


Changes:

=====================================
configure.ac
=====================================
@@ -448,11 +448,37 @@ MAYBE_OVERRIDE_STAGE0([ar],[AR_STAGE0])
 dnl make extensions visible to allow feature-tests to detect them lateron
 AC_USE_SYSTEM_EXTENSIONS
 
-dnl ** figure out how to invoke the C preprocessor (i.e. `gcc -E`)
-AC_PROG_CPP
-
 # --with-hs-cpp/--with-hs-cpp-flags
-FP_CPP_CMD_WITH_ARGS(HaskellCPPCmd, HaskellCPPArgs)
+AC_ARG_WITH(hs-cpp,
+[AS_HELP_STRING([--with-hs-cpp=ARG],
+      [Path to the (C) preprocessor for Haskell files [default=autodetect]])],
+[
+    if test "$HostOS" = "mingw32"
+    then
+        AC_MSG_WARN([Request to use $withval will be ignored])
+    else
+        HaskellCPPCmd=$withval
+    fi
+],
+[
+    # We can't use $CPP here, since HaskellCPPCmd is expected to be a single
+    # command (no flags), and AC_PROG_CPP defines CPP as "/usr/bin/gcc -E".
+    HaskellCPPCmd=$CC
+]
+)
+AC_ARG_WITH(hs-cpp-flags,
+  [AS_HELP_STRING([--with-hs-cpp-flags=ARG],
+      [Flags to the (C) preprocessor for Haskell files [default=autodetect]])],
+  [
+      if test "$HostOS" = "mingw32"
+      then
+          AC_MSG_WARN([Request to use $withval will be ignored])
+      else
+          HaskellCPPArgs=$withval
+      fi
+  ],
+[ HaskellCPPArgs="" ]
+)
 AC_SUBST([HaskellCPPCmd])
 AC_SUBST([HaskellCPPArgs])
 


=====================================
m4/fp_cpp_cmd_with_args.m4 deleted
=====================================
@@ -1,69 +0,0 @@
-# FP_CPP_CMD_WITH_ARGS()
-# ----------------------
-# sets CPP command and its arguments
-#
-# $1 = the variable to set to CPP command
-# $2 = the variable to set to CPP command arguments
-
-AC_DEFUN([FP_CPP_CMD_WITH_ARGS],[
-dnl ** what cpp to use?
-dnl --------------------------------------------------------------
-AC_ARG_WITH(hs-cpp,
-[AS_HELP_STRING([--with-hs-cpp=ARG],
-      [Path to the (C) preprocessor for Haskell files [default=autodetect]])],
-[
-    if test "$HostOS" = "mingw32"
-    then
-        AC_MSG_WARN([Request to use $withval will be ignored])
-    else
-        HS_CPP_CMD=$withval
-    fi
-],
-[
-
-    # We can't use $CPP here, since HS_CPP_CMD is expected to be a single
-    # command (no flags), and AC_PROG_CPP defines CPP as "/usr/bin/gcc -E".
-    HS_CPP_CMD=$CC
-
-]
-)
-
-dnl ** what cpp flags to use?
-dnl -----------------------------------------------------------
-AC_ARG_WITH(hs-cpp-flags,
-  [AS_HELP_STRING([--with-hs-cpp-flags=ARG],
-      [Flags to the (C) preprocessor for Haskell files [default=autodetect]])],
-  [
-      if test "$HostOS" = "mingw32"
-      then
-          AC_MSG_WARN([Request to use $withval will be ignored])
-      else
-          HS_CPP_ARGS=$withval
-      fi
-  ],
-[
-  $HS_CPP_CMD -x c /dev/null -dM -E > conftest.txt 2>&1
-  if grep "__clang__" conftest.txt >/dev/null 2>&1; then
-    HS_CPP_ARGS="-E -undef -traditional -Wno-invalid-pp-token -Wno-unicode -Wno-trigraphs"
-  else
-      $HS_CPP_CMD  -v > conftest.txt 2>&1
-      if  grep "gcc" conftest.txt >/dev/null 2>&1; then
-          HS_CPP_ARGS="-E -undef -traditional"
-        else
-          $HS_CPP_CMD  --version > conftest.txt 2>&1
-          if grep "cpphs" conftest.txt >/dev/null 2>&1; then
-            HS_CPP_ARGS="--cpp -traditional"
-          else
-            AC_MSG_WARN([configure can't recognize your CPP program, you may need to set --with-hs-cpp-flags=FLAGS explicitly])
-            HS_CPP_ARGS=""
-          fi
-      fi
-  fi
-  ]
-)
-
-$1=$HS_CPP_CMD
-$2=$HS_CPP_ARGS
-
-])
-


=====================================
m4/ghc_toolchain.m4
=====================================
@@ -20,11 +20,13 @@ AC_DEFUN([FIND_GHC_TOOLCHAIN],
     echo "--triple=$target" >> acargs
     echo "--cc=$CC" >> acargs
     ADD_GHC_TOOLCHAIN_ARG([cc-opt], [$CONF_CC_OPTS_STAGE1])
-    # TODO (previously we had in configure script use of --traditional??)
-    # First thing disable the comment:
-    # Also, differentiatiate between hscpp and cpp?
-    #echo "--cpp=$CPP" >> acargs
+
+    # We can't use $CPP, since HS_CPP_CMD is expected to be a single
+    # command (no flags), and AC_PROG_CPP defines CPP as "/usr/bin/gcc -E".
+    echo "--cpp=$HaskellCPPCmd" >> acargs
+    # ROMES:TODO: CONF_CPP_OPTS_STAGE1 vs HaskellCPPArgs
     ADD_GHC_TOOLCHAIN_ARG([cpp-opt], [$CONF_CPP_OPTS_STAGE1])
+
     echo "--cc-link=$CC" >> acargs
     ADD_GHC_TOOLCHAIN_ARG([cc-link-opt], [$CONF_GCC_LINK_OPTS_STAGE1])
     echo "--cxx=$CXX" >> acargs



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ef11d6086beb968266186bf172f690d53e974860
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/20230512/17f423d5/attachment-0001.html>


More information about the ghc-commits mailing list