Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
CFLAGS tool (query and re-compile pkgs based on CFLAGS)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
dreamer3
Guru
Guru


Joined: 24 Sep 2002
Posts: 553

PostPosted: Tue Dec 10, 2002 7:45 am    Post subject: CFLAGS tool (query and re-compile pkgs based on CFLAGS) Reply with quote

Ok, I've been meaning to upload this for a while, but just didn't get around to it until now. Every since I started with Gentoo until about a month ago I kept changing my CFLAGS all the time, and of course compiling things as i went with all different flags.

Well, the question has been asked, and I myself wondered... how do I only compile packages that haven't ALREADY been compiled with my existing CFLAGS? Or, how can I automatically re-compile all the packages I've compiled with -O3 to -O2 (my current pref). Going from -O3 to -O2 was my biggest push...

I wrote my own answer... try running it with no parameters to get the built in help... please provide feedback, thoughts, constructive critism, bug reports, etc... and let me know if you find this useful.

qcflags (http://elektron.its.tudelft.nl/~piguil09/cflags)
Code:
#!/bin/bash

source /etc/make.conf

NO="\x1b[0;0m"
BR="\x1b[0;01m"
CY="\x1b[36;01m"
RD="\x1b[31;01m"
GR="\x1b[32;01m"
YL="\x1b[33;01m"
BL="\x1b[34;01m"

T="\t"

verb=0
group="*"

if [ ${#} -eq 0 ]; then
   usage=y;
fi

while [ ${#} -gt 0 ]
do
   a=${1}
   shift
   case "${a}" in

   -h|--help)
      usage=y
      break
      ;;

   -p|--pretend)
      emerge_pretend=y;
      ;;

   --flags)
      filter_flags=$1
      shift
      ;;

   --emerge)
      emerge_go=y;
      ;;

   -f|--fetch)
      fetch=y
      ;;

   -g|--group)
      group=$1
      shift
      ;;

   -l|--list)
      list=y;
      ;;

   -n|--nice)
      nice=nice
      ;;

   -v|--verbose)
      let $((verb++))
      ;;

   -vv)
      let $((verb++))
      let $((verb++))
      ;;

   -nc|--no-color|--nocolor|--no-colors|--nocolors)
      nocolor=y
      ;;

   -*)
      echo -e ${CY}${PROG}${NO}:${YL} Invalid option ${RD}$a 1>&2
      usage=y
      break
      ;;
   *)
      if [ -n "${arg}" ]; then
         echo -e ${CY}${PROG}: ${YL}Only one argument supported
         usage=y
         break
      fi
      # Kill a trailing slash
      arg=${a%/}
      ;;

   esac
done

if [ "${usage}" ]; then
   echo -e "${CY}qcflags v0.10${NO}

${CY}qcflags${NO} is a tool that allows you to query packages
based on the CFLAGS with which they were compiled and re-emerge
packages based on this criteria.

${BR}Usage:
${T}${CY}${PROG}${NO} [${BR}options${NO}] [${YL}pkgname${NO}] [${BL}-g${YL} group${NO}]${NO} [${BL}--flags${YL} cflags${NO}]
${T}${CY}${PROG}${NO} ${BL}--help${NO}

${BR}Queries:
  ${BL}-g,  --group${NO}${T}${T}Find by group (can be combined with other searches)
  ${BL}--flags${NO}${T}${T}Find based upon the CFLAGS used to compile

${BR}Actions:
  ${BL}-l,  --list${NO}${T}${T}list packages
  ${BL}-p,  --pretend${NO}${T}emerge --pretend the selected packages
  ${BL}-f,  --fetch${NO}${T}${T}emerge --fetch the selected packages
  ${BL}--emerge${NO}${T}${T}emerge the selected packages
  ${BL}-n,  --nice${NO}${T}${T}use nice to execute the above

${BR}Modifiers:"
#  ${BL}-nc, --no-color${NO}${T}don't use colors
echo -e "  ${BL}-v,  --verbose${NO}${T}Be more verbose [ can be repeated twice ]
  ${BL}-vv${NO}${T}${T}${T}Same as ${BL}-v -v${NO}

${YL}Notes${NO}:
  Some packages modify your custom CFLAGS for improved stability. It may
  not be possible to get ${BR}_every_${NO} package on your system compiled
  with your exact CFLAGS.

${YL}Examples${NO}:
  ${PROG} -l      list packages not compiled with current CFLAGS
  ${PROG} -v      same as above, but show the CFLAGS used to compile
  ${PROG} -vv      \"\", but show pkgs compiled with current CFLAGS as well
  ${PROG} -g sys-apps   show only packages in the sys-apps group
  ${PROG} bash      show only packages that match \"bash\"

  ${PROG} --flags O3   show only pacakges compiled with O3 in the CFLAGS
"
   exit
fi

if [[ ! ${emerge_pretend} && ! ${emerge_go} ]]; then
   list=y
fi

