summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2012-01-14 09:10:54 +0000
committerMike Frysinger <vapier@gentoo.org>2012-01-14 09:10:54 +0000
commit36d2806cc512b5eb7cc473dbf94b86cdd946b4e5 (patch)
tree1bb40fd08f41ac0232bebfb99aac3e6b268d74f7 /eclass/flag-o-matic.eclass
parentRemove old versions. (diff)
downloadgentoo-2-36d2806cc512b5eb7cc473dbf94b86cdd946b4e5.tar.gz
gentoo-2-36d2806cc512b5eb7cc473dbf94b86cdd946b4e5.tar.bz2
gentoo-2-36d2806cc512b5eb7cc473dbf94b86cdd946b4e5.zip
unify duplicated lists of variable names and duplicated code blocks, and try to clean up code a bit
Diffstat (limited to 'eclass/flag-o-matic.eclass')
-rw-r--r--eclass/flag-o-matic.eclass140
1 files changed, 52 insertions, 88 deletions
diff --git a/eclass/flag-o-matic.eclass b/eclass/flag-o-matic.eclass
index e30a3a96407d..30bca775efcd 100644
--- a/eclass/flag-o-matic.eclass
+++ b/eclass/flag-o-matic.eclass
@@ -1,6 +1,6 @@
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.166 2012/01/14 08:22:13 vapier Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.167 2012/01/14 09:10:54 vapier Exp $
# @ECLASS: flag-o-matic.eclass
# @MAINTAINER:
@@ -15,6 +15,11 @@ ___ECLASS_ONCE_FLAG_O_MATIC="recur -_+^+_- spank"
inherit eutils toolchain-funcs multilib
+# Return all the flag variables that our high level funcs operate on.
+all-flag-vars() {
+ echo {C,CPP,CXX,F,FC,LD}FLAGS
+}
+
# {C,CXX,F,FC}FLAGS that we allow in strip-flags
# Note: shell globs and character lists are allowed
setup-allowed-flags() {
@@ -80,20 +85,17 @@ _filter-hardened() {
# Strings removed are matched as globs, so for example
# '-O*' would remove -O1, -O2 etc.
_filter-var() {
- local f x VAR VAL
- declare -a new
-
- VAR=$1
+ local f x var=$1 new=()
shift
- eval VAL=\${${VAR}}
- for f in ${VAL}; do
- for x in "$@"; do
+
+ for f in ${!var} ; do
+ for x in "$@" ; do
# Note this should work with globs like -O*
[[ ${f} == ${x} ]] && continue 2
done
- eval new\[\${\#new\[@]}]=\${f}
+ new+=( "${f}" )
done
- eval export ${VAR}=\${new\[*]}
+ eval export ${var}=\""${new[*]}"\"
}
# @FUNCTION: filter-flags
@@ -103,8 +105,8 @@ _filter-var() {
filter-flags() {
_filter-hardened "$@"
local v
- for v in C CPP CXX F FC LD ; do
- _filter-var ${v}FLAGS "$@"
+ for v in $(all-flag-vars) ; do
+ _filter-var ${v} "$@"
done
return 0
}
@@ -188,24 +190,21 @@ append-flags() {
# @DESCRIPTION:
# Replace the <old> flag with <new>. Accepts shell globs for <old>.
replace-flags() {
- [[ $# != 2 ]] \
- && echo && eerror "Usage: replace-flags <old flag> <new flag>" \
- && die "replace-flags takes 2 arguments, not $#"
+ [[ $# != 2 ]] && die "Usage: replace-flags <old flag> <new flag>"
- local f fset
- declare -a new_CFLAGS new_CXXFLAGS new_FFLAGS new_FCFLAGS
-
- for fset in CFLAGS CXXFLAGS FFLAGS FCFLAGS; do
+ local f var new
+ for var in $(all-flag-vars) ; do
# Looping over the flags instead of using a global
# substitution ensures that we're working with flag atoms.
# Otherwise globs like -O* have the potential to wipe out the
# list of flags.
- for f in ${!fset}; do
+ new=()
+ for f in ${!var} ; do
# Note this should work with globs like -O*
[[ ${f} == ${1} ]] && f=${2}
- eval new_${fset}\[\${\#new_${fset}\[@]}]=\${f}
+ new+=( "${f}" )
done
- eval export ${fset}=\${new_${fset}\[*]}
+ eval export ${var}=\""${new[*]}"\"
done
return 0
@@ -243,7 +242,12 @@ _is_flagq() {
# Returns shell true if <flag> is in {C,CXX,F,FC}FLAGS, else returns shell false. Accepts shell globs.
is-flagq() {
[[ -n $2 ]] && die "Usage: is-flag <flag>"
- _is_flagq CFLAGS $1 || _is_flagq CXXFLAGS $1 || _is_flagq FFLAGS $1 || _is_flagq FCFLAGS $1
+
+ local var
+ for var in $(all-flag-vars) ; do
+ _is_flagq ${var} "$1" && return 0
+ done
+ return 1
}
# @FUNCTION: is-flag
@@ -309,77 +313,35 @@ filter-mfpmath() {
# @DESCRIPTION:
# Strip C[XX]FLAGS of everything except known good/safe flags.
strip-flags() {
- local x y flag NEW_CFLAGS NEW_CXXFLAGS NEW_FFLAGS NEW_FCFLAGS
+ local x y var
setup-allowed-flags
- local NEW_CFLAGS=""
- local NEW_CXXFLAGS=""
- local NEW_FFLAGS=""
- local NEW_FCFLAGS=""
-
set -f # disable pathname expansion
- for x in ${CFLAGS}; do
- for y in ${ALLOWED_FLAGS}; do
- flag=${x%%=*}
- if [ "${flag%%${y}}" = "" ] ; then
- NEW_CFLAGS="${NEW_CFLAGS} ${x}"
- break
- fi
+ for var in $(all-flag-vars) ; do
+ local new=()
+
+ for x in ${!var} ; do
+ local flag=${x%%=*}
+ for y in ${ALLOWED_FLAGS} ; do
+ if [[ -z ${flag%%${y}} ]] ; then
+ new+=( "${x}" )
+ break
+ fi
+ done
done
- done
-
- for x in ${CXXFLAGS}; do
- for y in ${ALLOWED_FLAGS}; do
- flag=${x%%=*}
- if [ "${flag%%${y}}" = "" ] ; then
- NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}"
- break
- fi
- done
- done
- for x in ${FFLAGS}; do
- for y in ${ALLOWED_FLAGS}; do
- flag=${x%%=*}
- if [ "${flag%%${y}}" = "" ] ; then
- NEW_FFLAGS="${NEW_FFLAGS} ${x}"
- break
- fi
- done
- done
+ # In case we filtered out all optimization flags fallback to -O2
+ if _is_flagq ${var} "-O*" && ! _is_flagq new "-O*" ; then
+ new+=( -O2 )
+ fi
- for x in ${FCFLAGS}; do
- for y in ${ALLOWED_FLAGS}; do
- flag=${x%%=*}
- if [ "${flag%%${y}}" = "" ] ; then
- NEW_FCFLAGS="${NEW_FCFLAGS} ${x}"
- break
- fi
- done
+ eval export ${var}=\""${new[*]}"\"
done
- # In case we filtered out all optimization flags fallback to -O2
- if [ "${CFLAGS/-O}" != "${CFLAGS}" -a "${NEW_CFLAGS/-O}" = "${NEW_CFLAGS}" ]; then
- NEW_CFLAGS="${NEW_CFLAGS} -O2"
- fi
- if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then
- NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2"
- fi
- if [ "${FFLAGS/-O}" != "${FFLAGS}" -a "${NEW_FFLAGS/-O}" = "${NEW_FFLAGS}" ]; then
- NEW_FFLAGS="${NEW_FFLAGS} -O2"
- fi
- if [ "${FCFLAGS/-O}" != "${FCFLAGS}" -a "${NEW_FCFLAGS/-O}" = "${NEW_FCFLAGS}" ]; then
- NEW_FCFLAGS="${NEW_FCFLAGS} -O2"
- fi
-
set +f # re-enable pathname expansion
- export CFLAGS="${NEW_CFLAGS}"
- export CXXFLAGS="${NEW_CXXFLAGS}"
- export FFLAGS="${NEW_FFLAGS}"
- export FCFLAGS="${NEW_FCFLAGS}"
return 0
}
@@ -497,18 +459,20 @@ strip-unsupported-flags() {
# @DESCRIPTION:
# Find and echo the value for a particular flag. Accepts shell globs.
get-flag() {
- local f findflag="$1"
+ local f var findflag="$1"
# this code looks a little flaky but seems to work for
# everything we want ...
# for example, if CFLAGS="-march=i686":
# `get-flag -march` == "-march=i686"
# `get-flag march` == "i686"
- for f in ${CFLAGS} ${CXXFLAGS} ${FFLAGS} ${FCFLAGS} ; do
- if [ "${f/${findflag}}" != "${f}" ] ; then
- printf "%s\n" "${f/-${findflag}=}"
- return 0
- fi
+ for var in $(all-flag-vars) ; do
+ for f in ${!var} ; do
+ if [ "${f/${findflag}}" != "${f}" ] ; then
+ printf "%s\n" "${f/-${findflag}=}"
+ return 0
+ fi
+ done
done
return 1
}