Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2003 - (hide annotations) (download)
Mon Dec 31 15:14:19 2012 UTC (11 years, 10 months ago) by niro
File size: 10455 byte(s)
-exclude GLU
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 633 # $Header: /home/cvsd/magellan-cvs/magellan-src/opengl-update/opengl-update.sh,v 1.10 2007-11-14 19:19:16 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 niro 617 hasq()
15     {
16 niro 616 local x
17    
18     local me=${1}
19     shift
20 niro 617
21     for x in $@
22     do
23     [[ ${x} = ${me} ]] && return 0
24 niro 616 done
25 niro 617
26 niro 616 return 1
27     }
28    
29 niro 617 check_user()
30     {
31     if [[ $(id -u) -ne 0 ]]
32     then
33 niro 616 echo "${0}: Must be run as root."
34     exit 1
35     fi
36     }
37    
38 niro 617 get_current_implem()
39     {
40 niro 616 local implem
41 niro 617
42     if [[ -f ${ENV_D} ]]
43     then
44 niro 616 source ${ENV_D}
45 niro 617 if [[ -n ${OPENGL_PROFILE} ]]
46     then
47 niro 616 implem="${OPENGL_PROFILE}"
48 niro 617 elif [[ -n ${LDPATH} ]]
49     then
50 niro 616 implem="${LDPATH%%:*}"
51     implem="${implem##*opengl/}"
52     implem="${implem%/lib*}"
53     fi
54     unset LDPATH
55     unset OPENGL_PROFILE
56     fi
57    
58     echo ${implem}
59     }
60    
61 niro 617 get_implementations()
62     {
63 niro 616 local implems
64 niro 617
65     for dir in ${PREFIX}/lib{,32,64}/opengl/*
66     do
67     if [[ -d ${dir} ]] &&
68 niro 624 [[ ${dir##*/} != global ]] &&
69     ! hasq ${dir##*/} ${implems}
70 niro 617 then
71 niro 616 implems=${implems:+${implems} }${dir##*/}
72     fi
73     done
74 niro 617
75 niro 616 echo ${implems}
76     }
77    
78 niro 617 print_version()
79     {
80 niro 616 echo "opengl-update ${VERSION}"
81     }
82    
83 niro 617 print_usage()
84     {
85 niro 616 # Get grammar right in message
86     local IS_ARE IMPLEM_PLURAL
87 niro 617
88     if [[ $(echo ${AVAIL_IMPLEMS} | wc -w) -eq 1 ]]
89     then
90 niro 616 IS_ARE="is"
91     IMPLEM_PLURAL=""
92     else
93     IS_ARE="are"
94     IMPLEM_PLURAL="s"
95     fi
96    
97     print_version
98    
99     cat << FOO
100     Usage: ${0##*/} [<options>] <GL implementation>
101     Set the opengl implementation.
102     Valid options:
103 niro 633 --help|-h|-?: Prints this help.
104     --version: Shows the version of this utility.
105 niro 616 --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 niro 632 override global ones provided by opengl-update.
110 niro 616
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 624 set_new_implementation()
201 niro 617 {
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 niro 629 [[ ! -h ${PREFIX}/${LIBDIR} ]] || continue
231 niro 617 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 niro 1988 for file in lib{EGL,GL*,OpenVG}{,core}.{so,dylib,a,la}
245 niro 617 do
246 niro 2003 # exclude libGLU
247     [[ ${file} = libGLU.so ]] && continue
248 niro 617 [[ -h ${file} ]] && rm -f ${file}
249     done
250    
251     # Note that we don't do .so*, just .so on purpose. The
252     # loader knows to look in the profile dir, and the
253     # linked just needs the .so
254 niro 1988 for file in ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/lib{EGL,GL*,OpenVG}{,core}.{so,dylib,a,la}
255 niro 617 do
256     [[ -f ${file} ]] || continue
257     [[ -f ${file##*/} ]] && rm -f ${file##*/}
258    
259     # Fix libtool archives (#48297)
260     if [[ ${file%.la} != ${file} ]]
261     then
262     sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/}
263     else
264     ln -s ${file}
265     fi
266     done
267     popd &> /dev/null
268    
269     if [[ -e ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/tls ]]
270     then
271     mkdir -p ${DST_PREFIX}/${LIBDIR}/tls
272     pushd ${DST_PREFIX}/${LIBDIR}/tls &> /dev/null
273 niro 616 # First remove old symlinks
274 niro 1988 for file in lib{EGL,GL*,OpenVG}{,core}.{so,dylib,a,la}
275 niro 617 do
276 niro 2003 # exclude libGLU
277     [[ ${file} = libGLU.so ]] && continue
278 niro 616 [[ -h ${file} ]] && rm -f ${file}
279     done
280    
281 niro 1988 for file in ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/tls/lib{EGL,GL*,OpenVG}{,core}.{so,dylib,a,la}
282 niro 617 do
283     [[ -f ${file} ]] || continue
284     [[ -f ${file##*/} ]] && rm -f ${file##*/}
285 niro 616
286     # Fix libtool archives (#48297)
287 niro 617 if [[ ${file%.la} != ${file} ]]
288     then
289 niro 616 sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/}
290     else
291     ln -s ${file}
292     fi
293     done
294     popd &> /dev/null
295 niro 617 fi
296 niro 616
297 niro 617 local MODULEDIR
298     if [[ -e ${DST_PREFIX}/${LIBDIR}/xorg/modules ]]
299     then
300     MODULEDIR="xorg/modules"
301     else
302     MODULEDIR="modules"
303     fi
304 niro 616
305 niro 617 if [[ -e ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/extensions ]]
306     then
307     mkdir -p ${DST_PREFIX}/${LIBDIR}/${MODULEDIR}/extensions
308     pushd ${DST_PREFIX}/${LIBDIR}/${MODULEDIR}/extensions &> /dev/null
309     # First remove old symlinks
310 niro 1978 for file in lib{wfb,glx,dri,dri2}.{so,dylib,a}
311 niro 617 do
312     [[ -h ${file} ]] && rm -f ${file}
313     done
314 niro 616
315 niro 617 for file in ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/extensions/*.{so,a,la}
316     do
317     [[ -f ${file} ]] || continue
318     [[ -f ${file##*/} ]] && rm -f ${file##*/}
319 niro 616
320 niro 617 # Fix libtool archives (#48297)
321     if [[ ${file%.la} != ${file} ]]
322     then
323     sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/}
324     else
325     ln -s ${file}
326     fi
327     done
328     popd &> /dev/null
329     fi
330 niro 616
331 niro 617 # Setup the includes
332 niro 1984 local -A headers
333 niro 2003 headers[GL]="gl.h glx.h glxtokens.h glext.h glxext.h glxmd.h glxproto.h"
334 niro 1978 headers[GLES]="egl.h gl_extensions.h glext.h gl.h glplatform.h"
335     headers[GLES2]="gl2ext.h gl2.h gl2platform.h"
336 niro 1995 headers[EGL]="eglext.h egl.h eglmesaext.h eglplatform.h"
337 niro 1978 headers[KHR]="khrplatform.h"
338     headers[VG]="openvg.h vgext.h vgplatform.h vgu.h"
339     for incl_dir in EGL GL GLES GLES2 KHR VG
340     do
341     mkdir -p ${DST_PREFIX}/include/${incl_dir}
342     pushd ${DST_PREFIX}/include/${incl_dir} &> /dev/null
343     for file in ${headers[${incl_dir}]}
344     do
345     # IMPORTANT
346     # It is preferable currently to use the standard glext.h file
347     # however if an OpenGL provider must use a self produced glext.h
348     # then it should be installed to ${GL_IMPLEM}/include and the user
349     # can add the --impl-headers option to select it.
350     if [[ ${USE_PROFILE_HEADERS} = yes ]]
351     then
352     # Check the profile first.
353     if [[ -e ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${incl_dir}/${file} ]]
354     then
355     [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file}
356     ln -s ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${incl_dir}/${file}
357     fi
358     continue
359     fi
360 niro 616
361 niro 1978 if [[ -e ${PREFIX}/${LIBDIR}/opengl/global/include/${incl_dir}/${file} ]]
362 niro 617 then
363 niro 616 [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file}
364 niro 1978 ln -s ${PREFIX}/${LIBDIR}/opengl/global/include/${incl_dir}/${file}
365     elif [[ -e ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${incl_dir}/${file} ]]
366     then
367     [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file}
368     ln -s ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${incl_dir}/${file}
369     elif [[ -e ${PREFIX}/${LIBDIR}/opengl/xorg/include/${incl_dir}/${file} ]]
370     then
371     [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file}
372     ln -s ${PREFIX}/${LIBDIR}/opengl/xorg/include/${incl_dir}/${file}
373 niro 616 fi
374 niro 1978 done
375     popd &> /dev/null
376     done
377 niro 616
378 niro 617 # Setup the $LDPATH
379     ldpath="${ldpath:+${ldpath}:}${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib"
380 niro 616
381 niro 617 done
382 niro 616
383 niro 621 # put only one LDPATH per line!
384 niro 620 local i
385     for i in $(echo ${ldpath} | sed "s:\::\ :g")
386     do
387     echo "LDPATH=\"${i}\"" >> ${ENV_D}
388     done
389 niro 617 echo "OPENGL_PROFILE=\"${GL_IMPLEM}\"" >> ${ENV_D}
390 niro 616
391 niro 617 env-rebuild
392    
393 niro 616 return 0
394     }
395    
396     ## START PROGRAM ##
397    
398     ENV_D="/etc/env.d/03opengl"
399     NEW_GL_IMPLEM=""
400     ACTION=""
401     PREFIX="/usr"
402     DST_PREFIX="/usr"
403     AVAIL_IMPLEMS=$(get_implementations)
404     CURRENT_GL_IMPLEM=$(get_current_implem)
405     USE_PROFILE_HEADERS="no"
406 niro 619 VERSION="@@VERSION@@"
407 niro 616
408     parse_options ${@}
409    
410     case ${ACTION} in
411     get-implementation)
412 niro 617 if [[ -n ${CURRENT_GL_IMPLEM} ]]
413     then
414 niro 616 echo ${CURRENT_GL_IMPLEM}
415     exit 0
416     else
417     exit 2
418     fi
419 niro 617 ;;
420    
421 niro 616 old-implementation)
422 niro 624 set_new_implementation ${CURRENT_GL_IMPLEM}
423 niro 616 exit $?
424 niro 617 ;;
425    
426 niro 616 set-implementation)
427 niro 617 if [[ -n ${NEW_GL_IMPLEM} ]]
428     then
429 niro 624 set_new_implementation ${NEW_GL_IMPLEM}
430 niro 616 exit $?
431     else
432     print_usage
433     exit 1
434     fi
435 niro 617 ;;
436    
437 niro 616 version)
438     print_version
439     exit 0
440 niro 617 ;;
441    
442 niro 616 usage)
443     print_usage
444     exit 0
445 niro 617 ;;
446    
447 niro 616 error)
448     print_usage
449     exit 1
450 niro 617 ;;
451    
452 niro 616 *)
453     print_usage
454     exit 1
455 niro 617 ;;
456 niro 616 esac