Magellan Linux

Annotation of /trunk/opengl-update-magellan/opengl-update-2.2.1

Parent Directory Parent Directory | Revision Log Revision Log


Revision 153 - (hide annotations) (download)
Tue May 8 20:52:56 2007 UTC (17 years ago) by niro
File size: 9629 byte(s)
-import

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