Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
distclean and per package CFLAGS in portage...
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
Till Varoquaux
n00b
n00b


Joined: 28 Oct 2004
Posts: 24

PostPosted: Wed Nov 10, 2004 11:38 pm    Post subject: distclean and per package CFLAGS in portage... Reply with quote

Browsing on the internet I found this article on how to set up portage so that you could have per packages cflags (/etc/portage/packages.cflags) and to get it to remove the sources from the DIST_DIR once they are finished compilling. This script is great however it had a couple of sytaxe errors. I fiexd those and everything *seems* to be working fine:
Code:


# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# - /etc/portage/bashrc

if [ "$0" = "/usr/lib/portage/bin/ebuild.sh" -o "$0" = "/usr/lib/portage/bin/ebuild-daemon.sh" ]; then

   if [ "${DEBUG}" != "" ]; then
      echo ----------------------------------------------------
      echo \$_=$_
      echo \$\*=$*
      # whatever this was supposed to do it's broken...
      #echo \$<at>=$<at>

      echo PORTDIR=$PORTDIR
      echo CATEGORY=$CATEGORY
      echo PN=$PN
      echo PV=$PV
      echo PR=$PR
      echo PF=$PF
      echo P=$P

      echo USER=$USER
      echo HOME=$HOME
      echo PATH=${PATH}
      echo LD_PRELOAD=${LD_PRELOAD}
      echo ----------------------------------------------------
   fi

   eecho() {
      [ "$NOCOLOR" = "false" ] && echo -ne '\e[1;34m>\e[1;36m>\e[1;35m>\e[0m ' || echo -n ">>> "
      echo "$*"
   }
   
   package-pre-compile() {
      local i af1 af2 flaws audit line s_files
      local save_pwd=$PWD

      PATH=$PATH:/usr/sbin:/usr/bin:/bin:/sbin
      echo "FEATURES=$FEATURES"
      cd ${S} || return 0

      [ -z "${FEATURE_AUDIT_LOGPATH}" ] && export FEATURE_AUDIT_LOGPATH="/var/log/ebuildaudit"
      addwrite ${FEATURE_AUDIT_LOGPATH}
      for audit in flawfinder rats; do
         if [ "`has ${audit} ${FEATURES}`" != "" -a -x /usr/bin/${audit} ]; then
            flaws=""
            case "${audit}" in
               flawfinder)
                  s_files="`find ${S} -name '*.c' -o -name '*.cpp'`"
                  [ -z "${FEATURE_FLAWFINDER_MINLEVEL}" ] && export FEATURE_FLAWFINDER_MINLEVEL=5
               ;;
               rats)
                  s_files="`/usr/bin/find ${S} -name '*.c' -o -name '*.cpp' -o -name '*.php' -o -name '*.pl'`"
                  [ -z "${FEATURE_RATS_WARNLEVEL}" ] && export FEATURE_RATS_WARNLEVEL=1
               ;;
               *) : ;;
            esac
            if [ -n "$s_files" ]; then
               s_count=`echo ${s_files} | tr ' ' '\n' | wc -l | awk '{print $1}'`
               eecho "Running ${audit} on [$s_count] files"
               flaws=""
               [ "${audit}" == "flawfinder" ] &&
                  flaws=$(/usr/bin/flawfinder --quiet --dataonly
--minlevel=${FEATURE_FLAWFINDER_MINLEVEL} ${s_files})
   
               [ "${audit}" == "rats" ] &&
                  flaws=$(/usr/bin/rats --quiet --resultsonly --warning ${FEATURE_RATS_WARNLEVEL} ${s_files})
   
               if [ -n "$flaws" ]; then
                  line="------------------------------------------------------------------------"
                  i=5;echo;while [ $i != 0 ]; do echo -ne ".\a" ; sleep 0.25 ; i=$(($i - 1)) ; done ;echo
                  echo ${line}
                  ewarn "${audit} report for ${PN} on $(date -u)"
                  echo ${line} ; echo -e "${flaws}" ; echo ${line}
                  i=5;echo;while [ $i != 0 ]; do echo -ne ".\a" ; sleep 0.25 ; i=$(($i - 1)) ; done ;echo
                  if [ -d "${FEATURE_AUDIT_LOGPATH}" ]; then
                     af1="${FEATURE_AUDIT_LOGPATH}/${PN}-${PV}_${audit}"
                     af2="${FEATURE_AUDIT_LOGPATH}/${audit}.log"
                     > $af1
                     for a in $af1 $af2 ; do
                        eecho "Saving audit data to $a"
                        echo ${line} >> ${a}
                        echo " * ${audit} report for ${PN} on $(date -u)" >> ${a}
                        echo ${line} >> ${a}
                        echo -e "${flaws}" >> ${a}
                        echo ${line} >> ${a}
                     done
                  fi
               fi
            fi
         fi
      done
      cd ${save_pwd}
   }

   package-distdir-clean() {
      local a x
      for a in ${FEATURES} ; do
         if [ "$a" = "distclean" ]; then
            for x in ${SRC_URI}; do
               x=$(/bin/basename $x)
               if [[ -f $DISTDIR/$x ]]; then
                  size="$(/bin/ls -lh  ${DISTDIR}/${x} | /bin/awk '{print $5}')"
                  eecho "All done with ${x} Removing it to save ${size}"
                  /bin/rm ${DISTDIR}/${x}
               fi
            done
         fi
      done
   }

   append-cflags() {
      export CFLAGS="${CFLAGS} $*"
      export CXXFLAGS="${CXXFLAGS} $*"
      return 0
   }

   package-cflags() {
      local target flags flag i;

      # bail if file does not exist or is not readable.
      [ -r ${ROOT}/etc/portage/package.cflags ] || return 0

      # need bash >= 3
      if [ "${BASH_VERSINFO[0]}" -le 2 ]; then
         eecho "Need bash3 for this bashrc script to work"
         return 0
      fi

      while read -a target; do
         if [[ ${target[ <at> ]%%#*} ]]; then

            # valid syntax no >=<! operators
            # category CFLAGS
            # category/packagename CFLAGS
            if [[ ${target%%#*} && ${target%% *} = "^(${CATEGORY}|${CATEGORY}/${PN})\>" ]]; then
               skip=0
               if [[ ${target} != ${CATEGORY} ]] ; then
                  if [[ ${target} != ${CATEGORY}/${PN} ]] ; then
                     skip=1
                  fi
               fi
               if [ "${skip}" == 0 ] ; then
                  flags=(${target[ <at> ]:1})
                  if [[ ${flags[ <at> ]} = 'CFLAGS' ]]; then
                     for (( i = 0; i < ${#flags[ <at> ]}; i++ )); do
                        if [[ ${flags[$i]} = 'CFLAGS' ]]; then
                           appened-cflags $(eval echo "${flags[$i]}")
                           unset flags[$i]
                        fi
                     done
                  fi
                  for flag in ${flags[ <at> ]}; do
                     if [[ ${CFLAGS} = ${flag} ]]; then
                        continue 1
                     else
                        append-cflags "${flag}"
                     fi
                  done
                  export -n C{,XX}FLAGS
                  eecho "Using package.cflags entry for target ${target} for ${CATEGORY}/${PN}"
               fi
            fi
         fi
      done < ${ROOT}/etc/portage/package.cflags
   }

   case "$*"  in
      # stay really quiet here.
      depend) : ;;
      *)
         if [ "${LD_PRELOAD##*/}" = "libsandbox.so" ]; then
            [ "$NOCOLOR" = "false" ] && i=$(echo -ne '\e[1;32m+\e[0m') || i="+"
         else
            [ "$NOCOLOR" = "false" ] && i=$(echo -ne '\e[1;31m-\e[0m') || i="-"
         fi
         eecho "$USER ${i}sandbox($*)"
         package-cflags

         [ "$*" = "postinst" ] && package-distdir-clean
         [ "$*" = "compile" ] && package-pre-compile
      ;;
   esac
else
   echo "This bashrc does not know anything about $0"
fi

Put this in your /etc/portage/bashrc read the link that is given up here and have some fun.
Note: This is currently NOT to be considered as stable. I won't take any responsibilties if something ever does go wrong.
Back to top
View user's profile Send private message
s0undt3ch
n00b
n00b


Joined: 09 Apr 2005
Posts: 14

PostPosted: Fri May 06, 2005 12:10 pm    Post subject: Reply with quote

I'm getting this error:
Code:
/etc/portage/bashrc: line 133: <at> : syntax error: operand expected (error token is "<at> ")

and it's not using my package.cflags, know why?
_________________
s0undt3ch
The real *nux newbie, one has to admit!!!

[ AMD Athlon @ 1 Ghz / 512 RAM on Gentoo 2005.1 [SERVER] ]
[ P4 @ 2.8 GHz / 1Gig Ram on Gentoo 2005.1/XP ]
Back to top
View user's profile Send private message
s0undt3ch
n00b
n00b


Joined: 09 Apr 2005
Posts: 14

PostPosted: Fri May 06, 2005 12:33 pm    Post subject: Reply with quote

For just/at least CFLAGS per package:
Code:
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# /etc/portage/bashrc

if [ "$0" = "/usr/lib/portage/bin/ebuild.sh" ]; then

   if [ "${DEBUG}" != "" ]; then
      echo ----------------------------------------------------
      echo \$_=$_
      echo \$\*=$*
      echo \$@=$@
      echo \$0=$0


      echo PORTDIR=$PORTDIR
      echo CATEGORY=$CATEGORY
      echo PN=$PN
      echo PV=$PV
      echo PR=$PR
      echo PF=$PF
      echo P=$P

      echo USER=$USER
      echo HOME=$HOME
      echo PATH=${PATH}
      echo LD_PRELOAD=${LD_PRELOAD}
      echo ----------------------------------------------------
   fi

   eecho() {
      [ "$NOCOLOR" = "false" ] && echo -ne '\e[1;34m>\e[1;36m>\e[1;35m>\e[0m ' || echo -n ">>> "
      echo "$*"
   }

   case "$*"  in
      # stay really quiet here.
      depend) : ;;
      *)
         if [ "$(/bin/basename /${LD_PRELOAD})" = "libsandbox.so" ]; then
            eecho "$USER +sandbox($*) $PWD"
         else   
            eecho "$USER -sandbox($*) $PWD"
         fi
         if [ -e ${ROOT}/etc/portage/package.cflags ]; then
            save_IFS
            IFS=$'\n'
            for x in $(/bin/cat ${ROOT}/etc/portage/package.cflags); do
               unset IFS
               x="$(echo $x)"
               IFS=$'\n'
               if [ "${x:0:1}" != "#" ]; then
                  PKG="${x%%[$'\t\n ']*}"
                  if [ "$PKG" == "$CATEGORY/$PN" ]; then
                     export CFLAGS="${x/$PKG/}"
                     eecho "Using package.cflags entry for $PN"
                  fi
               fi
            done
            restore_IFS
         fi

      ;;
   esac
fi


From http://gentoo-wiki.com/TIP_The_/etc/portage/bashrc_file
_________________
s0undt3ch
The real *nux newbie, one has to admit!!!

[ AMD Athlon @ 1 Ghz / 512 RAM on Gentoo 2005.1 [SERVER] ]
[ P4 @ 2.8 GHz / 1Gig Ram on Gentoo 2005.1/XP ]
Back to top
View user's profile Send private message
Cold-Phoenix
n00b
n00b


Joined: 17 Jun 2004
Posts: 24

PostPosted: Sat May 07, 2005 2:28 pm    Post subject: Reply with quote

What about extending this script to support setting other variables on a per package basis, for example setting FEATURE, LDFLAGS and CXXFLAGS, let alone others i havn't thought of or that havn't been invented yet ;).
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum