Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 621 - (hide annotations) (download) (as text)
Wed Nov 14 18:20:10 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: 9628 byte(s)
-added a comment

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