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