we've had enough ricer bugs for a while...
authorSimon Stelling <blubb@gentoo.org>
Sat, 11 Mar 2006 23:38:30 +0000 (23:38 +0000)
committerSimon Stelling <blubb@gentoo.org>
Sat, 11 Mar 2006 23:38:30 +0000 (23:38 +0000)
this profile.bashrc filters out any flag that isn't recognized by the compiler (will make the -fPIC configure test fail) and spit out a warning. also spit out warnings for the flags that should never get set by the user (-m32, -fPIC, -fvisibility=hidden to name a few)

profiles/default-linux/amd64/profile.bashrc [new file with mode: 0644]

diff --git a/profiles/default-linux/amd64/profile.bashrc b/profiles/default-linux/amd64/profile.bashrc
new file mode 100644 (file)
index 0000000..d67aee6
--- /dev/null
@@ -0,0 +1,65 @@
+getPROG() {
+    local var=$1
+    local prog=$2
+
+    if [[ -n ${!var} ]] ; then
+        echo "${!var}"
+        return 0
+    fi
+
+    local search=
+    [[ -n $3 ]] && search=$(type -p "$3-${prog}")
+    [[ -z ${search} && -n ${CHOST} ]] && search=$(type -p "${CHOST}-${prog}")
+    [[ -n ${search} ]] && prog=${search##*/}
+
+    export ${var}=${prog}
+    echo "${!var}"
+}
+
+hasme() {
+       local x
+
+       local me=$1
+       shift
+       for x in "$@"; do
+               if [ "${x}" == "${me}" ]; then
+               return 0
+       fi
+       done
+       return 1
+}
+
+test_broken_flags() {
+       local mygcc=${1}
+       shift
+       echo 'main(){}' | ${mygcc} ${@} -E - 2>&1 | egrep "unrecognized .*option" \
+               | egrep -o -- '('\''|\"|`)-.*' | sed -r 's/('\''|`|")//g'
+}
+
+if [[ ${EBUILD_PHASE} == "setup" ]]; then
+       trigger=0
+       for flag in ${CFLAGS} ; do
+                broken_flag=$(test_broken_flags $(getPROG CC gcc) ${flag})
+                if [[ -n ${broken_flag} ]]; then
+                       ewarn "Filtering out the non-existing CFLAG \"${broken_flag}\""
+                       CFLAGS=${CFLAGS//${broken_flag}}
+               fi
+       done
+       for flag in ${CXXFLAGS} ; do
+               broken_flag=$(test_broken_flags $(getPROG CXX g++) ${flag})
+               if [[ -n ${broken_flag} ]]; then
+                       ewarn "Filtering out the non-existing CXXFLAG \"${broken_flag}\"" 
+                       CXXFLAGS=${CXXFLAGS//${broken_flag}}
+               fi
+       done
+       for flag in "-fvisibility=hidden" "-fvisibility-hidden" "-fvisibility-inline-hidden" "-fPIC" "-fweb" "-m32" "-m64" "-g3" "-ggdb3" ; do
+               hasme ${flag} ${CFLAGS} ${CXXFLAGS} && trigger=1 && \
+               ewarn "Your C(XX)FLAGS contain(s) \"${flag}\" which can break packages."
+       done
+       if [[ ${trigger} -ge 1 ]]; then
+               ewarn ""
+               ewarn "Before you file a bug please remove these flags and "
+               ewarn "re-compile the package in question as well as all its dependencies"
+       fi
+fi
+unset trigger broken_flag