From 1574b11598d4dce42fe174eaf406b6f130db02bb Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Mon, 25 Feb 2019 13:09:11 +0000 Subject: [PATCH] Precompiled headers: supply "-x c-header" or "-x c++-header" if available. Some older versions of gcc give "all.hpp: linker input file unused because linking not done" otherwise, because they don't realize files named *.hpp are headers. Reported-by: Wayne Scott --- redoconf/_compile.od | 5 +++-- redoconf/compile.od | 3 +++ redoconf/default.do.sh | 4 ++-- redoconf/rc/default.h.precompiled.rc.od | 11 +++++++++-- redoconf/rc/default.hpp.precompiled.rc.od | 13 ++++++++++--- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/redoconf/_compile.od b/redoconf/_compile.od index 4a237b9..856a065 100644 --- a/redoconf/_compile.od +++ b/redoconf/_compile.od @@ -6,9 +6,10 @@ cat >$3 <<-EOF t="\$1" d="\$2" i="\$3" IFS="$NL" set -f - \$CC -o "\$t" -c "\$i" \\ + \$CC -o "\$t" \\ -MMD -MF "\$d" \\ - \$CPPFLAGS \$CFLAGS \$CXXFLAGS \$FLAGS_PCH \$xCFLAGS \$OPTFLAGS + \$CPPFLAGS \$CFLAGS \$CXXFLAGS \$FLAGS_PCH \$xCFLAGS \$OPTFLAGS \\ + -c "\$i" EOF chmod a+x "$3" redo-stamp <$3 diff --git a/redoconf/compile.od b/redoconf/compile.od index f379ad8..79363bf 100644 --- a/redoconf/compile.od +++ b/redoconf/compile.od @@ -31,6 +31,7 @@ cat >$3 <<-EOF CXXFLAGS= PCH1=$(shquote "$CFLAGS_PCH") PCH2=$(shquote "$CFLAGS_PCH_FPIC") + PCH3=$(shquote "$CFLAGS_PCH_LANG") ;; *) CC=$(shquote "$CXX") @@ -39,11 +40,13 @@ cat >$3 <<-EOF CXXFLAGS=$(shquote "$CXXFLAGS") PCH1=$(shquote "$CXXFLAGS_PCH") PCH2=$(shquote "$CXXFLAGS_PCH_FPIC") + PCH3=$(shquote "$CXXFLAGS_PCH_LANG") ;; esac case \$PCH in 1) FLAGS_PCH=\$PCH1 ;; 2) FLAGS_PCH=\$PCH2 ;; + 3) FLAGS_PCH=\$PCH3 ;; esac . ./_compile EOF diff --git a/redoconf/default.do.sh b/redoconf/default.do.sh index 76cb10d..56a6b18 100644 --- a/redoconf/default.do.sh +++ b/redoconf/default.do.sh @@ -116,14 +116,14 @@ case $1 in ;; *.h.fpic.gch|*.hpp.fpic.gch) src="$S/${1%.fpic.gch}" - xCFLAGS="-fPIC" PCH="" dep="" compile "$@" + xCFLAGS="-fPIC" PCH="3" dep="" compile "$@" # precompiled header is "unchanged" if its component # headers are unchanged. cat ${deps#*:} | tee $1.stamp | redo-stamp ;; *.h.gch|*.hpp.gch) src="$S/${1%.gch}" - xCFLAGS="" PCH="" dep="" compile "$@" + xCFLAGS="" PCH="3" dep="" compile "$@" # precompiled header is "unchanged" if its component # headers are unchanged. cat ${deps#*:} | tee $1.stamp | redo-stamp diff --git a/redoconf/rc/default.h.precompiled.rc.od b/redoconf/rc/default.h.precompiled.rc.od index 0402169..66f4434 100644 --- a/redoconf/rc/default.h.precompiled.rc.od +++ b/redoconf/rc/default.h.precompiled.rc.od @@ -4,13 +4,20 @@ rc_include rc/CC.rc base="${1#rc/}" src="${base%.h.precompiled.rc}" +# Check whether the compiler supports forcing +# the language type. Some versions of gcc +# need this in order to precompile headers +# named *.hpp. +x="-x${NL}c-header" +if (appendln CFLAGS "$x" && rc_compile cc nolink); then + rc_appendln CFLAGS_PCH_LANG "$x" +fi + # The existence of the specific gcc warning about # precompiled headers is a pretty good indicator # that they are supported in the way we expect. rc_appendln CFLAGS "-Winvalid-pch" if rc_compile cc nolink; then - rc_appendln CFLAGS "$x" - rc_appendln CFLAGS_PCH "-include$NL$src.h" rc_appendln CFLAGS_PCH_FPIC "-include$NL$src.h.fpic" diff --git a/redoconf/rc/default.hpp.precompiled.rc.od b/redoconf/rc/default.hpp.precompiled.rc.od index 41fc712..d6ae4d4 100644 --- a/redoconf/rc/default.hpp.precompiled.rc.od +++ b/redoconf/rc/default.hpp.precompiled.rc.od @@ -4,13 +4,20 @@ rc_include rc/CXX.rc base="${1#rc/}" src="${base%.hpp.precompiled.rc}" +# Check whether the compiler supports forcing +# the language type. Some versions of gcc +# need this in order to precompile headers +# named *.hpp. +x="-x${NL}c++-header" +if (appendln CXXFLAGS "$x" && rc_compile cxx nolink); then + rc_appendln CXXFLAGS_PCH_LANG "$x" +fi + # The existence of the specific gcc warning about # precompiled headers is a pretty good indicator # that they are supported in the way we expect. -appendln CXXFLAGS "-Winvalid-pch" +rc_appendln CXXFLAGS "-Winvalid-pch" if rc_compile cxx nolink; then - rc_appendln CXXFLAGS "$x" - rc_appendln CXXFLAGS_PCH "-include$NL$src.hpp" rc_appendln CXXFLAGS_PCH_FPIC "-include$NL$src.hpp.fpic"