gcc-plugin.sh 853 B

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