Magellan Linux

Diff of /tags/openglupdate-2_3_1/opengl-update.in

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 616 by niro, Wed Nov 14 18:01:25 2007 UTC revision 617 by niro, Wed Nov 14 18:15:11 2007 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2  # Copyright 1999-2004 Gentoo Foundation  # Copyright 1999-2004 Gentoo Foundation
3  # Distributed under the terms of the GNU General Public License v2  # 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 $  # $Header: /home/cvsd/magellan-cvs/magellan-src/opengl-update/opengl-update.sh,v 1.2 2007-11-14 18:15:11 niro Exp $
5  # Author:  Martin Schlemmer <azarah@gentoo.org>  # Author:  Martin Schlemmer <azarah@gentoo.org>
6  # Further modifications by Donnie Berkholz <spyderous@gentoo.org>  # Further modifications by Donnie Berkholz <spyderous@gentoo.org>
7  # Further modifications based off submissions to bug #54984 <cyfred@gentoo.org>  # Further modifications based off submissions to bug #54984 <cyfred@gentoo.org>
# Line 13  Line 13 
13    
14  . /etc/init.d/functions  . /etc/init.d/functions
15    
16  hasq() {  hasq()
17    {
18   local x   local x
19    
20   local me=${1}   local me=${1}
21   shift   shift
22            
23   for x in "${@}"; do   for x in $@
24   if [[ "${x}" == "${me}" ]]; then   do
25   return 0   [[ ${x} = ${me} ]] && return 0
  fi  
26   done   done
27    
28   return 1   return 1
29  }  }
30    
31  check_user() {  check_user()
32   if [[ $(id -u) -ne 0 ]]; then  {
33     if [[ $(id -u) -ne 0 ]]
34     then
35   echo "${0}: Must be run as root."   echo "${0}: Must be run as root."
36   exit 1   exit 1
37   fi   fi
38  }  }
39    
40  get_current_implem() {  get_current_implem()
41    {
42   local implem   local implem
43   if [[ -f ${ENV_D} ]]; then  
44     if [[ -f ${ENV_D} ]]
45     then
46   source ${ENV_D}   source ${ENV_D}
47   if [[ -n "${OPENGL_PROFILE}" ]]; then   if [[ -n ${OPENGL_PROFILE} ]]
48     then
49   implem="${OPENGL_PROFILE}"   implem="${OPENGL_PROFILE}"
50   elif [[ -n "${LDPATH}" ]]; then   elif [[ -n ${LDPATH} ]]
51     then
52   implem="${LDPATH%%:*}"   implem="${LDPATH%%:*}"
53   implem="${implem##*opengl/}"   implem="${implem##*opengl/}"
54   implem="${implem%/lib*}"   implem="${implem%/lib*}"
# Line 52  get_current_implem() { Line 60  get_current_implem() {
60   echo ${implem}   echo ${implem}
61  }  }
62    
63  get_implementations() {  get_implementations()
64    {
65   local implems   local implems
66   for dir in ${PREFIX}/lib{,32,64}/opengl/*; do  
67   if [[ -d "${dir}" && ${dir##*/} != "global" ]] && ! hasq ${dir##*/} ${implems}; then   for dir in ${PREFIX}/lib{,32,64}/opengl/*
68     do
69     if [[ -d ${dir} ]] &&
70     [[ ${dir##*/} != global ]]
71     && ! hasq ${dir##*/} ${implems}
72     then
73   implems=${implems:+${implems} }${dir##*/}   implems=${implems:+${implems} }${dir##*/}
74   fi   fi
75   done   done
76    
77   echo ${implems}   echo ${implems}
78  }  }
79    
80  print_version() {  print_version()
81    {
82   echo "opengl-update ${VERSION}"   echo "opengl-update ${VERSION}"
83  }  }
84    
85  print_usage() {  print_usage()
86    {
87   # Get grammar right in message   # Get grammar right in message
88   local IS_ARE IMPLEM_PLURAL   local IS_ARE IMPLEM_PLURAL
89   if [[ $(echo ${AVAIL_IMPLEMS} | wc -w) -eq 1 ]]; then  
90     if [[ $(echo ${AVAIL_IMPLEMS} | wc -w) -eq 1 ]]
91     then
92   IS_ARE="is"   IS_ARE="is"
93   IMPLEM_PLURAL=""   IMPLEM_PLURAL=""
94   else   else
# Line 109  FOO Line 128  FOO
128   exit 1   exit 1
129  }  }
130    
131  parse_options() {  parse_options()
132    {
133   local opt   local opt
134   while [[ ${#} -gt 0 ]]; do  
135     while [[ ${#} -gt 0 ]]
136     do
137   opt=${1}   opt=${1}
138   shift   shift
139   case ${opt} in   case ${opt} in
140   --use-old)   --use-old)
141   if [[ -n "${ACTION}" ]]; then   if [[ -n ${ACTION} ]]
142     then
143   ACTION="error"   ACTION="error"
144   echo "Invalid usage."   echo "Invalid usage."
145   else   else
146   if [[ -n "${CURRENT_GL_IMPLEM}" ]] && hasq ${CURRENT_GL_IMPLEM} ${AVAIL_IMPLEMS}; then   if [[ -n "${CURRENT_GL_IMPLEM}" ]] &&
147     hasq ${CURRENT_GL_IMPLEM} ${AVAIL_IMPLEMS}
148     then
149   ACTION="old-implementation"   ACTION="old-implementation"
150   fi   fi
151   fi   fi
152   ;;   ;;
153    
154   --get-implementation)   --get-implementation)
155   if [[ -n "${ACTION}" ]]; then   if [[ -n ${ACTION} ]]
156     then
157   ACTION="error"   ACTION="error"
158   echo "Invalid usage."   echo "Invalid usage."
159   else   else
160   ACTION="get-implementation"   ACTION="get-implementation"
161   fi   fi
162   ;;   ;;
163    
164   --prefix=*)   --prefix=*)
165   PREFIX=${opt#*=}   PREFIX=${opt#*=}
166   AVAIL_IMPLEMS=$(get_implementations)   AVAIL_IMPLEMS=$(get_implementations)
167   ;;   ;;
168   --dst-prefix=*)  
169   DST_PREFIX=${opt#*=}   --dst-prefix=*) DST_PREFIX=${opt#*=} ;;
170   ;;  
171   --impl-headers)   --impl-headers) USE_PROFILE_HEADERS="yes" ;;
172   USE_PROFILE_HEADERS="yes"  
173   ;;   --help|-h|-?) ACION="usage" ;;
174   --help|-h|-?)  
175   ACION="usage"   --version) ACTION="version" ;;
176   ;;  
  --version)  
  ACTION="version"  
  ;;  
177   *)   *)
178   if hasq ${opt} ${AVAIL_IMPLEMS}; then   if hasq ${opt} ${AVAIL_IMPLEMS}
179   if [[ "${ACTION}" != "old-implementation" ]]; then   then
180   if [[ -n "${ACTION}" ]]; then   if [[ ${ACTION} != old-implementation ]]
181     then
182     if [[ -n ${ACTION} ]]
183     then
184   ACTION="error"   ACTION="error"
185   echo "Invalid usage."   echo "Invalid usage."
186   else   else
187   ACTION="set-implementation"   ACTION="set-implementation"
188   NEW_GL_IMPLEM="${opt}"   NEW_GL_IMPLEM="${opt}"
189   fi   fi
190   fi   fi
191   else   else
192   echo "Unrecognized option: ${opt}"   echo "Unrecognized option: ${opt}"
193   ACTION="error"   ACTION="error"
194   fi   fi
195   ;;   ;;
196   esac   esac
197   done   done
198  }  }
199    
200  set-new-implementation() {  set-new-implementation()
201    {
202   local GL_IMPLEM=${1}   local GL_IMPLEM=${1}
203   local GL_LOCAL   local GL_LOCAL
204    
# Line 178  set-new-implementation() { Line 207  set-new-implementation() {
207   # Set a sane umask... bug #83115   # Set a sane umask... bug #83115
208   umask 022   umask 022
209    
210   if ! hasq ${GL_IMPLEM} ${AVAIL_IMPLEMS}; then   if ! hasq ${GL_IMPLEM} ${AVAIL_IMPLEMS}
211     then
212   echo "Invalid profile selected."   echo "Invalid profile selected."
213   exit 1   exit 1
214   fi   fi
215    
216   echo "Switching to ${GL_IMPLEM} OpenGL interface"   echo "Switching to ${GL_IMPLEM} OpenGL interface"
  rm -f ${ENV_D} &> /dev/null  
217    
218   LIBDIRS="lib32 lib lib64"   rm -f ${ENV_D} &> /dev/null
219   for LIBDIR in ${LIBDIRS}; do  
220   # Special case handling of lib32 because it can be a symlink to   LIBDIRS="lib32 lib lib64"
221   # emul libs   for LIBDIR in ${LIBDIRS}
222   if [[ "${LIBDIR}" = "lib32" ]]; then   do
223   [[ -d "${PREFIX}/${LIBDIR}/opengl" ]] || continue   # Special case handling of lib32 because it can be a symlink to
224   else   # emul libs
225   [[ -d "${PREFIX}/${LIBDIR}/opengl" && ! -h "${PREFIX}/${LIBDIR}" ]] || continue   if [[ ${LIBDIR} = lib32 ]]
226   fi   then
227     [[ -d ${PREFIX}/${LIBDIR}/opengl ]] || continue
228   # Fallback on xorg if we don't have this implementation for this LIBDIR.   else
229   if [[ ! -d ${PREFIX}/${LIBDIR}/opengl/"${GL_IMPLEM}" ]]; then   [[ -d ${PREFIX}/${LIBDIR}/opengl ]] &&
230   GL_LOCAL="xorg"   ! -h ${PREFIX}/${LIBDIR} ]] || continue
231   else   fi
232   GL_LOCAL="${GL_IMPLEM}"  
233   fi   # Fallback on xorg if we don't have this implementation for this LIBDIR.
234     if [[ ! -d ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM} ]]
235   mkdir -p ${DST_PREFIX}/${LIBDIR}   then
236   pushd ${DST_PREFIX}/${LIBDIR} &> /dev/null   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   # First remove old symlinks   # First remove old symlinks
272   for file in libGL{,core}.{a,so,la} ; do   for file in libGL{,core}.{a,so,la}
273     do
274   [[ -h ${file} ]] && rm -f ${file}   [[ -h ${file} ]] && rm -f ${file}
275   done   done
276    
277   # Note that we don't do .so*, just .so on purpose.  The   for file in ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/tls/libGL{,core}.{so,a,la}
278   # loader knows to look in the profile dir, and the   do
279   # linked just needs the .so   [[ -f ${file} ]] || continue
280   for file in ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/libGL{,core}.{so,a,la}; do   [[ -f ${file##*/} ]] && rm -f ${file##*/}
  [[ -f "${file}" ]] || continue  
  [[ -f "${file##*/}" ]] && rm -f ${file##*/}  
281    
282   # Fix libtool archives (#48297)   # Fix libtool archives (#48297)
283   if [[ "${file%.la}" != "${file}" ]]; then   if [[ ${file%.la} != ${file} ]]
284     then
285   sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/}   sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/}
286   else   else
287   ln -s ${file}   ln -s ${file}
288   fi   fi
289   done   done
290   popd &> /dev/null   popd &> /dev/null
291     fi
292    
293   if [[ -e "${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/tls" ]]; then   local MODULEDIR
294   mkdir -p ${DST_PREFIX}/${LIBDIR}/tls   if [[ -e ${DST_PREFIX}/${LIBDIR}/xorg/modules ]]
295   pushd ${DST_PREFIX}/${LIBDIR}/tls &> /dev/null   then
296   # First remove old symlinks   MODULEDIR="xorg/modules"
297   for file in libGL{,core}.{a,so,la} ; do   else
298   [[ -h ${file} ]] && rm -f ${file}   MODULEDIR="modules"
299   done   fi
300    
301   for file in ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib/tls/libGL{,core}.{so,a,la}; do   if [[ -e ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/extensions ]]
302   [[ -f "${file}" ]] || continue   then
303   [[ -f "${file##*/}" ]] && rm -f ${file##*/}   mkdir -p ${DST_PREFIX}/${LIBDIR}/${MODULEDIR}/extensions
304     pushd ${DST_PREFIX}/${LIBDIR}/${MODULEDIR}/extensions &> /dev/null
305   # Fix libtool archives (#48297)   # First remove old symlinks
306   if [ "${file%.la}" != "${file}" ]; then   for file in libglx.so libglx.a
307   sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/}   do
308   else   [[ -h ${file} ]] && rm -f ${file}
309   ln -s ${file}   done
310   fi  
311   done   for file in ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/extensions/*.{so,a,la}
312   popd &> /dev/null   do
313   fi   [[ -f ${file} ]] || continue
314     [[ -f ${file##*/} ]] && rm -f ${file##*/}
315   local MODULEDIR  
316   if [[ -e "${DST_PREFIX}/${LIBDIR}/xorg/modules" ]]; then   # Fix libtool archives (#48297)
317   MODULEDIR="xorg/modules"   if [[ ${file%.la} != ${file} ]]
318   else   then
319   MODULEDIR="modules"   sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/}
320   fi   else
321     ln -s ${file}
  if [[ -e "${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/extensions" ]]; then  
  mkdir -p ${DST_PREFIX}/${LIBDIR}/${MODULEDIR}/extensions  
  pushd ${DST_PREFIX}/${LIBDIR}/${MODULEDIR}/extensions &> /dev/null  
  # First remove old symlinks  
  for file in libglx.so libglx.a; do  
  [[ -h ${file} ]] && rm -f ${file}  
  done  
   
  for file in ${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/extensions/*.{so,a,la}; do  
  [[ -f "${file}" ]] || continue  
  [[ -f "${file##*/}" ]] && rm -f ${file##*/}  
   
  # Fix libtool archives (#48297)  
  if [[ "${file%.la}" != "${file}" ]]; then  
  sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${LIBDIR}:g" ${file} > ${file##*/}  
  else  
  ln -s ${file}  
  fi  
  done  
  popd &> /dev/null  
  fi  
   
  # Setup the includes  
  mkdir -p ${DST_PREFIX}/include/GL  
  pushd ${DST_PREFIX}/include/GL &> /dev/null  
  for file in gl.h glx.h glxtokens.h glext.h glxext.h glxmd.h glxproto.h; do  
  # IMPORTANT  
  # It is preferable currently to use the standard glext.h file  
  # however if an OpenGL provider must use a self produced glext.h  
  # then it should be installed to ${GL_IMPLEM}/include and the user  
  # can add the --impl-headers option to select it.  
   
  if [[ ${USE_PROFILE_HEADERS} == "yes" ]] ; then  
  # Check the profile first.  
  if [[ -e ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${file} ]]; then  
  [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file}  
  ln -s ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${file}  
  fi  
  continue  
322   fi   fi
323     done
324     popd &> /dev/null
325     fi
326    
327   if [[ -e ${PREFIX}/${LIBDIR}/opengl/global/include/${file} ]]; then   # Setup the includes
328   [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file}   mkdir -p ${DST_PREFIX}/include/GL
329   ln -s ${PREFIX}/${LIBDIR}/opengl/global/include/${file}   pushd ${DST_PREFIX}/include/GL &> /dev/null
330   elif [[ -e ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${file} ]]; then   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    
338     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   [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file}   [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file}
344   ln -s ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${file}   ln -s ${PREFIX}/${LIBDIR}/opengl/${GL_IMPLEM}/include/${file}
  elif [[ -e ${PREFIX}/${LIBDIR}/opengl/xorg/include/${file} ]]; then  
  [[ -f "${file}" || ( -L "${file}" && ! -e "${file}" ) ]] && rm -f ${file}  
  ln -s ${PREFIX}/${LIBDIR}/opengl/xorg/include/${file}  
345   fi   fi
346   done   continue
347   popd &> /dev/null   fi
348    
349   # Setup the $LDPATH   if [[ -e ${PREFIX}/${LIBDIR}/opengl/global/include/${file} ]]
350   ldpath="${ldpath:+${ldpath}:}${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib"   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    
365   done   # Setup the $LDPATH
366     ldpath="${ldpath:+${ldpath}:}${PREFIX}/${LIBDIR}/opengl/${GL_LOCAL}/lib"
367    
368   echo "LDPATH=\"${ldpath}\"" > ${ENV_D}   done
  echo "OPENGL_PROFILE=\"${GL_IMPLEM}\"" >> ${ENV_D}  
