Skip to content

Commit

Permalink
Control CPP through settings file (#8683)
Browse files Browse the repository at this point in the history
Summary:
Allow the CPP program and flag choices for GHC
be configured via the the ghc settings file

Test Plan: ran validate yesterday

Reviewers: hvr, austin, mzero, simonmar

Reviewed By: austin, mzero, simonmar

Subscribers: mzero, simonmar, relrod, carter

Differential Revision: https://phabricator.haskell.org/D26
  • Loading branch information
cartazio authored and Austin Seipp committed Jul 2, 2014
1 parent 8afe616 commit 34f7e9a
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 15 deletions.
9 changes: 9 additions & 0 deletions aclocal.m4
Expand Up @@ -454,6 +454,7 @@ AC_DEFUN([FP_SETTINGS],
then
mingw_bin_prefix=mingw/bin/
SettingsCCompilerCommand="\$topdir/../${mingw_bin_prefix}gcc.exe"
SettingsHaskellCPPCommand="\$topdir/../${mingw_bin_prefix}gcc.exe"
SettingsLdCommand="\$topdir/../${mingw_bin_prefix}ld.exe"
SettingsArCommand="\$topdir/../${mingw_bin_prefix}ar.exe"
SettingsPerlCommand='$topdir/../perl/perl.exe'
Expand All @@ -462,6 +463,8 @@ AC_DEFUN([FP_SETTINGS],
SettingsTouchCommand='$topdir/touchy.exe'
else
SettingsCCompilerCommand="$WhatGccIsCalled"
SettingsHaskellCPPCommand="$HaskellCPPCmd"
SettingsHaskellCPPFlags="$HaskellCPPArgs"
SettingsLdCommand="$LdCmd"
SettingsArCommand="$ArCmd"
SettingsPerlCommand="$PerlCmd"
Expand All @@ -486,6 +489,8 @@ AC_DEFUN([FP_SETTINGS],
SettingsCCompilerLinkFlags="$CONF_GCC_LINKER_OPTS_STAGE2"
SettingsLdFlags="$CONF_LD_LINKER_OPTS_STAGE2"
AC_SUBST(SettingsCCompilerCommand)
AC_SUBST(SettingsHaskellCPPCommand)
AC_SUBST(SettingsHaskellCPPFlags)
AC_SUBST(SettingsCCompilerFlags)
AC_SUBST(SettingsCCompilerLinkFlags)
AC_SUBST(SettingsLdCommand)
Expand Down Expand Up @@ -706,6 +711,8 @@ AC_ARG_WITH($2,
)
]) # FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL



# FP_PROG_CONTEXT_DIFF
# --------------------
# Figure out how to do context diffs. Sets the output variable ContextDiffCmd.
Expand Down Expand Up @@ -2101,4 +2108,6 @@ AC_DEFUN([MAYBE_OVERRIDE_STAGE0],[
fi
])



# LocalWords: fi
2 changes: 0 additions & 2 deletions compiler/ghc.mk
Expand Up @@ -99,8 +99,6 @@ endif
@echo 'cGhcEnableTablesNextToCode = "$(GhcEnableTablesNextToCode)"' >> $@
@echo 'cLeadingUnderscore :: String' >> $@
@echo 'cLeadingUnderscore = "$(LeadingUnderscore)"' >> $@
@echo 'cRAWCPP_FLAGS :: String' >> $@
@echo 'cRAWCPP_FLAGS = "$(RAWCPP_FLAGS)"' >> $@
@echo 'cGHC_UNLIT_PGM :: String' >> $@
@echo 'cGHC_UNLIT_PGM = "$(utils/unlit_dist_PROG)"' >> $@
@echo 'cGHC_SPLIT_PGM :: String' >> $@
Expand Down
8 changes: 4 additions & 4 deletions compiler/main/SysTools.lhs
Expand Up @@ -235,6 +235,8 @@ initSysTools mbMinusB
-- to make that possible, so for now you can't.
gcc_prog <- getSetting "C compiler command"
gcc_args_str <- getSetting "C compiler flags"
cpp_prog <- getSetting "Haskell CPP command"
cpp_args_str <- getSetting "Haskell CPP flags"
let unreg_gcc_args = if targetUnregisterised
then ["-DNO_REGS", "-DUSE_MINIINTERPRETER"]
else []
Expand All @@ -243,6 +245,7 @@ initSysTools mbMinusB
| mkTablesNextToCode targetUnregisterised
= ["-DTABLES_NEXT_TO_CODE"]
| otherwise = []
cpp_args= map Option (words cpp_args_str)
gcc_args = map Option (words gcc_args_str
++ unreg_gcc_args
++ tntc_gcc_args)
Expand Down Expand Up @@ -285,10 +288,7 @@ initSysTools mbMinusB
-- cpp is derived from gcc on all platforms
-- HACK, see setPgmP below. We keep 'words' here to remember to fix
-- Config.hs one day.
let cpp_prog = gcc_prog
cpp_args = Option "-E"
: map Option (words cRAWCPP_FLAGS)
++ gcc_args
-- Other things being equal, as and ld are simply gcc
gcc_link_args_str <- getSetting "C compiler link flags"
Expand Down
77 changes: 68 additions & 9 deletions configure.ac
Expand Up @@ -34,7 +34,7 @@ fi
AC_SUBST([CONFIGURE_ARGS], [$ac_configure_args])

dnl ----------------------------------------------------------
dnl ** Find unixy sort and find commands,
dnl ** Find unixy sort and find commands,
dnl ** which are needed by FP_SETUP_PROJECT_VERSION

dnl ** Find find command (for Win32's benefit)
Expand Down Expand Up @@ -91,7 +91,7 @@ AC_ARG_WITH([ghc],
WithGhc="$GHC"])

dnl ** Tell the make system which OS we are using
dnl $OSTYPE is set by the operating system to "msys" or "cygwin" or something
dnl $OSTYPE is set by the operating system to "msys" or "cygwin" or something
AC_SUBST(OSTYPE)

AC_ARG_ENABLE(bootstrap-with-devel-snapshot,
Expand Down Expand Up @@ -479,6 +479,64 @@ export CC
MAYBE_OVERRIDE_STAGE0([gcc],[CC_STAGE0])
MAYBE_OVERRIDE_STAGE0([ar],[AR_STAGE0])

dnl ** what cpp to use?
dnl --------------------------------------------------------------
AC_ARG_WITH(hs-cpp,
[AC_HELP_STRING([--with-hs-cpp=ARG],
[Use ARG as the path to cpp [default=autodetect]])],
[
if test "$HostOS" = "mingw32"
then
AC_MSG_WARN([Request to use $withval will be ignored])
else
HaskellCPPCmd=$withval
fi
],
[
if test "$HostOS" != "mingw32"
then
HaskellCPPCmd=$WhatGccIsCalled
fi
]
)



dnl ** what cpp flags to use?
dnl -----------------------------------------------------------
AC_ARG_WITH(hs-cpp-flags,
[AC_HELP_STRING([--with-hs-cpp-flags=ARG],
[Use ARG as the path to hs cpp [default=autodetect]])],
[
if test "$HostOS" = "mingw32"
then
AC_MSG_WARN([Request to use $withval will be ignored])
else
HaskellCPPArgs=$withval
fi
],
[
$HaskellCPPCmd -x c /dev/null -dM -E > conftest.txt 2>&1
if grep "__clang__" conftest.txt >/dev/null 2>&1; then
HaskellCPPArgs="-E -undef -traditional -Wno-invalid-pp-token -Wno-unicode -Wno-trigraphs "
else
$HaskellCPPCmd -v > conftest.txt 2>&1
if grep "gcc" conftest.txt >/dev/null 2>&1; then
HaskellCPPArgs="-E -undef -traditional "
else
$HaskellCPPCmd --version > conftest.txt 2>&1
if grep "cpphs" conftest.txt >/dev/null 2>&1; then
HaskellCPPArgs="--cpp -traditional"
else
AC_MSG_WARN([configure can't recognize your CPP program, you may need to set --with-hs-cpp-flags=FLAGS explicitly])
HaskellCPPArgs=""
fi
fi
fi
]
)


dnl ** Which ld to use?
dnl --------------------------------------------------------------
FP_ARG_WITH_PATH_GNU_PROG([LD], [ld], [ld])
Expand Down Expand Up @@ -991,13 +1049,14 @@ echo ["\
Using $CompilerName : $WhatGccIsCalled
which is version : $GccVersion
Building a cross compiler : $CrossCompiling
ld : $LdCmd
Happy : $HappyCmd ($HappyVersion)
Alex : $AlexCmd ($AlexVersion)
Perl : $PerlCmd
dblatex : $DblatexCmd
xsltproc : $XsltprocCmd
cpp : $HaskellCPPCmd
cpp-flags : $HaskellCPPArgs
ld : $LdCmd
Happy : $HappyCmd ($HappyVersion)
Alex : $AlexCmd ($AlexVersion)
Perl : $PerlCmd
dblatex : $DblatexCmd
xsltproc : $XsltprocCmd
Using LLVM tools
llc : $LlcCmd
Expand Down
59 changes: 59 additions & 0 deletions distrib/configure.ac.in
Expand Up @@ -63,6 +63,65 @@ FIND_GCC([WhatGccIsCalled], [gcc], [gcc])
CC="$WhatGccIsCalled"
export CC


dnl ** what cpp to use?
dnl --------------------------------------------------------------
AC_ARG_WITH(hs-cpp,
[AC_HELP_STRING([--with-hs-cpp=ARG],
[Use ARG as the path to cpp [default=autodetect]])],
[
if test "$HostOS" = "mingw32"
then
AC_MSG_WARN([Request to use $withval will be ignored])
else
HaskellCPPCmd=$withval
fi
],
[
if test "$HostOS" != "mingw32"
then
HaskellCPPCmd=$WhatGccIsCalled
fi
]
)



dnl ** what cpp flags to use?
dnl -----------------------------------------------------------
AC_ARG_WITH(hs-cpp-flags,
[AC_HELP_STRING([--with-hs-cpp-flags=ARG],
[Use ARG as the path to hs cpp [default=autodetect]])],
[
if test "$HostOS" = "mingw32"
then
AC_MSG_WARN([Request to use $withval will be ignored])
else
HaskellCPPArgs=$withval
fi
],
[
$HaskellCPPCmd -x c /dev/null -dM -E > conftest.txt 2>&1
if grep "__clang__" conftest.txt >/dev/null 2>&1; then
HaskellCPPArgs="-E -undef -traditional -Wno-invalid-pp-token -Wno-unicode -Wno-trigraphs "
else
$HaskellCPPCmd -v > conftest.txt 2>&1
if grep "gcc" conftest.txt >/dev/null 2>&1; then
HaskellCPPArgs="-E -undef -traditional "
else
$HaskellCPPCmd --version > conftest.txt 2>&1
if grep "cpphs" conftest.txt >/dev/null 2>&1; then
HaskellCPPArgs="--cpp -traditional"
else
AC_MSG_WARN([configure can't recognize your CPP program, you may need to set --with-hs-cpp-flags=FLAGS explicitly])
HaskellCPPArgs=""
fi
fi
fi
]
)


dnl ** Which ld to use?
dnl --------------------------------------------------------------
FP_ARG_WITH_PATH_GNU_PROG([LD], [ld], [ld])
Expand Down
2 changes: 2 additions & 0 deletions settings.in
Expand Up @@ -2,6 +2,8 @@
("C compiler command", "@SettingsCCompilerCommand@"),
("C compiler flags", "@SettingsCCompilerFlags@"),
("C compiler link flags", "@SettingsCCompilerLinkFlags@"),
("Haskell CPP command","@SettingsHaskellCPPCommand@"),
("Haskell CPP flags","@SettingsHaskellCPPFlags@"),
("ld command", "@SettingsLdCommand@"),
("ld flags", "@SettingsLdFlags@"),
("ld supports compact unwind", "@LdHasNoCompactUnwind@"),
Expand Down

0 comments on commit 34f7e9a

Please sign in to comment.