blob: 2333b5967b57b390d155f05c63555af62cbae016 (
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
|
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/app-admin/eselect-gnat/files/gnat-common.bash,v 1.2 2007/09/25 21:06:55 george Exp $
#
# Original Author: George Shapovalov <george@gentoo.org>
# Purpose: Contains common vars/locations and functions for use by gnat.eclass,
# gnat.eselect and gnatbuild.eclass.
#
# NOTE!!!
# This eclass should just define vars (tyr to limit these!) and simple functions.
# No bash extensions!!
# That is, no portage or eclass internals are allowed!
#
# ----------------------------------
# Globals
# Environmantal stuff (for env update)
SPECSDIR="/usr/share/gnat/eselect"
ENVDIR="/etc/env.d"
MARKER="55gnat-"
# ------------------------------------
# Helpers
#
# get_all_profile_components splits gnat profile and returns pace separated list of its components:
# x86_64-pc-linux-gnu-gnat-gcc-4.1 -> x86_64-pc-linux-gnu gcc 4.1
# args:
# $1 - the string to split
get_all_profile_components() {
local GnatSLOT=${1##*-}
local remainder=${1%-*}
local GnatPkg=${remainder##*-}
remainder=${remainder%-gnat-*}
echo "${remainder} ${GnatPkg} ${GnatSLOT}"
}
# similar to above, returns only SLOT component:
# x86_64-pc-linux-gnu-gnat-gcc-4.1 -> 4.1
# args:
# $1 - the string to extract the slot from
get_gnat_SLOT() {
echo "${1##*-}"
}
# returns only Pkg component:
# x86_64-pc-linux-gnu-gnat-gcc-4.1 -> gcc
# args:
# $1 - the string to extract the slot from
get_gnat_Pkg() {
local remainder=${1%-*}
echo "${remainder##*-}"
}
# returns only Arch component:
# x86_64-pc-linux-gnu-gnat-gcc-4.1 -> x86_64-pc-linux-gnu
# args:
# $1 - the string to extract the slot from
get_gnat_Arch() {
echo ${1%-gnat-*}
}
## -------------------------------------------
# gnat profile and lib detection functions
# 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
}
# 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
}
## -----------------------
# princial action - central part of do_set and helpers
# 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
}
# The action!
# Part common for do_set and do_update of gnat.eselect, also used in gnat.eclass
# to set environment during lib build and installation
#
# 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}"
# the next three use the common base
local libBase=$(get_var_from_spec ${SPECSDIR}/${toset} ldpath)
echo "LDPATH=${libBase}:${libBase}/adalib$(get_lib_var_settings LDPATH ${toset} ${libs[@]})" >> "${envfile}"
echo "ADA_INCLUDE_PATH=${libBase}/adainclude$(get_lib_var_settings ADA_INCLUDE_PATH ${toset} ${libs[@]})" >> "${envfile}"
echo "ADA_OBJECTS_PATH=${libBase}/adalib$(get_lib_var_settings ADA_OBJECTS_PATH ${toset} ${libs[@]})" >> "${envfile}"
}
|