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