summaryrefslogtreecommitdiff
blob: 723a15ea5b7440ba1d28365a5621018a5b99718d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/x11-base/opengl-update/files/opengl-update-3.0.0,v 1.2 2005/08/13 07:43:47 eradicator Exp $
# Author:  Martin Schlemmer <azarah@gentoo.org>
# Further modifications by Donnie Berkholz <spyderous@gentoo.org>
# Further modifications based off submissions to bug #54984 <cyfred@gentoo.org>
# Further modifications by Jeremy Huddleston <eradicator@gentoo.org>


print_usage() {
	cat << FOO
Usage: ${0##*/} [<options>] <GL implementation>
       Set the opengl implementation.
       Valid options:
       --use-old:          If an implementation is already set, use that one.
       --prefix=<val>:     Set the source prefix (default: /usr)
       --dst-prefix=<val>: Set the destination prefix (default: /usr)
       --impl-headers:     Use headers provided by this implementation to
                           override golbal ones provided by opengl-update.

Usage: ${0##*/} --get-implementation
       Print the current implementaion

Notes:
       --impl-headers was default in <opengl-update-2.2.

Examples:
       ${0##*/} xorg-x11
       This will setup things to use libGL.so from X.org.

       ${0##*/} nvidia
       This will setup things to use libGL.so from the nVidia drivers.

WARNING: opengl-update is deprecated and is just a frontend to the opengl
         eselect module.  A future version will drop support for the
         opengl-update command.  Please see 'eselect opengl help'

FOO
}

get_implementations() {
	local implems
	for dir in ${PREFIX}/lib{,32,64}/opengl/*; do 
		if [[ -d "${dir}" && ${dir##*/} != "global" ]] && ! hasq ${dir##*/} ${implems}; then
			implems=${implems:+${implems} }${dir##*/}
		fi
	done
	echo ${implems}
}

parse_options() {
	local opt
	while [[ ${#} -gt 0 ]]; do
		opt=${1}
		shift
		case ${opt} in
			--use-old)
				if [[ -n "${ACTION}" ]]; then
					ACTION="error"
					eerror "Invalid usage."
				else
					if [[ -n "${CURRENT_GL_IMPLEM}" ]] && hasq ${CURRENT_GL_IMPLEM} ${AVAIL_IMPLEMS}; then
						ACTION="old-implementation"
					fi
				fi				
			;;
			--get-implementation)
				if [[ -n "${ACTION}" ]]; then
					ACTION="error"
					eerror "Invalid usage."
				else
					ACTION="get-implementation"
				fi				
			;;
			--prefix=*)
				PREFIX=${opt#*=}
				AVAIL_IMPLEMS=$(get_implementations)
			;;
			--dst-prefix=*)
				DST_PREFIX=${opt#*=}
			;;
			--impl-headers)
				USE_PROFILE_HEADERS="yes"
			;;
			--help|-h|-?)
				ACION="usage"
			;;
			*)
				if hasq ${opt} ${AVAIL_IMPLEMS}; then
					if [[ "${ACTION}" != "old-implementation" ]]; then
						if [[ -n "${ACTION}" ]]; then
							ACTION="error"
							eerror "Invalid usage."
						else
							ACTION="set-implementation"
							NEW_GL_IMPLEM="${opt}"
						fi
					fi				
				else
					eerror "Unrecognized option: ${opt}"
					ACTION="error"
				fi
			;;
		esac
	done
}

## START PROGRAM ##

NEW_GL_IMPLEM=""
ACTION=""
PREFIX="/usr"
DST_PREFIX="/usr"
AVAIL_IMPLEMS=$(get_implementations)
CURRENT_GL_IMPLEM=$(eselect opengl show)
USE_PROFILE_HEADERS="no"

parse_options ${@}

case ${ACTION} in
	get-implementation)
		eselect opengl show
	;;
	old-implementation)
		eselect opengl set --use-old
		exit $?
	;;
	set-implementation)
		local myconf = "set ${NEW_GL_IMPLEM} --prefix=\"${PREFIX}\" --dst-prefix=\"${DST_PREFIX}\""
		if [[ ${USE_PROFILE_HEADERS} == "yes" ]] ; then
			myconf="${myconf} --impl-headers"
		fi
		eselect opengl ${myconf}
	;;
	usage)
		print_usage
		exit 0
	;;
	*)
		print_usage
		exit 1
	;;
esac