gcc-plugin.sh 1.1 KB

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