369    
370   env-rebuild   echo "LDPATH=\"${ldpath}\"" > ${ENV_D}
371     echo "OPENGL_PROFILE=\"${GL_IMPLEM}\"" >> ${ENV_D}
372    
373     env-rebuild
374    
375   return 0   return 0
376  }  }
# Line 338  parse_options ${@} Line 391  parse_options ${@}
391    
392  case ${ACTION} in  case ${ACTION} in
393   get-implementation)   get-implementation)
394   if [[ -n "${CURRENT_GL_IMPLEM}" ]]; then   if [[ -n ${CURRENT_GL_IMPLEM} ]]
395     then
396   echo ${CURRENT_GL_IMPLEM}   echo ${CURRENT_GL_IMPLEM}
397   exit 0   exit 0
398   else   else
399   exit 2   exit 2
400   fi   fi
401   ;;   ;;
402    
403   old-implementation)   old-implementation)
404   set-new-implementation ${CURRENT_GL_IMPLEM}   set-new-implementation ${CURRENT_GL_IMPLEM}
405   exit $?   exit $?
406   ;;   ;;
407    
408   set-implementation)   set-implementation)
409   if [[ -n "${NEW_GL_IMPLEM}" ]]; then   if [[ -n ${NEW_GL_IMPLEM} ]]
410     then
411   set-new-implementation ${NEW_GL_IMPLEM}   set-new-implementation ${NEW_GL_IMPLEM}
412   exit $?   exit $?
413   else   else
414   print_usage   print_usage
415   exit 1   exit 1
416   fi   fi
417   ;;   ;;
418    
419   version)   version)
420   print_version   print_version
421   exit 0   exit 0
422   ;;   ;;
423    
424   usage)   usage)
425   print_usage   print_usage
426   exit 0   exit 0
427   ;;   ;;
428    
429   error)   error)
430   print_usage   print_usage
431   exit 1   exit 1
432   ;;   ;;
433    
434   *)   *)
435   print_usage   print_usage
436   exit 1   exit 1
437   ;;   ;;
438  esac  esac

Legend:
Removed from v.616  
changed lines
  Added in v.617