Gentoo Archives: gentoo-dev

From: Mike Gilbert <floppym@g.o>
To: gentoo-dev@l.g.o
Cc: toolchain@g.o
Subject: [gentoo-dev] [PATCH] flag-o-matic.eclass: treat "--param x" as a unit when testing flags
Date: Fri, 13 Apr 2018 16:21:58
Message-Id: 20180413162147.18340-1-floppym@gentoo.org
1 For clang and gcc, --param consumes the next argument. Testing --param
2 and its value separately is nonsensical.
3 ---
4 eclass/flag-o-matic.eclass | 33 +++++++++++++++++++++++----------
5 eclass/tests/flag-o-matic.sh | 4 ++--
6 2 files changed, 25 insertions(+), 12 deletions(-)
7
8 diff --git a/eclass/flag-o-matic.eclass b/eclass/flag-o-matic.eclass
9 index 14b84fbdbebe..5ab14b08d6ec 100644
10 --- a/eclass/flag-o-matic.eclass
11 +++ b/eclass/flag-o-matic.eclass
12 @@ -421,9 +421,9 @@ strip-flags() {
13 test-flag-PROG() {
14 local comp=$1
15 local lang=$2
16 - local flag=$3
17 + shift 2
18
19 - [[ -z ${comp} || -z ${flag} ]] && return 1
20 + [[ -z ${comp} || -z $1 ]] && return 1
21
22 local cmdline=(
23 $(tc-get${comp})
24 @@ -434,11 +434,11 @@ test-flag-PROG() {
25 -c -o /dev/null
26 )
27 if "${cmdline[@]}" -x${lang} - </dev/null &>/dev/null ; then
28 - cmdline+=( "${flag}" -x${lang} - )
29 + cmdline+=( "$@" -x${lang} - )
30 else
31 # XXX: what's the purpose of this? does it even work with
32 # any compiler?
33 - cmdline+=( "${flag}" -c -o /dev/null /dev/null )
34 + cmdline+=( "$@" -c -o /dev/null /dev/null )
35 fi
36
37 if ! "${cmdline[@]}" </dev/null &>/dev/null; then
38 @@ -455,25 +455,25 @@ test-flag-PROG() {
39 # @USAGE: <flag>
40 # @DESCRIPTION:
41 # Returns shell true if <flag> is supported by the C compiler, else returns shell false.
42 -test-flag-CC() { test-flag-PROG "CC" c "$1"; }
43 +test-flag-CC() { test-flag-PROG "CC" c "$@"; }
44
45 # @FUNCTION: test-flag-CXX
46 # @USAGE: <flag>
47 # @DESCRIPTION:
48 # Returns shell true if <flag> is supported by the C++ compiler, else returns shell false.
49 -test-flag-CXX() { test-flag-PROG "CXX" c++ "$1"; }
50 +test-flag-CXX() { test-flag-PROG "CXX" c++ "$@"; }
51
52 # @FUNCTION: test-flag-F77
53 # @USAGE: <flag>
54 # @DESCRIPTION:
55 # Returns shell true if <flag> is supported by the Fortran 77 compiler, else returns shell false.
56 -test-flag-F77() { test-flag-PROG "F77" f77 "$1"; }
57 +test-flag-F77() { test-flag-PROG "F77" f77 "$@"; }
58
59 # @FUNCTION: test-flag-FC
60 # @USAGE: <flag>
61 # @DESCRIPTION:
62 # Returns shell true if <flag> is supported by the Fortran 90 compiler, else returns shell false.
63 -test-flag-FC() { test-flag-PROG "FC" f95 "$1"; }
64 +test-flag-FC() { test-flag-PROG "FC" f95 "$@"; }
65
66 test-flags-PROG() {
67 local comp=$1
68 @@ -484,8 +484,21 @@ test-flags-PROG() {
69
70 [[ -z ${comp} ]] && return 1
71
72 - for x ; do
73 - test-flag-${comp} "${x}" && flags+=( "${x}" )
74 + while (( $# )); do
75 + case "$1" in
76 + --param)
77 + if test-flag-${comp} "$1" "$2"; then
78 + flags+=( "$1" "$2" )
79 + fi
80 + shift 2
81 + ;;
82 + *)
83 + if test-flag-${comp} "$1"; then
84 + flags+=( "$1" )
85 + fi
86 + shift 1
87 + ;;
88 + esac
89 done
90
91 echo "${flags[*]}"
92 diff --git a/eclass/tests/flag-o-matic.sh b/eclass/tests/flag-o-matic.sh
93 index 53af9f862c41..97cd71d710a2 100755
94 --- a/eclass/tests/flag-o-matic.sh
95 +++ b/eclass/tests/flag-o-matic.sh
96 @@ -6,7 +6,7 @@ source tests-common.sh
97
98 inherit flag-o-matic
99
100 -CFLAGS="-a -b -c=1"
101 +CFLAGS="-a -b -c=1 --param l1-cache-size=32"
102 CXXFLAGS="-x -y -z=2"
103 LDFLAGS="-l -m -n=3"
104 ftend() {
105 @@ -55,7 +55,7 @@ done <<<"
106
107 tbegin "strip-unsupported-flags"
108 strip-unsupported-flags
109 -[[ ${CFLAGS} == "" ]] && [[ ${CXXFLAGS} == "-z=2" ]] && [[ ${LDFLAGS} == "" ]]
110 +[[ ${CFLAGS} == "--param l1-cache-size=32" ]] && [[ ${CXXFLAGS} == "-z=2" ]] && [[ ${LDFLAGS} == "" ]]
111 ftend
112
113 for var in $(all-flag-vars) ; do
114 --
115 2.17.0.rc2

Replies