Magellan Linux

Contents of /trunk/opengl-update-magellan/opengl-update-2.2.4

Parent Directory Parent Directory | Revision Log Revision Log


Revision 153 - (show annotations) (download)
Tue May 8 20:52:56 2007 UTC (17 years, 5 months ago) by niro
File size: 9852 byte(s)
-import

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