--- trunk/opengl-update/opengl-update.sh 2007/11/14 18:01:25 616 +++ trunk/opengl-update/opengl-update.in 2012/12/31 15:14:19 2003 @@ -1,7 +1,7 @@ #!/bin/bash # Copyright 1999-2004 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /home/cvsd/magellan-cvs/magellan-src/opengl-update/opengl-update.sh,v 1.1 2007-11-14 18:01:25 niro Exp $ +# $Header: /home/cvsd/magellan-cvs/magellan-src/opengl-update/opengl-update.sh,v 1.10 2007-11-14 19:19:16 niro Exp $ # Author: Martin Schlemmer # Further modifications by Donnie Berkholz # Further modifications based off submissions to bug #54984 @@ -11,36 +11,42 @@ # # -. /etc/init.d/functions - -hasq() { +hasq() +{ local x local me=${1} shift - - for x in "${@}"; do - if [[ "${x}" == "${me}" ]]; then - return 0 - fi + + for x in $@ + do + [[ ${x} = ${me} ]] && return 0 done + return 1 } -check_user() { - if [[ $(id -u) -ne 0 ]]; then +check_user() +{ + if [[ $(id -u) -ne 0 ]] + then echo "${0}: Must be run as root." exit 1 fi } -get_current_implem() { +get_current_implem() +{ local implem - if [[ -f ${ENV_D} ]]; then + + if [[ -f ${ENV_D} ]] + then source ${ENV_D} - if [[ -n "${OPENGL_PROFILE}" ]]; then + if [[ -n ${OPENGL_PROFILE} ]] + then implem="${OPENGL_PROFILE}" - elif [[ -n "${LDPATH}" ]]; then + elif [[ -n ${LDPATH} ]] + then implem="${LDPATH%%:*}" implem="${implem##*opengl/}" implem="${implem%/lib*}" @@ -52,24 +58,35 @@ echo ${implem} } -get_implementations() { +get_implementations() +{ local implems - for dir in ${PREFIX}/lib{,32,64}/opengl/*; do - if [[ -d "${dir}" && ${dir##*/} != "global" ]] && ! hasq ${dir##*/} ${implems}; then + + for dir in ${PREFIX}/lib{,32,64}/opengl/* + do + if [[ -d ${dir} ]] && + [[ ${dir##*/} != global ]] && + ! hasq ${dir##*/} ${implems} + then implems=${implems:+${implems} }${dir##*/} fi done + echo ${implems} } -print_version() { +print_version() +{ echo "opengl-update ${VERSION}" } -print_usage() { +print_usage() +{ # Get grammar right in message local IS_ARE IMPLEM_PLURAL - if [[ $(echo ${AVAIL_IMPLEMS} | wc -w) -eq 1 ]]; then + + if [[ $(echo ${AVAIL_IMPLEMS} | wc -w) -eq 1 ]] + then IS_ARE="is" IMPLEM_PLURAL="" else @@ -83,11 +100,13 @@ Usage: ${0##*/} [] Set the opengl implementation. Valid options: + --help|-h|-?: Prints this help. + --version: Shows the version of this utility. --use-old: If an implementation is already set, use that one. --prefix=: Set the source prefix (default: /usr) --dst-prefix=: Set the destination prefix (default: /usr) --impl-headers: Use headers provided by this implementation to - override golbal ones provided by opengl-update. + override global ones provided by opengl-update. Usage: ${0##*/} --get-implementation Print the current implementaion @@ -109,67 +128,77 @@ exit 1 } -parse_options() { +parse_options() +{ local opt - while [[ ${#} -gt 0 ]]; do + + while [[ ${#} -gt 0 ]] + do opt=${1} shift case ${opt} in --use-old) - if [[ -n "${ACTION}" ]]; then + if [[ -n ${ACTION} ]] + then ACTION="error" echo "Invalid usage." else - if [[ -n "${CURRENT_GL_IMPLEM}" ]] && hasq ${CURRENT_GL_IMPLEM} ${AVAIL_IMPLEMS}; then + if [[ -n "${CURRENT_GL_IMPLEM}" ]] && + hasq ${CURRENT_GL_IMPLEM} ${AVAIL_IMPLEMS} + then ACTION="old-implementation" fi - fi - ;; + fi + ;; + --get-implementation) - if [[ -n "${ACTION}" ]]; then + if [[ -n ${ACTION} ]] + then ACTION="error" echo "Invalid usage." else ACTION="get-implementation" - fi - ;; + fi + ;; + --prefix=*) PREFIX=${opt#*=} AVAIL_IMPLEMS=$(get_implementations) - ;; - --dst-prefix=*) - DST_PREFIX=${opt#*=} - ;; - --impl-headers) - USE_PROFILE_HEADERS="yes" - ;; - --help|-h|-?) - ACION="usage" - ;; - --version) - ACTION="version" - ;; + ;; + + --dst-prefix=*) DST_PREFIX=${opt#*=} ;; + + --impl-headers) USE_PROFILE_HEADERS="yes" ;; + + --help|-h|-?) ACTION="usage" ;; + + --version) ACTION="version" ;; + *) - if hasq ${opt} ${AVAIL_IMPLEMS}; then - if [[ "${ACTION}" != "old-implementation" ]]; then - if [[ -n "${ACTION}" ]]; then + if hasq ${opt} ${AVAIL_IMPLEMS} + then + if [[ ${ACTION} != old-implementation ]] + then + if [[ -n ${ACTION} ]] + then ACTION="error" echo "Invalid usage." else ACTION="set-implementation" NEW_GL_IMPLEM="${opt}" fi - fi + fi else echo "Unrecognized option: ${opt}" ACTION="error" fi - ;; + ;; esac done } -set-new-implementation() { +set_new_implementation() +{ local GL_IMPLEM=${1} local GL_LOCAL @@ -178,146 +207,188 @@ # Set a sane umask... bug #83115 umask 022 - if ! hasq ${GL_IMPLEM} ${AVAIL_IMPLEMS}; then + if ! hasq ${GL_IMPLEM} ${AVAIL_IMPLEMS} + then echo "Invalid profile selected." exit 1 fi echo "Switching to ${GL_IMPLEM} OpenGL interface" - rm -f ${ENV_D} &> /dev/null - LIBDIRS="lib32 lib lib64" - for LIBDIR in ${LIBDIRS}; do - # Special case handling of lib32 because it can be a symlink to - # emul libs - if [[ "${LIBDIR}" = "lib32" ]]; then - [[ -d "${PREFIX}/${LIBDIR}/opengl" ]] || continue - else - [[ -d "${PREFIX}/${LIBDIR}/opengl" && ! -h "${PREFIX}/${LIBDIR}" ]] || continue - fi - - # Fallback on xorg if we don't have this implementation for this LIBDIR. - if [[ ! -d ${PREFIX}/${LIBDIR}/opengl/"${GL_IMPLEM}" ]]; then - GL_LOCAL="xorg" - else - GL_LOCAL="${GL_IMPLEM}" - fi - - mkdir -p ${DST_PREFIX}/${LIBDIR} - pushd ${DST_PREFIX}/${LIBDIR} &> /dev/null + rm -f ${ENV_D} &> /dev/null + + LIBDIRS="lib32 lib lib64" + for LIBDIR in ${LIBDIRS} + do + # Special case handling of lib32 because it can be a symlink to + # emul libs + if [[ ${LIBDIR} = lib32 ]] + then + [[ -d ${PREFIX}/${LIBDIR}/opengl ]] || continue + else + [[ -d ${PREFIX}/${LIBDIR}/opengl ]] && + [[ ! -h ${PREFIX}/${LIBDIR} ]] || continue + fi + + # Fallback on xorg if we don't have this implementation for this LIBDIR. + if [[ ! -d ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM} ]] + then + GL_LOCAL="xorg" + else + GL_LOCAL="${GL_IMPLEM}" + fi + + mkdir -p ${DST_PREFIX}/${LIBDIR} + pushd ${DST_PREFIX}/${LIBDIR} &> /dev/null + # First remove old symlinks + for file in lib{EGL,GL*,OpenVG}{,core}.{so,dylib,a,la} + do + # exclude libGLU + [[ ${file} = libGLU.so ]] && continue + [[ -h ${file} ]] && rm -f ${file} + 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 ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/lib{EGL,GL*,OpenVG}{,core}.{so,dylib,a,la} + do + [[ -f ${file} ]] || continue + [[ -f ${file##*/} ]] && rm -f ${file##*/} + + # Fix libtool archives (#48297) + if [[ ${file%.la} != ${file} ]] + then + sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/} + else + ln -s ${file} + fi + done + popd &> /dev/null + + if [[ -e ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/tls ]] + then + mkdir -p ${DST_PREFIX}/${LIBDIR}/tls + pushd ${DST_PREFIX}/${LIBDIR}/tls &> /dev/null # First remove old symlinks - for file in libGL{,core}.{a,so,la} ; do + for file in lib{EGL,GL*,OpenVG}{,core}.{so,dylib,a,la} + do + # exclude libGLU + [[ ${file} = libGLU.so ]] && continue [[ -h ${file} ]] && rm -f ${file} 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 ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/libGL{,core}.{so,a,la}; do - [[ -f "${file}" ]] || continue - [[ -f "${file##*/}" ]] && rm -f ${file##*/} + for file in ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/tls/lib{EGL,GL*,OpenVG}{,core}.{so,dylib,a,la} + do + [[ -f ${file} ]] || continue + [[ -f ${file##*/} ]] && rm -f ${file##*/} # Fix libtool archives (#48297) - if [[ "${file%.la}" != "${file}" ]]; then + if [[ ${file%.la} != ${file} ]] + then sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/} else ln -s ${file} fi done popd &> /dev/null + fi - if [[ -e "${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/tls" ]]; then - mkdir -p ${DST_PREFIX}/${LIBDIR}/tls - pushd ${DST_PREFIX}/${LIBDIR}/tls &> /dev/null - # First remove old symlinks - for file in libGL{,core}.{a,so,la} ; do - [[ -h ${file} ]] && rm -f ${file} - done - - for file in ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/tls/libGL{,core}.{so,a,la}; do - [[ -f "${file}" ]] || continue - [[ -f "${file##*/}" ]] && rm -f ${file##*/} - - # Fix libtool archives (#48297) - if [ "${file%.la}" != "${file}" ]; then - sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/} - else - ln -s ${file} - fi - done - popd &> /dev/null - 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 - pushd ${DST_PREFIX}/${LIBDIR}/${MODULEDIR}/extensions &> /dev/null - # First remove old symlinks - for file in libglx.so libglx.a; do - [[ -h ${file} ]] && rm -f ${file} - done - - for file in ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/extensions/*.{so,a,la}; do - [[ -f "${file}" ]] || continue - [[ -f "${file##*/}" ]] && rm -f ${file##*/} - - # Fix libtool archives (#48297) - if [[ "${file%.la}" != "${file}" ]]; then - sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/} - else - ln -s ${file} - fi - done - popd &> /dev/null - fi - - # Setup the includes - mkdir -p ${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 + 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 + pushd ${DST_PREFIX}/${LIBDIR}/${MODULEDIR}/extensions &> /dev/null + # First remove old symlinks + for file in lib{wfb,glx,dri,dri2}.{so,dylib,a} + do + [[ -h ${file} ]] && rm -f ${file} + done + + for file in ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/extensions/*.{so,a,la} + do + [[ -f ${file} ]] || continue + [[ -f ${file##*/} ]] && rm -f ${file##*/} + + # Fix libtool archives (#48297) + if [[ ${file%.la} != ${file} ]] + then + sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/} + else + ln -s ${file} + fi + done + popd &> /dev/null + fi + + # Setup the includes + local -A headers + headers[GL]="gl.h glx.h glxtokens.h glext.h glxext.h glxmd.h glxproto.h" + headers[GLES]="egl.h gl_extensions.h glext.h gl.h glplatform.h" + headers[GLES2]="gl2ext.h gl2.h gl2platform.h" + headers[EGL]="eglext.h egl.h eglmesaext.h eglplatform.h" + headers[KHR]="khrplatform.h" + headers[VG]="openvg.h vgext.h vgplatform.h vgu.h" + for incl_dir in EGL GL GLES GLES2 KHR VG + do + mkdir -p ${DST_PREFIX}/include/${incl_dir} + pushd ${DST_PREFIX}/include/${incl_dir} &> /dev/null + for file in ${headers[${incl_dir}]} + 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 + if [[ ${USE_PROFILE_HEADERS} = yes ]] + then # Check the profile first. - if [[ -e ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${file} ]]; then + if [[ -e ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${incl_dir}/${file} ]] + then [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file} - ln -s ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${file} + ln -s ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${incl_dir}/${file} fi continue fi - if [[ -e ${PREFIX}/${LIBDIR}/opengl/global/include/${file} ]]; then + if [[ -e ${PREFIX}/${LIBDIR}/opengl/global/include/${incl_dir}/${file} ]] + then [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file} - ln -s ${PREFIX}/${LIBDIR}/opengl/global/include/${file} - elif [[ -e ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${file} ]]; then + ln -s ${PREFIX}/${LIBDIR}/opengl/global/include/${incl_dir}/${file} + elif [[ -e ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${incl_dir}/${file} ]] + then [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file} - ln -s ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${file} - elif [[ -e ${PREFIX}/${LIBDIR}/opengl/xorg/include/${file} ]]; then + ln -s ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${incl_dir}/${file} + elif [[ -e ${PREFIX}/${LIBDIR}/opengl/xorg/include/${incl_dir}/${file} ]] + then [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file} - ln -s ${PREFIX}/${LIBDIR}/opengl/xorg/include/${file} + ln -s ${PREFIX}/${LIBDIR}/opengl/xorg/include/${incl_dir}/${file} fi done popd &> /dev/null + done - # Setup the $LDPATH - ldpath="${ldpath:+${ldpath}:}${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib" + # Setup the $LDPATH + ldpath="${ldpath:+${ldpath}:}${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib" - done + done - echo "LDPATH=\"${ldpath}\"" > ${ENV_D} - echo "OPENGL_PROFILE=\"${GL_IMPLEM}\"" >> ${ENV_D} + # put only one LDPATH per line! + local i + for i in $(echo ${ldpath} | sed "s:\::\ :g") + do + echo "LDPATH=\"${i}\"" >> ${ENV_D} + done + echo "OPENGL_PROFILE=\"${GL_IMPLEM}\"" >> ${ENV_D} - env-rebuild + env-rebuild return 0 } @@ -332,46 +403,54 @@ AVAIL_IMPLEMS=$(get_implementations) CURRENT_GL_IMPLEM=$(get_current_implem) USE_PROFILE_HEADERS="no" -VERSION="2.2.4" +VERSION="@@VERSION@@" parse_options ${@} case ${ACTION} in get-implementation) - if [[ -n "${CURRENT_GL_IMPLEM}" ]]; then + if [[ -n ${CURRENT_GL_IMPLEM} ]] + then echo ${CURRENT_GL_IMPLEM} exit 0 else exit 2 fi - ;; + ;; + old-implementation) - set-new-implementation ${CURRENT_GL_IMPLEM} + set_new_implementation ${CURRENT_GL_IMPLEM} exit $? - ;; + ;; + set-implementation) - if [[ -n "${NEW_GL_IMPLEM}" ]]; then - set-new-implementation ${NEW_GL_IMPLEM} + if [[ -n ${NEW_GL_IMPLEM} ]] + then + set_new_implementation ${NEW_GL_IMPLEM} exit $? else print_usage exit 1 fi - ;; + ;; + version) print_version exit 0 - ;; + ;; + usage) print_usage exit 0 - ;; + ;; + error) print_usage exit 1 - ;; + ;; + *) print_usage exit 1 - ;; + ;; esac