View previous topic :: View next topic |
Author |
Message |
Imak n00b
Joined: 07 Feb 2008 Posts: 29
|
Posted: Thu Sep 03, 2009 9:32 pm Post subject: Help with scripting bashrc to allow for package c & ld f |
|
|
Greetings,
Novice here looking to tailor a script for personal usage.
Situation: I'm testing out using both the ICC and GNU compilers and want to compile programs default ICC and use the GNU when necessary. Found a little script in the Wiki's with the following:
Code: |
# /etc/portage/bashrc
export GCC=${OCC}
export GCXX=${OCXX}
export OCC="icc"
export OCXX="icpc"
export CFLAGS=${ICCCFLAGS}
export CXXFLAGS=${ICCCXXFLAGS}
[ -r ${ROOT}/etc/portage/package.gcc ] || return 0
while read -a target; do
if [ "${target}" = "${CATEGORY}/${PN}" ]; then
export OCC=${GCC}
export OCXX=${GCXX}
export CFLAGS="$flags"
export CXXFLAGS="$CFLAGS"
if [ -r ${ROOT}/etc/portage/package.gcc-cflags ]; then
while read target flags; do
if [ "${target}" = "${CATEGORY}/${PN}" ]; then
export CFLAGS="$flags"
export CXXFLAGS="$CFLAGS"
break
fi
done < ${ROOT}/etc/portage/package.gcc-cflags
fi
break
fi
done < ${ROOT}/etc/portage/package.gcc
if [ -r ${ROOT}/etc/portage/package.icc-cflags ]; then
while read target flags; do
if [ "${target}" = "${CATEGORY}/${PN}" ]; then
export CFLAGS="$flags"
export CXXFLAGS="$CFLAGS"
break
fi
done < ${ROOT}/etc/portage/package.icc-cflags
fi
if [ "${OCC}" != "" ]; then
export CC_FOR_BUILD="${OCC}" #workaround gcc detection function in toolchain-funcs.eclass
fi
unset GCC
unset GCXX
|
The problem I think is two fold.
1) When a package is listed in 'package.gcc' and if the flags are not set in 'package.gcc-cflags' the package is stripped of all C, CXX, LD (since I believe the ICC Flags over wrote them, and when switched back the script fails to restore the defaults) thus when portage goes to compile the program it doesn't default to the settings found in make.conf. Can someone please inform me what the variable names are for the globally declared C, CXX, LD flags portage uses? Or how to properly reference the variables from make.conf?
2) I'm attempting to modify the script to include per package LDflags by adding a mirroring code segment as follows:
Code: |
# export LDFLAGS = "$ldflags" define along with the other variables during the GNU compiler switch
# the following would take place within the 'if [ -r ${ROOT}/etc/portage/package.gcc-cflags ]' statement
if [ -r ${ROOT}/etc/portage/package.gcc-ldflags ]; then
while read target ldflags; do
if [ "${target}" = "${CATEGORY}/${PN}" ]; then
export LDFLAGS="$ldflags"
break
fi
done < ${ROOT}/etc/portage/package.gcc-ldflags
|
Even though I think this code segment allows users to set per package ldflags, I think it also overrides the desired programs 'native' settings, thus when the flags are issued in 'package.gcc-ldflags' it prevents compiling. But, I don't understand why the default settings would change and not just the ldflags.
Any help would be most appreciated. |
|
Back to top |
|
|
Imak n00b
Joined: 07 Feb 2008 Posts: 29
|
Posted: Thu Sep 03, 2009 9:53 pm Post subject: Silly me. |
|
|
After writing this post I realized that I could probably first 'save' the default values in variables and just recall those during the compiler switch.
I'm not to familiar with this scripts syntax but I assume (hopefully) the following will solve problem #1. (I apologize for asking and not testing.)
Code: |
export GCC=${OCC}
export GCXX=${OCXX}
export OCC="icc"
export OCXX="icpc"
export DefaultCflags=${CFLAGS}
export DefaultLdflags=${LDFLAGS}
export CFLAGS=${ICCCFLAGS}
export CXXFLAGS=${ICCCXXFLAGS}
[ -r ${ROOT}/etc/portage/package.gcc ] || return 0
while read -a target; do
if [ "${target}" = "${CATEGORY}/${PN}" ]; then
export OCC=${GCC}
export OCXX=${GCXX}
export CFLAGS=${DefaultCflags}
export CXXFLAGS="$CFLAGS"
if [ -r ${ROOT}/etc/portage/package.gcc-cflags ]; then
while read target flags; do
if [ "${target}" = "${CATEGORY}/${PN}" ]; then
export CFLAGS="$flags"
export CXXFLAGS="$CFLAGS"
break
fi
done < ${ROOT}/etc/portage/package.gcc-cflags
fi
break
fi
done < ${ROOT}/etc/portage/package.gcc
if [ -r ${ROOT}/etc/portage/package.icc-cflags ]; then
while read target flags; do
if [ "${target}" = "${CATEGORY}/${PN}" ]; then
export CFLAGS="$flags"
export CXXFLAGS="$CFLAGS"
break
fi
done < ${ROOT}/etc/portage/package.icc-cflags
fi
if [ "${OCC}" != "" ]; then
export CC_FOR_BUILD="${OCC}" #workaround gcc detection function in toolchain-funcs.eclass
fi
unset GCC
unset GCXX
|
|
|
Back to top |
|
|
Imak n00b
Joined: 07 Feb 2008 Posts: 29
|
Posted: Fri Sep 04, 2009 4:21 am Post subject: Just a little bit more... |
|
|
Current revision.
Code: |
# /etc/portage/bashrc
export GCC=${OCC}
export GCXX=${OCXX}
export OCC="icc"
export OCXX="icpc"
export DefaultCFLAGS=${CFLAGS}
export DefaultLDFLAGS=${LDFLAGS}
export CFLAGS=${ICCCFLAGS}
export CXXFLAGS=${ICCCXXFLAGS}
[ -r ${ROOT}/etc/portage/package.gcc ] || return 0
while read -a target; do
if [ "${target}" = "${CATEGORY}/${PN}" ]; then
export OCC=${GCC}
export OCXX=${GCXX}
export CFLAGS="$DefaultCFLAGS"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="$DefaultLDFLAGS"
if [ -r ${ROOT}/etc/portage/package.gcc-cflags ]; then
while read target flags; do
if [ "${target}" = "${CATEGORY}/${PN}" ]; then
export CFLAGS="$flags"
export CXXFLAGS="$CFLAGS"
break
fi
done < ${ROOT}/etc/portage/package.gcc-cflags
fi
break
fi
done < ${ROOT}/etc/portage/package.gcc
### Need help with the code segment below ###
# Apparently, this does properly set custom LDFlags, but only for the duration of this code segment. Either when 'break' # is issued or the file is closed the LDFlags revert to something unknown. There must be multiple instances where the
# LDFlag(s) need to be issued, unlike the CFlags. Any tips on how to keep the file open till the package compiles?
# I need some help putting some sort of statement which greps or awks for '>>> Source compiled' then triggers the
# close of file package.ldflags. That or I'm misinterpreting the issue.
/---------------------------------------------------------------
if [ -r ${ROOT}/etc/portage/package.ldflags ]; then
while read target flags; do
if [ "${target}" = "${CATEGORY}/${PN}" ]; then
export LDFLAGS="$flags"
break
fi
done < ${ROOT}/etc/portage/package.ldflags
/---------------------------------------------------------------
if [ -r ${ROOT}/etc/portage/package.icc-cflags ]; then
while read target flags; do
if [ "${target}" = "${CATEGORY}/${PN}" ]; then
export CFLAGS="$flags"
export CXXFLAGS="$CFLAGS"
break
fi
done < ${ROOT}/etc/portage/package.icc-cflags
fi
if [ "${OCC}" != "" ]; then
export CC_FOR_BUILD="${OCC}" #workaround gcc detection function in toolchain-funcs.eclass
fi
unset GCC
unset GCXX
|
New Idea: Automatic filling of package.gcc
- Can anyone fill me in on how to print a message to a file once a certain string is written to the terminal?
# Something like this?
Code: |
if(m/^- (\S+) \(ERROR: "${CATEGORY}/${PN}" failed)
echo "${CATEGORY}/${PN}" >> /etc/portage/package.gcc
einfo "Adding {CATEGORY}/${PN} to package.gcc and emerging in 3 seconds."; sleep 3
emerge --resume
|
|
|
Back to top |
|
|
Imak n00b
Joined: 07 Feb 2008 Posts: 29
|
Posted: Sat Sep 05, 2009 6:18 pm Post subject: Ugh... |
|
|
Well, my bad for not understanding the comment "icc cannot compile all packages in portage". When I went to compile world with ICC I was surprised to see how many packages actually compiled. However, upon inspection, I realized that for most of the programs it was creating code with fragments that were unexecutable, and as world progress it became noticeable that the programs like xorg would not function properly, even though the programs compiled.
So, for those still interested in using the ICC compiler you will have to accept compiling on "specific" packages. (Anecdotall, I noticed links load significantly faster when compiled with ICC).
By the way, there was nothing wrong with the per package LDflags section of the script, I just didn't have the correct flags set in package.ldflags. |
|
Back to top |
|
|
|
|
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
|
|