mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.6 KiB

  1. #!/bin/bash
  2. #
  3. # AutoPCH: Automatically use pre-compiled headers
  4. #
  5. # Simply use this script instead of calling g++ directly.
  6. # This is a dirty hack. So don't wonder if it does not work
  7. # out of the box with every package.
  8. #
  9. # example using kdegames:
  10. # -----------------------
  11. #
  12. # time make CXX="autopch"
  13. # real 30m41.945s
  14. # user 25m30.924s
  15. # sys 3m9.300s
  16. #
  17. # without autopch:
  18. # real 42m59.061s
  19. # user 36m50.630s
  20. # sys 2m41.806s
  21. cxx="${AUTOPCHCXX:-g++}"
  22. cppfile="$( echo "$*" | sed -r 's,.* ([^ ]*\.cpp).*,\1,'; )"
  23. cppargs="$( echo "$*" | sed -r 's, ([^- ]|-[MCSEco])[^ ]*,,g'; )"
  24. # echo "AutoPCH> $cxx $*" >&2
  25. # echo "AutoPCH - cppfile> $cppfile" >&2
  26. # echo "AutoPCH - cppargs> $cppargs" >&2
  27. if [ ".$cppfile" == ".$*" ]; then
  28. exec $cxx "$@"
  29. exit 1
  30. fi
  31. if [ ! -f autopch.h -a ! -f autopch_oops.h ]; then
  32. {
  33. echo "#ifndef _AUTOPCH_H_"
  34. echo "#define _AUTOPCH_H_"
  35. echo "#warning AutoPCH: THEWARNING"
  36. [ -f autopch_incl.h ] && cat autopch_incl.h
  37. egrep -h '^#(include.*\.h[">]|if|endif|define.*[^\\]$|undef)' *.cpp | \
  38. egrep -v "[<\"](${AUTOPCHEXCL:-autopch.h})[\">]"
  39. echo "#endif /* _AUTOPCH_H_ */"
  40. } > autopch.h.plain
  41. sed 's,THEWARNING,New pre-compiled header.,' < autopch.h.plain > autopch.h
  42. echo "exec $cxx -I. $cppargs -x c++ -c autopch.h" > autopch.sh
  43. if ! sh autopch.sh; then mv -f autopch.h autopch_oops.h; fi
  44. sed 's,THEWARNING,Pre-compiled header not used!,' < autopch.h.plain > autopch.h
  45. fi
  46. if ! test -f autopch.h || ! $cxx -include autopch.h "$@"; then
  47. echo "AutoPCH: Fallback to non pre-compiled headers!" >&2
  48. exec $cxx "$@"
  49. exit 1
  50. fi
  51. exit 0