blob: dc095b4bc0e7d1ce513ce81dca3f1bd31271fb1b (
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id: gnat.eselect-0.9,v 1.1 2006/05/26 11:21:30 george Exp $
DESCRIPTION="Manage the talled gnat compilers"
MAINTAINER="ada@gentoo.org"
SVN_DATE='$Date: 2006/05/26 11:21:30 $'
VERSION=$(svn_date_to_version "${SVN_DATE}" )
SPECSDIR="/usr/share/gnat/eselect"
ENVDIR="/etc/env.d"
MARKER="55gnat-"
#LibMarker="56"
### Phylosophy
# Each gnat installs a "specs" file named ${ARCH}-${PN}-${SLOT} under ${SPECSDIR}
# Each lib creates a dir with its name under ${SPECSDIR} and populates it with
# similar specs files (same name scheme)
# Recognizing gnat specs from lib specs is then eazy - test entry for being a
# dir, then just check what gnat profiles are installed for each lib..
# doset then creates env file that combines settings for gnat and for the
# corresponding profile of each installed lib..
### Helpers
# create a list of all gnat env.d files
# for now use trivial implementation - store name of active profile in the
# env file name, so it gets called 55gnat-${ARCH}-${PN}-${SLOT}
get_env_list() {
for fn in ${ENVDIR}/${MARKER}*; do
echo $(basename ${fn})
done
}
# return *the* name of the active profile, checking that we do not have multiple
# env files.
# There can be only one!
get_current_gnat() {
local profiles=( $(get_env_list) )
if [ ${profiles[@]} == "${MARKER}*" ]; then exit; fi
if (( 1 == ${#profiles[@]} )); then
local active=${profiles[0]#${MARKER}}
else
die -q "${ENVDIR} contains multiple gnat profiles, please cleanup!"
fi
if [ -f ${SPECSDIR}/${active} ]; then
echo ${active}
else
die -q "the active env.d profile does not correspond to any installed gnat!"
fi
}
# find installed compilers and return a list
find_compilers() {
[ ! -d ${SPECSDIR} ] && exit
for fn in ${SPECSDIR}/*; do
[ ! -d ${fn} ] && echo $(basename ${fn});
done
}
# find installed libs and return a list
find_all_libs() {
[ ! -d ${SPECSDIR} ] && exit
for fn in ${SPECSDIR}/*; do
[ -d ${fn} ] && echo $(basename ${fn});
done
}
# find libs that have been built for a given profile
# Arguments:
# $1 - gnat profile for which to detect active libs
find_libs4profile() {
libs=( $(find_all_libs) )
for (( i = 0 ; i < ${#libs[@]} ; i = i + 1 )) ; do
[ -f ${SPECSDIR}/${libs[$i]}/$1 ] && echo "${libs[$i]}"
done
}
# check if the passed arg represents the installed gnat and return it or
# not_found
# takes args:
# $1 - list ID to check
get_name_from_list() {
compiler=$1
compilers=( $(find_compilers) )
for (( i = 0 ; i < ${#compilers[@]} ; i = i + 1 )) ; do
if [[ ${compilers[$i]} == ${compiler} ]] ; then
echo ${compiler}
return
fi
done
echo "(not-found)"
}
# extracts values of the passed var definition from given spec file
# params:
# $1: spec file (as generated by gnabuild.eclass)
# $2: variable name
get_var_from_spec() {
local var=$(grep -e "^ *$2=" $1|cut -d= -f2)
echo ${var}
}
# Cycle through given libs and form a : separated list of settings for the given
# var. Returned string starts with ":" if there is any non-empty setting,
# otherwise returns empty string
# params:
# $1 - name of env var to process
# $2 - name of gnat profile
# $3.. - list of libs to check (to avoid its composition every time)
# - the list is expanded to lest of args at the point of call
get_lib_var_settings() {
local envVar=$1
local toset=$2
#echo "get_lib_var_settings params:$@" >> /tmp/eselect-gnat.rep
if [[ "none" != ${3} ]]; then
local envString
local specLine
while [[ -n $3 ]]; do
specLine=$(get_var_from_spec ${SPECSDIR}/$3/${toset} ${envVar})
#echo "$3:${specLine}." >> /tmp/eselect-gnat.rep
[[ -n ${specLine} ]] && envString="${envString}:${specLine}"
shift
done
echo "${envString}"
fi
}
# removes env files (for compiler and libs)
# params:
# $1: the name of profile for which to remove env file
unset_env() {
rm -f ${ENVDIR}/${MARKER}$1 &> /dev/null
}
# Stuff common for do_set and do_update
#
# params:
# $1 - profile to set (toset param inside)
# $2 - envfile
generate_envFile() {
local toset=$1
local envfile=$2
local binpath="$(get_var_from_spec ${SPECSDIR}/${toset} binpath)"
local libexecpath="$(get_var_from_spec ${SPECSDIR}/${toset} libexecpath)"
local libs=( $(find_libs4profile ${toset}) )
#echo "generate_envFile: ${libs[@]}" >> /tmp/eselect-gnat.rep
if (( 0 == ${#libs[@]} )); then
libs="none"
fi
local MyPath="${binpath}:${libexecpath}$(get_lib_var_settings PATH ${toset} ${libs[@]})"
echo "PATH=${MyPath}" > "${envfile}"
echo "ROOTPATH=${MyPath}" >> "${envfile}"
echo "MANPATH=$(get_var_from_spec ${SPECSDIR}/${toset} manpath)$(get_lib_var_settings MANPATH ${toset} ${libs[@]})" >> "${envfile}"
echo "INFOPATH=$(get_var_from_spec ${SPECSDIR}/${toset} infopath)$(get_lib_var_settings INFOPATH ${toset} ${libs[@]})" >> "${envfile}"
echo "LDPATH=$(get_var_from_spec ${SPECSDIR}/${toset} ldpath)$(get_lib_var_settings LDPATH ${toset} ${libs[@]})" >> "${envfile}"
echo "ADA_INCLUDE_PATH=$(get_var_from_spec ${SPECSDIR}/${toset} ldpath)/adainclude$(get_lib_var_settings ADA_INCLUDE_PATH ${toset} ${libs[@]})" >> "${envfile}"
echo "ADA_OBJECTS_PATH=$(get_var_from_spec ${SPECSDIR}/${toset} ldpath)/adalib$(get_lib_var_settings ADA_OBJECTS_PATH ${toset} ${libs[@]})" >> "${envfile}"
}
### show action ###
describe_show() {
echo "Show the active gnat compiler/profile and installed libs"
}
do_show() {
write_list_start "Current gnat version:"
active=$(get_current_gnat)
if [ ! -z ${active} ] ; then # not sure why [ -n ] does not do the same
write_kv_list_entry "$active" ""
libs=( $(find_libs4profile ${active}) )
write_list_start "Active libs:"
write_numbered_list "${libs[@]}"
else
write_kv_list_entry "(none set)" ""
fi
}
### list action ###
describe_list() {
echo "List installed gnat compilers and libs"
}
do_list() {
compilers=( $(find_compilers ) )
active=$(get_current_gnat)
write_list_start "Available gnat compilers:"
if [[ -n ${compilers[@]} ]] ; then
local i
for (( i = 0 ; i < ${#compilers[@]} ; i = i + 1 )) ; do
linkversion=${compilers[${i}]}
[[ $linkversion == $active ]] && \
compilers[${i}]="${compilers[${i}]} $(highlight '*' )"
done
write_numbered_list "${compilers[@]}"
# now the libs
libs=( $(find_all_libs) )
write_list_start "Installed libs:"
for (( i = 0 ; i < ${#libs[@]} ; i = i + 1 )) ; do
[ -f ${SPECSDIR}/${libs[$i]}/${active} ] && \
libs[${i}]="${libs[${i}]} $(highlight '*' )"
done
write_numbered_list "${libs[@]}"
else
write_kv_list_entry "(none found)" ""
fi
}
### set action ###
describe_set() {
echo "Set active gnat compiler"
}
# The set action. Parameters:
# $1 - name of profile to set, obligatory, passed by eselect
# $2 - optional, name of env file to generate. Used from gnat.eclass.
do_set() {
if [[ -z ${1} ]] ; then
# no parameter
die -q "You didn't tell me which gnat to use"
fi
local toset=$(get_name_from_list $1)
if [[ ${toset} == "(not-found)" ]] ; then
die -q "I don't recognise the selection"
fi
# the action!
# in this implementation simply create an appropriate env file
local active=$(get_current_gnat)
if [[ -z ${2} ]] ; then
local envfile="${ENVDIR}/${MARKER}${toset}"
# now we need to remove an old env file, which is guaranteed to
# be unique by get_current_gnat above
if [[ -n ${active} ]] ; then
unset_env ${active}
fi
# just for a good measure remove the one we are going to write
unset_env ${toset}
else
local envfile="$2"
fi
generate_envFile ${toset} ${envfile}
}
### update action ###
#
# This action regenerates the /etc/env.d file for the current profile. Basically
# the same as set, only it does not take any parameters. It should be called from ebuilds
# installing Ada libs
describe_update() {
echo "Update active gnat profile picking up new libs."
}
do_update() {
local toset=$(get_current_gnat)
local envfile="${ENVDIR}/${MARKER}${toset}"
generate_envFile ${toset} ${envfile}
}
### unset action ###
describe_unset() {
echo "Remove settings for currently active gnat"
}
do_unset() {
local active=$(get_current_gnat)
# check whether we have any profile set before removing anything..
if [[ -n ${active} ]] ; then
unset_env ${active}
fi
}
|