# Copyright 1999-2006 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.112 2006/11/15 22:17:56 vapier Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.113 2006/11/15 22:46:52 vapier Exp $
#
# Maintainer: base-system@gentoo.org
local newcpu="$#" ; newcpu="${!newcpu}"
while [ $# -gt 1 ] ; do
# quote to make sure that no globbing is done (particularly on
- # ${oldcpu} prior to calling replace-flags
+ # ${oldcpu}) prior to calling replace-flags
replace-flags "-march=${1}" "-march=${newcpu}"
replace-flags "-mcpu=${1}" "-mcpu=${newcpu}"
replace-flags "-mtune=${1}" "-mtune=${newcpu}"
return 0
}
-is-flagq() {
+_is_flagq() {
local x
-
- for x in ${CFLAGS} ${CXXFLAGS} ; do
- # Note this should work with globs like -mcpu=ultrasparc*
- if [[ ${x} == ${1} ]]; then
- return 0
- fi
+ for x in ${!1} ; do
+ [[ ${x} == $2 ]] && return 0
done
return 1
}
+is-flagq() {
+ [[ -n $2 ]] && die "Usage: is-flag <flag>"
+ _is_flagq CFLAGS $1 || _is_flagq CXXFLAGS $1
+}
+
is-flag() {
- if is-flagq ${1}; then
- echo true
- return 0
- fi
- return 1
+ is-flagq "$@" && echo true
}
is-ldflagq() {
- local x
-
- for x in ${LDFLAGS} ; do
- # Note this should work with globs like -mcpu=ultrasparc*
- if [[ ${x} == ${1} ]]; then
- return 0
- fi
- done
- return 1
+ [[ -n $2 ]] && die "Usage: is-ldflag <flag>"
+ _is_flagq LDFLAGS $1
}
is-ldflag() {
- if is-ldflagq ${1}; then
- echo true
- return 0
- fi
- return 1
+ is-ldflagq "$@" && echo true
}
filter-mfpmath() {
shift
- [[ -z ${comp} ]] && \
- return 1
+ [[ -z ${comp} ]] && return 1
+ x=""
for x in "$@" ; do
- test-flag-${comp} "${x}" && flags="${flags} ${x}"
+ test-flag-${comp} "${x}" && flags="${flags}${flags:+ }${x}"
done
echo "${flags}"
}
strip-unsupported-flags() {
- local x NEW_CFLAGS NEW_CXXFLAGS
-
- for x in ${CFLAGS} ; do
- NEW_CFLAGS="${NEW_CFLAGS} $(test-flags ${x})"
- done
- for x in ${CXXFLAGS} ; do
- NEW_CXXFLAGS="${NEW_CXXFLAGS} $(test-flags ${x})"
- done
-
- export CFLAGS=${NEW_CFLAGS}
- export CXXFLAGS=${NEW_CXXFLAGS}
+ export CFLAGS=$(test-flags-CC ${CFLAGS})
+ export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS})
}
get-flag() {
;;
esac
}
+
+
+# Some tests for when we screw with things and want to make
+# sure we didn't break anything
+#TESTS() {
+# CFLAGS="-a -b -c=1"
+# CXXFLAGS="-x -y -z=2"
+# LDFLAGS="-l -m -n=3"
+#
+# die() { exit 1; }
+# (is-flag 1 2 3) && die
+# (is-ldflag 1 2 3) && die
+#
+# is-flagq -l && die
+# is-ldflagq -a && die
+# is-flagq -a || die
+# is-flagq -x || die
+# is-ldflagq -n=* || die
+# is-ldflagq -n && die
+#
+# strip-unsupported-flags
+# [[ ${CFLAGS} == "-c=1" ]] || die
+# [[ ${CXXFLAGS} == "-y -z=2" ]] || die
+#
+# echo "All tests pass"
+#}
+#TESTS