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 <wsc9tt@gmail.com>
This commit is contained in:
Avery Pennarun 2019-02-25 13:09:11 +00:00
commit 1574b11598
5 changed files with 27 additions and 9 deletions

View file

@ -6,9 +6,10 @@ cat >$3 <<-EOF
t="\$1" d="\$2" i="\$3" t="\$1" d="\$2" i="\$3"
IFS="$NL" IFS="$NL"
set -f set -f
\$CC -o "\$t" -c "\$i" \\ \$CC -o "\$t" \\
-MMD -MF "\$d" \\ -MMD -MF "\$d" \\
\$CPPFLAGS \$CFLAGS \$CXXFLAGS \$FLAGS_PCH \$xCFLAGS \$OPTFLAGS \$CPPFLAGS \$CFLAGS \$CXXFLAGS \$FLAGS_PCH \$xCFLAGS \$OPTFLAGS \\
-c "\$i"
EOF EOF
chmod a+x "$3" chmod a+x "$3"
redo-stamp <$3 redo-stamp <$3

View file

@ -31,6 +31,7 @@ cat >$3 <<-EOF
CXXFLAGS= CXXFLAGS=
PCH1=$(shquote "$CFLAGS_PCH") PCH1=$(shquote "$CFLAGS_PCH")
PCH2=$(shquote "$CFLAGS_PCH_FPIC") PCH2=$(shquote "$CFLAGS_PCH_FPIC")
PCH3=$(shquote "$CFLAGS_PCH_LANG")
;; ;;
*) *)
CC=$(shquote "$CXX") CC=$(shquote "$CXX")
@ -39,11 +40,13 @@ cat >$3 <<-EOF
CXXFLAGS=$(shquote "$CXXFLAGS") CXXFLAGS=$(shquote "$CXXFLAGS")
PCH1=$(shquote "$CXXFLAGS_PCH") PCH1=$(shquote "$CXXFLAGS_PCH")
PCH2=$(shquote "$CXXFLAGS_PCH_FPIC") PCH2=$(shquote "$CXXFLAGS_PCH_FPIC")
PCH3=$(shquote "$CXXFLAGS_PCH_LANG")
;; ;;
esac esac
case \$PCH in case \$PCH in
1) FLAGS_PCH=\$PCH1 ;; 1) FLAGS_PCH=\$PCH1 ;;
2) FLAGS_PCH=\$PCH2 ;; 2) FLAGS_PCH=\$PCH2 ;;
3) FLAGS_PCH=\$PCH3 ;;
esac esac
. ./_compile . ./_compile
EOF EOF

View file

@ -116,14 +116,14 @@ case $1 in
;; ;;
*.h.fpic.gch|*.hpp.fpic.gch) *.h.fpic.gch|*.hpp.fpic.gch)
src="$S/${1%.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 # precompiled header is "unchanged" if its component
# headers are unchanged. # headers are unchanged.
cat ${deps#*:} | tee $1.stamp | redo-stamp cat ${deps#*:} | tee $1.stamp | redo-stamp
;; ;;
*.h.gch|*.hpp.gch) *.h.gch|*.hpp.gch)
src="$S/${1%.gch}" src="$S/${1%.gch}"
xCFLAGS="" PCH="" dep="" compile "$@" xCFLAGS="" PCH="3" dep="" compile "$@"
# precompiled header is "unchanged" if its component # precompiled header is "unchanged" if its component
# headers are unchanged. # headers are unchanged.
cat ${deps#*:} | tee $1.stamp | redo-stamp cat ${deps#*:} | tee $1.stamp | redo-stamp

View file

@ -4,13 +4,20 @@ rc_include rc/CC.rc
base="${1#rc/}" base="${1#rc/}"
src="${base%.h.precompiled.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 # The existence of the specific gcc warning about
# precompiled headers is a pretty good indicator # precompiled headers is a pretty good indicator
# that they are supported in the way we expect. # that they are supported in the way we expect.
rc_appendln CFLAGS "-Winvalid-pch" rc_appendln CFLAGS "-Winvalid-pch"
if rc_compile cc nolink; then if rc_compile cc nolink; then
rc_appendln CFLAGS "$x"
rc_appendln CFLAGS_PCH "-include$NL$src.h" rc_appendln CFLAGS_PCH "-include$NL$src.h"
rc_appendln CFLAGS_PCH_FPIC "-include$NL$src.h.fpic" rc_appendln CFLAGS_PCH_FPIC "-include$NL$src.h.fpic"

View file

@ -4,13 +4,20 @@ rc_include rc/CXX.rc
base="${1#rc/}" base="${1#rc/}"
src="${base%.hpp.precompiled.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 # The existence of the specific gcc warning about
# precompiled headers is a pretty good indicator # precompiled headers is a pretty good indicator
# that they are supported in the way we expect. # that they are supported in the way we expect.
appendln CXXFLAGS "-Winvalid-pch" rc_appendln CXXFLAGS "-Winvalid-pch"
if rc_compile cxx nolink; then if rc_compile cxx nolink; then
rc_appendln CXXFLAGS "$x"
rc_appendln CXXFLAGS_PCH "-include$NL$src.hpp" rc_appendln CXXFLAGS_PCH "-include$NL$src.hpp"
rc_appendln CXXFLAGS_PCH_FPIC "-include$NL$src.hpp.fpic" rc_appendln CXXFLAGS_PCH_FPIC "-include$NL$src.hpp.fpic"