From 6a38f692991f4c8bc7db9f84b94e8b5f35225a5d Mon Sep 17 00:00:00 2001 From: Stefan Fiedler Date: Fri, 16 Mar 2007 11:54:05 +0000 Subject: [PATCH] Stefan Fiedler: gcc: several small g++-autopch fixes [2007021317442114433] (https://www.rocklinux.net/submaster) git-svn-id: http://www.rocklinux.org/svn/rock-linux/trunk@8260 c5f82cb5-29bc-0310-9cd0-bff59a50e3bc --- package/base/gcc/g++-autopch.sh | 46 +++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/package/base/gcc/g++-autopch.sh b/package/base/gcc/g++-autopch.sh index 5f69efe99..c5bf914d5 100644 --- a/package/base/gcc/g++-autopch.sh +++ b/package/base/gcc/g++-autopch.sh @@ -21,38 +21,50 @@ cxx="${AUTOPCHCXX:-g++}" -cppfile="$( echo "$*" | sed -r 's,.* ([^ ]*\.cpp).*,\1,'; )" -cppargs="$( echo "$*" | sed -r 's, ([^- ]|-[MCSEco])[^ ]*,,g'; )" +[ "$cxx" == "$0" ] && exit 2 -# echo "AutoPCH> $cxx $*" >&2 -# echo "AutoPCH - cppfile> $cppfile" >&2 -# echo "AutoPCH - cppargs> $cppargs" >&2 +cppfile="$( echo " $* " | sed -r 's,((.* )([^ ]*\.(cc|cp|cpp|CPP|cxx|c\+\+|C))) .*,\3,' )" +cppdir="$( echo "$cppfile" | sed -r 's,[^/]*$,,'; )" +cppargs="$( echo " $* " | sed -r 's, ([^- ]|-[MCSEco])[^ ]*,,g'; )" -if [ ".$cppfile" == ".$*" ]; then +echo "AutoPCH> $cxx $*" >&2 +echo "AutoPCH - cppargs> \"$cppargs\"" >&2 +echo "AutoPCH - cppdir, cppfile> \"$cppdir\", \"$cppfile\"" >&2 + +if [ ! -f "$cppfile" ]; then exec $cxx "$@" exit 1 fi -if [ ! -f autopch.h -a ! -f autopch_oops.h ]; then +autopch="$cppdir${cppdir:+/}autopch" +if [ ! -f "${autopch}.h" -a ! -f "${autopch}_oops.h" ]; then { echo "#ifndef _AUTOPCH_H_" echo "#define _AUTOPCH_H_" echo "#warning AutoPCH: THEWARNING" - [ -f autopch_incl.h ] && cat autopch_incl.h - egrep -h '^#(include.*\.h[">]|if|endif|define.*[^\\]$|undef)' *.cpp | \ - egrep -v "[<\"](${AUTOPCHEXCL:-autopch.h})[\">]" + [ -f "${autopch}_incl.h" ] && cat "${autopch}_incl.h" + sed -r '/^( | )*#( | )*(include|if|endif|define|undef)/ { + : label /\\$/ { N ; P ; b label ; } ; p + } ; d' "$cppdir"${cppdir:+/}*.{cc,cp,cpp,CPP,cxx,c++,C} 2&>1 +# \ +# | egrep -v "[<\"](${AUTOPCHEXCL:-autopch.h})[\">]" echo "#endif /* _AUTOPCH_H_ */" - } > autopch.h.plain - sed 's,THEWARNING,New pre-compiled header.,' < autopch.h.plain > autopch.h - echo "exec $cxx -I. $cppargs -x c++ -c autopch.h" > autopch.sh - if ! sh autopch.sh; then mv -f autopch.h autopch_oops.h; fi - sed 's,THEWARNING,Pre-compiled header not used!,' < autopch.h.plain > autopch.h + } > "${autopch}.h.plain" + sed 's,THEWARNING,New pre-compiled header.,' \ + < "${autopch}.h.plain" > "${autopch}.h" + # Precompile the autopch.h file + echo "exec $cxx -I. $cppargs -x c++ -c \"${autopch}.h\"" \ + > "${autopch}.sh" + if ! sh "${autopch}.sh" ; then + mv -f "${autopch}.h" "${autopch}_oops.h" + fi + sed 's,THEWARNING,Pre-compiled header not used!,' \ + < "${autopch}.h.plain" > "${autopch}.h" fi -if ! test -f autopch.h || ! $cxx -include autopch.h "$@"; then +if test -f ${autopch}.h && ! $cxx -include ${autopch}.h "$@"; then echo "AutoPCH: Fallback to non pre-compiled headers!" >&2 exec $cxx "$@" exit 1 fi exit 0 -