# Copyright 1999-2004 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id: opengl.eselect 373 2007-10-27 23:03:38Z eradicator $ # Author: Martin Schlemmer # Further modifications by Donnie Berkholz # Further modifications based off submissions to bug #54984 # Further modifications by Jeremy Huddleston # Made into eselect module by Jeremy Huddleston inherit multilib package-manager config # Eselect data DESCRIPTION="Manage the OpenGL implementation used by your system" MAINTAINER="x11-drivers@gentoo.org" SVN_DATE='$Date: 2007-10-27 16:03:38 -0700 (Sat, 27 Oct 2007) $' VERSION=$(svn_date_to_version "${SVN_DATE}" ) EBUILD_VERSION="1.0.6" # Our data ENV_FILE="${ROOT}/etc/env.d/03opengl" PREFIX="${ROOT}/usr" DST_PREFIX="${ROOT}/usr" USE_PROFILE_HEADERS="no" check_version() { if portageq has_version ${ROOT:-/} 'x11-base/xorg-x11'; then if ! portageq has_version ${ROOT:-/} '>=x11-base/xorg-x11-6.8.0-r4'; then die -q "This version requires >=x11-base/xorg-x11-6.8.0-r4" fi fi } get_current_implementation() { local ret local ldpath=$(load_config "${ENV_FILE}" LDPATH) local opengl_profile=$(load_config "${ENV_FILE}" OPENGL_PROFILE) if [[ -n ${opengl_profile} ]] ; then ret="${opengl_profile}" elif [[ -n ${ldpath} ]] ; then ret="${ldpath%%:*}" ret="${ret##*opengl/}" ret="${ret%/lib*}" fi echo ${ret} } get_implementations() { local ret dir for x in $(list_libdirs) ; do [[ ${ROOT} != / ]] && x=${x//${ROOT}} for dir in "${PREFIX}/${x}"/opengl/* ; do [[ -d ${dir} && $(basename "${dir}") != "global" ]] || continue has $(basename "${dir}") ${ret} && continue ret=${ret:+${ret} }$(basename "${dir}") done done echo ${ret} } setup_lib_symlinks() { local profile_libdir=${1} local libdir=${2} local file local rootfile mkdir -p "${libdir}" || die "Failed to create ${libdir}" pushd "${libdir}" &> /dev/null # First remove old symlinks for file in libGL{,core}.{a,so,la} ; do if [[ -e ${file} ]] ; then rm -f "${file}" || die -q "Failed to delete ${file}" fi done # Note that we don't do .so*, just .so on purpose. The # loader knows to look in the profile dir, and the # linked just needs the .so for file in ${profile_libdir}/libGL{,core}.{so,a,la}; do if [[ ${ROOT} != / ]] ; then rootfile="${file//${ROOT}}" else rootfile="${file}" fi [[ -f ${file} ]] || continue if [[ -f $(basename "${file}") ]] ; then rm -f "$(basename "${file}")" || die -q "Failed to delete ${libdir}/$(basename "${file}")" fi # Fix libtool archives (#48297) if [[ ${file%.la} != ${file} ]] ; then sed "s:${profile_libdir}:${libdir}:g" "${file}" > "$(basename "${file}")" || die -q "Failed to create ${libdir}/$(basename "${file}")" else ln -s "${rootfile}" || die -q "Failed to create ${libdir}/$(basename "${file}")" fi done popd &> /dev/null } set_new_implementation() { local gl_implem=${1} local avail_implems=$(get_implementations) check_version # Set a sane umask... bug #83115 umask 022 if ! has ${gl_implem} ${avail_implems}; then die -q "Invalid profile selected." fi echo -n "Switching to ${gl_implem} OpenGL interface..." if [[ -f ${ENV_FILE} ]] ; then rm -f "${ENV_FILE}" || die -q "Failed to remove ${ENV_FILE}" fi local libdir for libdir in $(list_libdirs); do [[ ${ROOT} != / ]] && libdir=${libdir//${ROOT}} # First make sure we have an opengl directory and this is a real lib dir, not a symlink [[ -d ${PREFIX}/${libdir}/opengl && ! -h ${PREFIX}/${libdir} ]] || continue # Fallback on xorg-x11 if we don't have this implementation for this libdir. local gl_local if [[ ! -d ${PREFIX}/${libdir}/opengl/"${gl_implem}" ]] ; then gl_local="xorg-x11" else gl_local="${gl_implem}" fi setup_lib_symlinks "${PREFIX}/${libdir}/opengl/${gl_local}/lib" "${DST_PREFIX}/${libdir}" if [[ -e ${PREFIX}/${libdir}/opengl/${gl_local}/lib/tls ]] ; then setup_lib_symlinks "${PREFIX}/${libdir}/opengl/${gl_local}/lib/tls" "${DST_PREFIX}/${libdir}/tls" fi local moduledir if [[ -e ${DST_PREFIX}/${libdir}/xorg/modules ]] ; then moduledir="xorg/modules" else moduledir="modules" fi if [[ -e ${PREFIX}/${libdir}/opengl/${gl_local}/extensions ]] ; then mkdir -p "${DST_PREFIX}/${libdir}/${moduledir}/extensions" || die "Failed to create ${DST_PREFIX}/${libdir}/${moduledir}/extensions" pushd "${DST_PREFIX}/${libdir}/${moduledir}/extensions" &> /dev/null # First remove old symlinks for file in lib{wfb,glx}.{a,so,la}; do if [[ -e ${file} ]] ; then rm -f "${file}" || die -q "Failed to delete ${DST_PREFIX}/${libdir}/${moduledir}/extensions/${file}" fi done for file in ${PREFIX}/${libdir}/opengl/${gl_local}/extensions/*.{so,a,la}; do [[ -f ${file} ]] || continue if [[ -f $(basename "${file}") ]] ; then rm -f "$(basename "${file}")" || die -q "Failed to delete ${DST_PREFIX}/${libdir}/${moduledir}/extensions/$(basename "${file}")" fi # Fix libtool archives (#48297) if [[ ${file%.la} != ${file} ]] ; then sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${libdir}:g" "${file}" > "$(basename "${file}")" || die -q "Failed to create ${DST_PREFIX}/${libdir}/${moduledir}/extensions/$(basename "${file}")" else ln -s "${file}" || die -q "Failed to create ${libdir}/$(basename "${file}")" fi done popd &> /dev/null fi # Setup the includes mkdir -p "${DST_PREFIX}/include/GL" || die "Failed to create ${DST_PREFIX}/include/GL" pushd "${DST_PREFIX}/include/GL" &> /dev/null for file in gl.h glx.h glxtokens.h glext.h glxext.h glxmd.h glxproto.h; do # IMPORTANT # It is preferable currently to use the standard glext.h file # however if an OpenGL provider must use a self produced glext.h # then it should be installed to ${gl_implem}/include and the user # can add the --impl-headers option to select it. if [[ "${USE_PROFILE_HEADERS}" == "yes" ]] ; then # Check the profile first. if [[ -e ${PREFIX}/${libdir}/opengl/${gl_implem}/include/${file} ]] ; then if [[ -f ${file} || ( -L ${file} && ! -e ${file} ) ]] ; then rm -f "${file}" || die -q "Failed to delete ${DST_PREFIX}/include/GL/$(basename "${file}")" fi ln -s ${PREFIX}/${libdir}/opengl/${gl_implem}/include/${file} || die -q "Failed to create ${DST_PREFIX}/include/GL/$(basename "${file}")" continue fi fi if [[ -e ${PREFIX}/${libdir}/opengl/global/include/${file} ]] ; then if [[ -f ${file} || ( -L ${file} && ! -e ${file} ) ]] ; then rm -f "${file}" || die -q "Failed to delete ${DST_PREFIX}/include/GL/$(basename "${file}")" fi ln -s ${PREFIX}/${libdir}/opengl/global/include/${file} || die -q "Failed to create ${DST_PREFIX}/include/GL/$(basename "${file}")" elif [[ -e ${PREFIX}/${libdir}/opengl/${gl_implem}/include/${file} ]] ; then if [[ -f ${file} || ( -L ${file} && ! -e ${file} ) ]] ; then rm -f "${file}" || die -q "Failed to delete ${DST_PREFIX}/include/GL/$(basename "${file}")" fi ln -s ${PREFIX}/${libdir}/opengl/${gl_implem}/include/${file} || die -q "Failed to create ${DST_PREFIX}/include/GL/$(basename "${file}")" elif [[ -e ${PREFIX}/${libdir}/opengl/xorg-x11/include/${file} ]] ; then if [[ -f ${file} || ( -L ${file} && ! -e ${file} ) ]] ; then rm -f "${file}" || die -q "Failed to delete ${DST_PREFIX}/include/GL/$(basename "${file}")" fi ln -s ${PREFIX}/${libdir}/opengl/xorg-x11/include/${file} || die -q "Failed to create ${DST_PREFIX}/include/GL/$(basename "${file}")" fi done popd &> /dev/null # Setup the $LDPATH ldpath="${ldpath:+${ldpath}:}${PREFIX}/${libdir}/opengl/${gl_local}/lib" done store_config ${ENV_FILE} LDPATH "${ldpath}" store_config ${ENV_FILE} OPENGL_PROFILE "${gl_implem}" do_action env update &> /dev/null echo " done" } ### show action ### describe_show() { echo "Print the current OpenGL implementation." } do_show() { local current=$(get_current_implementation) if [[ -n ${current} ]] ; then echo ${current} return 0 else echo "(none)" return 2 fi } ### list action ### describe_list() { echo "List the available OpenGL implementations." } do_list() { targets=( $(get_implementations) ) write_list_start "Available OpenGL implementations:" if [[ -n ${targets[@]} ]] ; then local i for (( i = 0 ; i < ${#targets[@]} ; i = i + 1 )) ; do [[ ${targets[${i}]} == $(get_current_implementation) ]] \ && targets[${i}]="${targets[${i}]} $(highlight '*' )" done write_numbered_list "${targets[@]}" else write_kv_list_entry "(none found)" "" fi } ### set action ### describe_set() { echo "Select the OpenGL implementation." } describe_set_parameters() { echo "" } describe_set_options() { echo " : The profile to activate" echo "--use-old : If an implementation is already set, use that one instead" echo "--prefix= : Set the source prefix (default: /usr)" echo "--dst-prefix= : Set the destination prefix (default: /usr)" echo "--impl-headers : Override global headers with ones provided by this profile" # write_list_start "Extra options for 'set' action:" # write_kv_list_entry "" "The profile to activate." # write_kv_list_entry "--use-old" "If an implementation is already set, use that one." # write_kv_list_entry "--prefix=" "Set the source prefix (default: /usr)" # write_kv_list_entry "--dst-prefix=" "Set the destination prefix (default: /usr)" # write_kv_list_entry "--impl-headers" "Use headers provided by this implementation to" # write_kv_list_entry "" "override golbal ones provided by opengl-update." # write_kv_list_entry "" "This was default in