I don't know when I installed ICC and used the unofficial Gentoo wiki to copy the script from there and use it. Anyway... after some time I started to modify the script from there. One bit there, another bit there. This is what I use now:
Code: Select all
##
## Set which compiler to favorize
##
primary_compiler="gcc"
secondary_compiler="icc"
###########################################################
##
## DO NOT CONFIGURE ANYTHING BELOW THIS LINE
##
###########################################################
##
## Try to exit as fast as needed
##
[ -z "${CATEGORY}" -o -z "${PN}" ] && return 0
[ "${primary_compiler}" == "gcc" -a -z "${secondary_compiler}" ] && secondary_compiler="icc"
[ "${primary_compiler}" == "icc" -a -z "${secondary_compiler}" ] && secondary_compiler="gcc"
[ "${secondary_compiler}" != "" -a ! -r "${ROOT}"/etc/portage/package.${secondary_compiler} ] && secondary_compiler=""
[ "${secondary_compiler}" == "" -a ! -r "${ROOT}"/etc/portage/package.${primary_compiler} ] && return 0
handled_by_primary=0
handled_by_secondary=0
##
## Function for exporting CFLAGS
##
export_CFLAGS() {
local compiler="gcc"
[ "${@}" == "icc" ] && compiler="icc"
if [ -r "${ROOT}"/etc/portage/package.${compiler}-cflags ]
then
while read target cflags
do
if [ "${target}" == "${CATEGORY}/${PN}" ]
then
export CFLAGS="${cflags}"
break
fi
done < "${ROOT}"/etc/portage/package.${compiler}-cflags
fi
}
##
## Function for exporting CXXFLAGS
##
export_CXXFLAGS() {
local compiler="gcc"
[ "${@}" == "icc" ] && compiler="icc"
if [ -r "${ROOT}"/etc/portage/package.${compiler}-cxxflags ]
then
while read target cxxflags
do
if [ "${target}" == "${CATEGORY}/${PN}" ]
then
export CXXFLAGS="${cxxflags}"
break
fi
done < "${ROOT}"/etc/portage/package.${compiler}-cxxflags
fi
}
##
## Function for exporting LDFLAGS
##
export_LDFLAGS() {
local compiler="gcc"
[ "${@}" == "icc" ] && compiler="icc"
if [ -r "${ROOT}"/etc/portage/package.${compiler}-ldflags ]
then
while read target ldflags
do
if [ "${target}" == "${CATEGORY}/${PN}" ]
then
export LDFLAGS="${ldflags}"
break
fi
done < "${ROOT}"/etc/portage/package.${compiler}-ldflags
fi
}
##
## Check if primary compiler will handle the package
##
if [ -r "${ROOT}"/etc/portage/package.${primary_compiler} ]
then
while read -a target
do
if [ "${target}" == "${CATEGORY}/${PN}" ]
then
handled_by_primary=1
if [ "${primary_compiler}" == "icc" ]
then
export OCC="icc"
export OCXX="icpc"
#export F77="ifort"
#export FC="ifort"
export CFLAGS=${ICCCFLAGS}
export CXXFLAGS=${ICCCXXFLAGS}
export LDFLAGS=${ICCLDFLAGS}
fi
export_CFLAGS ${primary_compiler}
export CXXFLAGS="${CFLAGS}"
export_CXXFLAGS ${primary_compiler}
export_LDFLAGS ${primary_compiler}
break
fi
done < "${ROOT}"/etc/portage/package.${primary_compiler}
fi
##
## Check if secondary compiler should handle the package
##
if [ "${handled_by_primary}" == "0" -a "${secondary_compiler}" != "" -a -r "${ROOT}"/etc/portage/package.${secondary_compiler} ]
then
while read -a target
do
if [ "${target}" == "${CATEGORY}/${PN}" ]
then
handled_by_secondary=1
if [ "${secondary_compiler}" == "icc" ]
then
export OCC="icc"
export OCXX="icpc"
#export F77="ifort"
#export FC="ifort"
export CFLAGS=${ICCCFLAGS}
export CXXFLAGS=${ICCCXXFLAGS}
export LDFLAGS=${ICCLDFLAGS}
fi
export_CFLAGS ${secondary_compiler}
export CXXFLAGS="${CFLAGS}"
export_CXXFLAGS ${secondary_compiler}
export_LDFLAGS ${secondary_compiler}
break
fi
done < "${ROOT}"/etc/portage/package.${secondary_compiler}
fi
##
## System compiler will handle the package
##
[ "${handled_by_primary}" == "0" -a "${handled_by_secondary}" == "0" ] && return 0
##
## workaround gcc detection function in toolchain-funcs.eclass
##
if [ "${OCC}" != "" ]
then
export CC_FOR_BUILD="${OCC}"
fi
I have another one but that one is not 100% finished and working the way I would like it to work. Anyway... maybe some one will find this one more flexible then the one in the unofficial Gentoo wiki? It works +/- the same way as the one in the unofficial Gentoo wiki except that it allows you as well to use different flags for the C++ compiler (/etc/portage/package.{gcc,icc}-cxxflags) and if needed LDFLAGS (/etc/portage/package.{gcc,icc}-ldflags). The CFLAGS can be specified in /etc/portage/package.{gcc,icc}-cflags. If no C++ flags are specified, then the script will use the one specified for the C compiler. Some stuff looks freaky but I tried to avoid running into problems by using external programs like sed, awk, grep, etc...
// SteveB