gcc-plugin.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. srctree=$(dirname "$0")
  3. SHOW_ERROR=
  4. if [ "$1" = "--show-error" ] ; then
  5. SHOW_ERROR=1
  6. shift || true
  7. fi
  8. gccplugins_dir=$($3 -print-file-name=plugin)
  9. plugincc=$($1 -E -x c++ - -o /dev/null -I"${srctree}"/gcc-plugins -I"${gccplugins_dir}"/include 2>&1 <<EOF
  10. #include "gcc-common.h"
  11. #if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
  12. #warning $2 CXX
  13. #else
  14. #warning $1 CC
  15. #endif
  16. EOF
  17. )
  18. if [ $? -ne 0 ]
  19. then
  20. if [ -n "$SHOW_ERROR" ] ; then
  21. echo "${plugincc}" >&2
  22. fi
  23. exit 1
  24. fi
  25. case "$plugincc" in
  26. *"$1 CC"*)
  27. echo "$1"
  28. exit 0
  29. ;;
  30. *"$2 CXX"*)
  31. # the c++ compiler needs another test, see below
  32. ;;
  33. *)
  34. exit 1
  35. ;;
  36. esac
  37. # we need a c++ compiler that supports the designated initializer GNU extension
  38. plugincc=$($2 -c -x c++ -std=gnu++98 - -fsyntax-only -I"${srctree}"/gcc-plugins -I"${gccplugins_dir}"/include 2>&1 <<EOF
  39. #include "gcc-common.h"
  40. class test {
  41. public:
  42. int test;
  43. } test = {
  44. .test = 1
  45. };
  46. EOF
  47. )
  48. if [ $? -eq 0 ]
  49. then
  50. echo "$2"
  51. exit 0
  52. fi
  53. if [ -n "$SHOW_ERROR" ] ; then
  54. echo "${plugincc}" >&2
  55. fi
  56. exit 1