View previous topic :: View next topic |
Author |
Message |
pdouble Tux's lil' helper
Joined: 24 Aug 2002 Posts: 89 Location: USA
|
Posted: Fri Feb 16, 2007 4:30 pm Post subject: paludis compiler setting hook |
|
|
I am attempting to write a paludis hook that will temporarily switch the compiler using gcc-config for specific packages. I am using this for QEMU which requires gcc 3 but I am running into problems. I think the problem lies in that I am unable to set environment variables in the hook that apply to the rest of the install operation. Is there any help, or another way to do this?
Code: |
#!/bin/bash
# Sets a specific compiler for a package. Reads the compiler
# settings from /etc/paludis/compiler.conf. Each line is
# a specification of <package> <gcc-config compiler spec>
#
# Make a symlink for this hook to:
# ebuild_init_pre
# ebuild_postinst_post
# install_fail
# install_post
# install_all_post
source ${PALUDIS_EBUILD_DIR}/echo_functions.bash
conf="/etc/paludis/compiler.conf"
savefile="${PALUDIS_HOOKS_TMPDIR:-${ROOT}/var/tmp/paludis}/compiler.${PALUDIS_PID}"
# Set compiler before starting installation
case "${HOOK}" in
ebuild_init_pre|ebuild_setup_pre)
# Find a specific compiler setting
compiler="$( grep "${CATEGORY}/${P}" ${conf} | awk '{ print $2 }' )"
[ -n "${compiler}" ] || compiler="$( grep "${CATEGORY}/${PN}" ${conf} | awk '{ print $2 }' )"
[ -n "${compiler}" ] || exit 0 # No compiler set
if [ "$(gcc-config -c)" != "${compiler}" ]; then
gcc-config -c > ${savefile} || die "Cannot save current compiler"
einfo "Changing compiler to ${compiler}"
gcc-config ${compiler} || ( rm ${savefile} ; die "Cannot change compiler to ${compiler}" )
fi
eval $( gcc-config -E )
einfo "Compiler ${CC} claims to be version $(${CC} -dumpversion)"
;;
*)
# Restore compiler after installation or failure
if [ -e "${savefile}" ] ; then
save="$(<${savefile})"
einfo "Restoring compiler to ${save}"
gcc-config ${save} || die "Cannot restore compiler to ${save}"
eval $( gcc-config -E )
rm ${savefile}
fi
;;
esac
|
Code: |
# Config file /etc/paludis/compiler.conf
app-emulation/qemu-softmmu i686-pc-linux-gnu-3.4.6
app-emulation/qemu-user i686-pc-linux-gnu-3.4.6
|
|
|
Back to top |
|
|
zxy Veteran
Joined: 06 Jan 2006 Posts: 1160 Location: in bed in front of the computer
|
Posted: Sat Feb 17, 2007 12:45 am Post subject: |
|
|
I'm not sure, but you could try setting CC and CXX variables (full path to the compiler executable) in the /etc/paludis/bashrc to the compiler you want. Just like you skip TEST (per package). I use this for ccache, but may work for gcc too. if it works it's much easier, but i have just one compiler, so i can't try.
Might be worth a try and doesn't need a hook at all. _________________ Nature does not hurry, yet everything is accomplished.
Lao Tzu |
|
Back to top |
|
|
pdouble Tux's lil' helper
Joined: 24 Aug 2002 Posts: 89 Location: USA
|
Posted: Tue Feb 20, 2007 10:51 pm Post subject: |
|
|
zxy wrote: | I'm not sure, but you could try setting CC and CXX variables (full path to the compiler executable) in the /etc/paludis/bashrc to the compiler you want. Just like you skip TEST (per package). I use this for ccache, but may work for gcc too. if it works it's much easier, but i have just one compiler, so i can't try.
Might be worth a try and doesn't need a hook at all. |
Good suggestion. It works, at least for qemu. The script has been changed as follows. Source this in your /etc/paludis/bashrc using the same config as given previously.
Code: |
#!/bin/bash
# Sets a specific compiler for a package. Reads the compiler
# settings from /etc/paludis/compiler.conf. Each line is
# a specification of <package> <gcc-config compiler spec>
#
# Example:
#
# app-emulation/qemu-softmmu i686-pc-linux-gnu-3.4.6
# app-emulation/qemu-user i686-pc-linux-gnu-3.4.6
source ${PALUDIS_EBUILD_DIR}/echo_functions.bash
compilerconf="/etc/paludis/compiler.conf"
# Find a specific compiler setting
if [ -n "${P}" ]; then
compiler="$( grep "${CATEGORY}/${P}" ${compilerconf} | awk '{ print $2 }' )"
[ -n "${compiler}" ] || compiler="$( grep "${CATEGORY}/${PN}" ${compilerconf} | awk '{ print $2 }' )"
if [ -n "${compiler}" -a "$(gcc-config -c)" != "${compiler}" ]; then
einfo "Setting up environment for compiler ${compiler}"
# gcc-config -E gives us an environment for the compiler
eval $( gcc-config -E ${compiler} )
# check if the CC/CXX settings will use the specified compiler
version1="$(${CC} -dumpversion)"
version2="$($( gcc-config -B ${compiler} )/gcc -dumpversion)"
if [ "${version1}" != "${version2}" ]; then
# No, we need to set the compiler vars
export CC="$( gcc-config -B ${compiler} )/gcc"
export CXX="$( gcc-config -B ${compiler} )/g++"
fi
einfo "Compiler ${CC} claims to be version $(${CC} -dumpversion)"
fi
fi
|
_________________ "Ye must be born again." - John 3:7 |
|
Back to top |
|
|
|