Magellan Linux

Annotation of /trunk/opengl-update/opengl-update.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 616 - (hide annotations) (download) (as text)
Wed Nov 14 18:01:25 2007 UTC (16 years, 11 months ago) by niro
Original Path: trunk/opengl-update/opengl-update.sh
File MIME type: application/x-sh
File size: 9650 byte(s)
-initial import: magellanized version 2.2.4

1 niro 616 #!/bin/bash
2     # Copyright 1999-2004 Gentoo Foundation
3     # Distributed under the terms of the GNU General Public License v2
4     # $Header: /home/cvsd/magellan-cvs/magellan-src/opengl-update/opengl-update.sh,v 1.1 2007-11-14 18:01:25 niro Exp $
5     # Author: Martin Schlemmer <azarah@gentoo.org>
6     # Further modifications by Donnie Berkholz <spyderous@gentoo.org>
7     # Further modifications based off submissions to bug #54984 <cyfred@gentoo.org>
8     # Further modifications by Jeremy Huddleston <eradicator@gentoo.org>
9     #
10     # hacked for use with magellan-linux
11     # <niro@magellan-linux.de>
12     #
13    
14     . /etc/init.d/functions
15    
16     hasq() {
17     local x
18    
19     local me=${1}
20     shift
21    
22     for x in "${@}"; do
23     if [[ "${x}" == "${me}" ]]; then
24     return 0
25     fi
26     done
27     return 1
28     }
29    
30     check_user() {
31     if [[ $(id -u) -ne 0 ]]; then
32     echo "${0}: Must be run as root."
33     exit 1
34     fi
35     }
36    
37     get_current_implem() {
38     local implem
39     if [[ -f ${ENV_D} ]]; then
40     source ${ENV_D}
41     if [[ -n "${OPENGL_PROFILE}" ]]; then
42     implem="${OPENGL_PROFILE}"
43     elif [[ -n "${LDPATH}" ]]; then
44     implem="${LDPATH%%:*}"
45     implem="${implem##*opengl/}"
46     implem="${implem%/lib*}"
47     fi
48     unset LDPATH
49     unset OPENGL_PROFILE
50     fi
51    
52     echo ${implem}
53     }
54    
55     get_implementations() {
56     local implems
57     for dir in ${PREFIX}/lib{,32,64}/opengl/*; do
58     if [[ -d "${dir}" && ${dir##*/} != "global" ]] && ! hasq ${dir##*/} ${implems}; then
59     implems=${implems:+${implems} }${dir##*/}
60     fi
61     done
62     echo ${implems}
63     }
64    
65     print_version() {
66     echo "opengl-update ${VERSION}"
67     }
68    
69     print_usage() {
70     # Get grammar right in message
71     local IS_ARE IMPLEM_PLURAL
72     if [[ $(echo ${AVAIL_IMPLEMS} | wc -w) -eq 1 ]]; then
73     IS_ARE="is"
74     IMPLEM_PLURAL=""
75     else
76     IS_ARE="are"
77     IMPLEM_PLURAL="s"
78     fi
79    
80     print_version
81    
82     cat << FOO
83     Usage: ${0##*/} [<options>] <GL implementation>
84     Set the opengl implementation.
85     Valid options:
86     --use-old: If an implementation is already set, use that one.
87     --prefix=<val>: Set the source prefix (default: /usr)
88     --dst-prefix=<val>: Set the destination prefix (default: /usr)
89     --impl-headers: Use headers provided by this implementation to
90     override golbal ones provided by opengl-update.
91    
92     Usage: ${0##*/} --get-implementation
93     Print the current implementaion
94    
95     Notes:
96     --impl-headers was default in <opengl-update-2.2.
97    
98     This utility switches between OpenGL implementations. There ${IS_ARE}
99     $(echo ${AVAIL_IMPLEMS} | wc -w) available implementation${IMPLEM_PLURAL}: ${AVAIL_IMPLEMS}
100    
101     Examples:
102     ${0##*/} xorg
103     This will setup things to use libGL.so from X.org.
104    
105     ${0##*/} nvidia
106     This will setup things to use libGL.so from the nVidia drivers.
107    
108     FOO
109     exit 1
110     }
111    
112     parse_options() {
113     local opt
114     while [[ ${#} -gt 0 ]]; do
115     opt=${1}
116     shift
117     case ${opt} in
118     --use-old)
119     if [[ -n "${ACTION}" ]]; then
120     ACTION="error"
121     echo "Invalid usage."
122     else
123     if [[ -n "${CURRENT_GL_IMPLEM}" ]] && hasq ${CURRENT_GL_IMPLEM} ${AVAIL_IMPLEMS}; then
124     ACTION="old-implementation"
125     fi
126     fi
127     ;;
128     --get-implementation)
129     if [[ -n "${ACTION}" ]]; then
130     ACTION="error"
131     echo "Invalid usage."
132     else
133     ACTION="get-implementation"
134     fi
135     ;;
136     --prefix=*)
137     PREFIX=${opt#*=}
138     AVAIL_IMPLEMS=$(get_implementations)
139     ;;
140     --dst-prefix=*)
141     DST_PREFIX=${opt#*=}
142     ;;
143     --impl-headers)
144     USE_PROFILE_HEADERS="yes"
145     ;;
146     --help|-h|-?)
147     ACION="usage"
148     ;;
149     --version)
150     ACTION="version"
151     ;;
152     *)
153     if hasq ${opt} ${AVAIL_IMPLEMS}; then
154     if [[ "${ACTION}" != "old-implementation" ]]; then
155     if [[ -n "${ACTION}" ]]; then
156     ACTION="error"
157     echo "Invalid usage."
158     else
159     ACTION="set-implementation"
160     NEW_GL_IMPLEM="${opt}"
161     fi
162     fi
163     else
164     echo "Unrecognized option: ${opt}"
165     ACTION="error"
166     fi
167     ;;
168     esac
169     done
170     }
171    
172     set-new-implementation() {
173     local GL_IMPLEM=${1}
174     local GL_LOCAL
175    
176     check_user
177    
178     # Set a sane umask... bug #83115
179     umask 022
180    
181     if ! hasq ${GL_IMPLEM} ${AVAIL_IMPLEMS}; then
182     echo "Invalid profile selected."
183     exit 1
184     fi
185    
186     echo "Switching to ${GL_IMPLEM} OpenGL interface"
187     rm -f ${ENV_D} &> /dev/null
188    
189     LIBDIRS="lib32 lib lib64"
190     for LIBDIR in ${LIBDIRS}; do
191     # Special case handling of lib32 because it can be a symlink to
192     # emul libs
193     if [[ "${LIBDIR}" = "lib32" ]]; then
194     [[ -d "${PREFIX}/${LIBDIR}/opengl" ]] || continue
195     else
196     [[ -d "${PREFIX}/${LIBDIR}/opengl" && ! -h "${PREFIX}/${LIBDIR}" ]] || continue
197     fi
198    
199     # Fallback on xorg if we don't have this implementation for this LIBDIR.
200     if [[ ! -d ${PREFIX}/${LIBDIR}/opengl/"${GL_IMPLEM}" ]]; then
201     GL_LOCAL="xorg"
202     else
203     GL_LOCAL="${GL_IMPLEM}"
204     fi
205    
206     mkdir -p ${DST_PREFIX}/${LIBDIR}
207     pushd ${DST_PREFIX}/${LIBDIR} &> /dev/null
208     # First remove old symlinks
209     for file in libGL{,core}.{a,so,la} ; do
210     [[ -h ${file} ]] && rm -f ${file}
211     done
212    
213     # Note that we don't do .so*, just .so on purpose. The
214     # loader knows to look in the profile dir, and the
215     # linked just needs the .so
216     for file in ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/libGL{,core}.{so,a,la}; do
217     [[ -f "${file}" ]] || continue
218     [[ -f "${file##*/}" ]] && rm -f ${file##*/}
219    
220     # Fix libtool archives (#48297)
221     if [[ "${file%.la}" != "${file}" ]]; then
222     sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/}
223     else
224     ln -s ${file}
225     fi
226     done
227     popd &> /dev/null
228    
229     if [[ -e "${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/tls" ]]; then
230     mkdir -p ${DST_PREFIX}/${LIBDIR}/tls
231     pushd ${DST_PREFIX}/${LIBDIR}/tls &> /dev/null
232     # First remove old symlinks
233     for file in libGL{,core}.{a,so,la} ; do
234     [[ -h ${file} ]] && rm -f ${file}
235     done
236    
237     for file in ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/tls/libGL{,core}.{so,a,la}; do
238     [[ -f "${file}" ]] || continue
239     [[ -f "${file##*/}" ]] && rm -f ${file##*/}
240    
241     # Fix libtool archives (#48297)
242     if [ "${file%.la}" != "${file}" ]; then
243     sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/}
244     else
245     ln -s ${file}
246     fi
247     done
248     popd &> /dev/null
249     fi
250    
251     local MODULEDIR
252     if [[ -e "${DST_PREFIX}/${LIBDIR}/xorg/modules" ]]; then
253     MODULEDIR="xorg/modules"
254     else
255     MODULEDIR="modules"
256     fi
257    
258     if [[ -e "${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/extensions" ]]; then
259     mkdir -p ${DST_PREFIX}/${LIBDIR}/${MODULEDIR}/extensions
260     pushd ${DST_PREFIX}/${LIBDIR}/${MODULEDIR}/extensions &> /dev/null
261     # First remove old symlinks
262     for file in libglx.so libglx.a; do
263     [[ -h ${file} ]] && rm -f ${file}
264     done
265    
266     for file in ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/extensions/*.{so,a,la}; do
267     [[ -f "${file}" ]] || continue
268     [[ -f "${file##*/}" ]] && rm -f ${file##*/}
269    
270     # Fix libtool archives (#48297)
271     if [[ "${file%.la}" != "${file}" ]]; then
272     sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/}
273     else
274     ln -s ${file}
275     fi
276     done
277     popd &> /dev/null
278     fi
279    
280     # Setup the includes
281     mkdir -p ${DST_PREFIX}/include/GL
282     pushd ${DST_PREFIX}/include/GL &> /dev/null
283     for file in gl.h glx.h glxtokens.h glext.h glxext.h glxmd.h glxproto.h; do
284     # IMPORTANT
285     # It is preferable currently to use the standard glext.h file
286     # however if an OpenGL provider must use a self produced glext.h
287     # then it should be installed to ${GL_IMPLEM}/include and the user
288     # can add the --impl-headers option to select it.
289    
290     if [[ ${USE_PROFILE_HEADERS} == "yes" ]] ; then
291     # Check the profile first.
292     if [[ -e ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${file} ]]; then
293     [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file}
294     ln -s ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${file}
295     fi
296     continue
297     fi
298    
299     if [[ -e ${PREFIX}/${LIBDIR}/opengl/global/include/${file} ]]; then
300     [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file}
301     ln -s ${PREFIX}/${LIBDIR}/opengl/global/include/${file}
302     elif [[ -e ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${file} ]]; then
303     [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file}
304     ln -s ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${file}
305     elif [[ -e ${PREFIX}/${LIBDIR}/opengl/xorg/include/${file} ]]; then
306     [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file}
307     ln -s ${PREFIX}/${LIBDIR}/opengl/xorg/include/${file}
308     fi
309     done
310     popd &> /dev/null
311    
312     # Setup the $LDPATH
313     ldpath="${ldpath:+${ldpath}:}${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib"
314    
315     done
316    
317     echo "LDPATH=\"${ldpath}\"" > ${ENV_D}
318     echo "OPENGL_PROFILE=\"${GL_IMPLEM}\"" >> ${ENV_D}
319    
320     env-rebuild
321    
322     return 0
323     }
324    
325     ## START PROGRAM ##
326    
327     ENV_D="/etc/env.d/03opengl"
328     NEW_GL_IMPLEM=""
329     ACTION=""
330     PREFIX="/usr"
331     DST_PREFIX="/usr"
332     AVAIL_IMPLEMS=$(get_implementations)
333     CURRENT_GL_IMPLEM=$(get_current_implem)
334     USE_PROFILE_HEADERS="no"
335     VERSION="2.2.4"
336    
337     parse_options ${@}
338    
339     case ${ACTION} in
340     get-implementation)
341     if [[ -n "${CURRENT_GL_IMPLEM}" ]]; then
342     echo ${CURRENT_GL_IMPLEM}
343     exit 0
344     else
345     exit 2
346     fi
347     ;;
348     old-implementation)
349     set-new-implementation ${CURRENT_GL_IMPLEM}
350     exit $?
351     ;;
352     set-implementation)
353     if [[ -n "${NEW_GL_IMPLEM}" ]]; then
354     set-new-implementation ${NEW_GL_IMPLEM}
355     exit $?
356     else
357     print_usage
358     exit 1
359     fi
360     ;;
361     version)
362     print_version
363     exit 0
364     ;;
365     usage)
366     print_usage
367     exit 0
368     ;;
369     error)
370     print_usage
371     exit 1
372     ;;
373     *)
374     print_usage
375     exit 1
376     ;;
377     esac