echo -e "${BR}Your currently set CFLAGS are: ${NO}"
echo -e ${CFLAGS}
#echo

if [ ${list} ];then
   echo
   echo -e "${BR}Packages needed re-emerging...${NO}"
fi

ipak=`find /var/db/pkg -iname *.ebuild`

if [ ${arg} ]; then
   ipak=`echo ${ipak} | sed -e "s: :\n:g" | grep ${arg}`
fi


if [ "${group}" != "*" ]; then
   ipak=`echo ${ipak} | sed -e "s: :\n:g" | grep ${group}`
fi

for p in ${ipak};do
   n=${p%.ebuild}
   var_db_pkg="/var/db/pkg/"
   n=${n/${var_db_pkg}/}
   n=${n/\/*\//\/}
   read p_cflags < /var/db/pkg/${n}/CFLAGS
   
   # remove the includes and other stuff that are added by some builds
   p_cflags=${p_cflags%% -I*}
   p_cflags=${p_cflags/ -Wno-deprecated/}
   # remove -g from end od gnome-common build
   [ "${n#gnome-base/gnome-common}" ] && p_cflags=${p_cflags/ -g/}

#echo "${n} ... ${CFLAGS} == ${p_cflags}"
   if [ "${CFLAGS}" != "${p_cflags}" ]; then
      if [[ -z "${filter_flags}" || "${p_cflags/${filter_flags}/}" != "${p_cflags}" ]] ; then
         [ ${list} ] &&   echo -en "${YL}${n}${NO}"
         # add it to the list of builds to be emerged
         nv=`echo ${n} | sed -e "s:-r[0-9]\+$::" -e "s:-[0-9][^-]*$::"`
#         echo ${nv}
         nv="^${nv}$"
         in_world=`cat /var/cache/edb/world | grep ${nv}`
         if [ "${in_world}" ]; then
            world="${world} =${n}"
         else
            depen="${depen} =${n}"
         fi
         # if we're in verbose mode, show the cflags
         if [[ ${list} && ${verb} -gt 0 ]]; then
            echo ":"${p_cflags};
         elif [ ${list} ]; then
            echo
         fi
      elif [[ ${list} && ${verb} -gt 1 ]]; then
         echo -en ${CY}${n}${NO}
         echo ":"${p_cflags};
      fi
   else
      if [[ ${list} && ${verb} -gt 1 ]]; then
         echo -e ${GR}${n}${NO}
      fi
   fi
done

if [ ${verb} -gt 0 ]; then
   echo
fi

# if pretend re-emerge
if [ ${emerge_pretend} ]; then
   echo -e "${BR}Suggested Dependencies:${NO}"
   if [ "${depen}" ]; then
      command="emerge -p --oneshot ${depen}"
      ${command}
   else
      echo -e "${YL}No dependencies found.${NO}"
   fi

   echo -e "${BR}Suggested World:${NO}"
   if [ "${world}" ]; then
      command="emerge -p ${world}"
      ${command}
   else
      echo -e "${YL}No packages found for world.${NO}"
      echo
   fi
fi

# if fetch
if [ ${fetch} ]; then
   if [ "${depen}" ]; then
      ${nice} emerge -f ${depen}
   fi
   if [ "${world}" ]; then
      ${nice} emerge -f ${world}
   fi
fi

# if real emerge
if [ ${emerge_go} ]; then
   if [ "${depen}" ]; then
      ${nice} emerge --oneshot ${depen}
   fi
   if [ "${world}" ]; then
      ${nice} emerge ${world}
   fi
fi


Last edited by dreamer3 on Thu Jan 02, 2003 4:44 pm; edited 1 time in total
Back to top
View user's profile Send private message
smart
Guru
Guru


Joined: 19 Nov 2002
Posts: 455

PostPosted: Tue Dec 10, 2002 6:13 pm    Post subject: Reply with quote

i suggest adding this cutie to the gentoolkit
Back to top
View user's profile Send private message
dreamer3
Guru
Guru


Joined: 24 Sep 2002
Posts: 553

PostPosted: Wed Dec 11, 2002 12:11 am    Post subject: Reply with quote

smart wrote:
i suggest adding this cutie to the gentoolkit

Fine by me. I'd be happy to officially maintain it as long as I can. I have a few ideas for improvements, but it currently does all I need. Though I'd be happy to add features based on suggestions of others.

I've always wanted a little proggy to maintain even if it isn't much...
Back to top
View user's profile Send private message
JohnY
Guru
Guru


Joined: 26 Jul 2002
Posts: 305

PostPosted: Wed Dec 11, 2002 1:58 am    Post subject: cflags -O3 to -02 Reply with quote

dreamer3,

If you don't mind my asking what prompted your descision to go from -O3 to -O2 and what gcc version are you using?

Thanks,

JohnY
Back to top
View user's profile Send private message
dreamer3
Guru
Guru


Joined: 24 Sep 2002
Posts: 553

PostPosted: Wed Dec 11, 2002 3:18 am    Post subject: Re: cflags -O3 to -02 Reply with quote

JohnY wrote:
If you don't mind my asking what prompted your descision to go from -O3 to -O2 and what gcc version are you using?

Using 3.2.1 now, just upgraded from 3.2... I decided that I didn't think gcc was making smart decisions with regard to inlining functions... to I went back to O2... system seems snappier.
Back to top
View user's profile Send private message
phong
Bodhisattva
Bodhisattva


Joined: 16 Jul 2002
Posts: 778
Location: Michigan - 15 & Ryan

PostPosted: Wed Dec 11, 2002 4:01 am    Post subject: Reply with quote

This is a tip rather than a support question, so I'm moving it to Documentation, Tips & Tricks from Portage and Programming.
_________________
"An empty head is not really empty; it is stuffed with rubbish. Hence the difficulty of forcing anything into an empty head."
-- Eric Hoffer
Back to top
View user's profile Send private message
BlackBart
Apprentice
Apprentice


Joined: 07 Oct 2002
Posts: 252

PostPosted: Thu Dec 26, 2002 9:07 pm    Post subject: Reply with quote

can you attatch the script, i seem to be having trouble copying and pasting it into a text editor.
Back to top
View user's profile Send private message
idl
Retired Dev
Retired Dev


Joined: 24 Dec 2002
Posts: 1728
Location: Nottingham, UK

PostPosted: Thu Dec 26, 2002 9:27 pm    Post subject: Reply with quote

dreamer3, why not try -Os its basicly the same as -O2 but has a few flags to make binarys smaller.
Back to top
View user's profile Send private message
dreamer3
Guru
Guru


Joined: 24 Sep 2002
Posts: 553

PostPosted: Tue Dec 31, 2002 4:57 am    Post subject: Reply with quote

port001 wrote:
dreamer3, why not try -Os its basicly the same as -O2 but has a few flags to make binarys smaller.

I'm happy with O2 for now...

wrote:
can you attatch the script, i seem to be having trouble copying and pasting it into a text editor.

You can't "attach" files on this forum. You'll just have to try cutting and pasting again... sorry.
Back to top
View user's profile Send private message
H-Pi
Apprentice
Apprentice


Joined: 26 Jun 2002
Posts: 175
Location: Delft (NL)

PostPosted: Thu Jan 02, 2003 12:11 am    Post subject: Reply with quote

BlackBart: http://elektron.its.tudelft.nl/~piguil09/cflags (I wonder why you're not able to cut'n'paste though)
Back to top
View user's profile Send private message
BlackBart
Apprentice
Apprentice


Joined: 07 Oct 2002
Posts: 252

PostPosted: Thu Jan 02, 2003 3:21 am    Post subject: Reply with quote

i can copy and paste, my problem is that i get funny characters at the end of each line (^M) causing the script not to work.
Back to top
View user's profile Send private message
Forse
Apprentice
Apprentice


Joined: 26 Dec 2002
Posts: 260
Location: /dev/random

PostPosted: Tue Jan 07, 2003 7:45 am    Post subject: Nice Reply with quote

A very nice script I must say :D But I am a little confused...I tied to use script with -l argument and it it showed that my current flags are:
Code:
-march=athlon-xp -mcpu=athlon-xp -O3 -pipe


even I have this line in my make.conf:
Code:
CFLAGS="-march=athlon-xp -O3 -pipe -msse -m3dnow -m3dnowext  -fomit-frame-pointer  -fforce-addr  -frerun-cse-after-loop -frerun-loop-opt -malign-functions=4 -
mmmx -mfpmath=fpu  -maccumulate-outgoing-args"


I know that it's not your script problem, but...anyway could you help me? Where should I make changes?

Thnx in advance
_________________
[ My sites ]: UnixTutorials : AniFIND : AnimeYume
Back to top
View user's profile Send private message
dreamer3
Guru
Guru


Joined: 24 Sep 2002
Posts: 553

PostPosted: Tue Jan 07, 2003 9:29 am    Post subject: Re: Nice Reply with quote

Forse wrote:
A very nice script I must say :D But I am a little confused...I tied to use script with -l argument and it it showed that my current flags are:
Code:
-march=athlon-xp -mcpu=athlon-xp -O3 -pipe


even I have this line in my make.conf:
Code:
CFLAGS="-march=athlon-xp -O3 -pipe -msse -m3dnow -m3dnowext  -fomit-frame-pointer  -fforce-addr  -frerun-cse-after-loop -frerun-loop-opt -malign-functions=4 -
mmmx -mfpmath=fpu  -maccumulate-outgoing-args"

There is no fancy logic to detect your CFLAGS, it simple sources (includes) your make.conf file at the top of the script and then it prints the value of CFLAGS... check to make sure your make.conf isn't defining CFLAGS twice and it's the latter one that qcflags is printing (and all your programs are using to compile).
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks 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