blob: 46c7d425d2973f07c7411d9645d7e1a6c6bccabc (
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
|
# -*-eselect-*- vim: ft=eselect
# Copyright 2014-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
inherit config multilib
DESCRIPTION="Manage luajit symlinks"
MAINTAINER="ilmostro7@gmail.com"
HEADER_FILES="luajit.h"
remove_symlinks() {
unlink "${EROOT}"/usr/bin/{luajit} &>/dev/null
for dir in $(get_libdirs) ; do
unlink "${EROOT}"${dir}/libluajit.so &>/dev/null && \
unlink "${EROOT}"${dir}/pkgconfig/luajit.pc &>/dev/null
done
for f in $HEADER_FILES ; do
unlink "${EROOT}"/usr/include/$f
done
unlink "${EROOT}"/usr/share/man/man1/{luajit}.1{,.gz,.bz2,.lzma} &>/dev/null
}
set_symlinks() {
local ver=$1
ln -s "${EROOT}"/usr/bin/luajit{$ver,}
for dir in $(get_libdirs) ; do
ln -s "${dir}"/libluajit{$ver,}.so
ln -s "${dir}"/pkgconfig/luajit{$ver,}.pc
done
for orig in "${EROOT}"/usr/share/man/man1/lua*$ver.1* ; do
ln -s "${orig}" "${orig//$ver}"
done
for f in $HEADER_FILES ; do
ln -s "${EROOT}"/usr/include/luajit$ver/$f "${EROOT}"/usr/include
done
}
get_libdirs() {
local dir libdirs
for dir in $(list_libdirs); do
[[ -L ${EROOT}/usr/${dir} ]] && continue
ls "${EROOT}"/usr/${dir}/libluajit*.* > /dev/null 2>&1 || continue
libdirs+=' '${EPREFIX}/usr/${dir}
done
echo ${libdirs:-${EPREFIX}/usr/lib}
}
find_targets() {
local dirs
local prefix="${EROOT}/usr/bin/luajit"
for f in ${prefix}2* ; do
dirs="${dirs} ${f##$prefix}"
done
echo $dirs
}
resolv_target() {
local targets=( $(find_targets) )
if is_number $1; then
[[ $1 -le ${#targets[@]} && $1 -gt 0 ]] && echo "${targets[ $(( $1 - 1 )) ]}"
elif has $1 ${targets[@]}; then
echo $1
fi
}
get_active_version() {
readlink -e "${EROOT}"/usr/bin/luajit | sed -ne "s:.*/usr/bin/luajit\([\d.-]*\):\1:p"
}
## Actual actions
## set action
describe_set() {
echo "Sets the current version of luajit"
}
describe_set_parameters() {
echo '<target>'
}
describe_set_options() {
echo 'target: Target name or number (from "list" action)'
}
do_set() {
local target=$(resolv_target $1)
if [[ -z "${target}" ]]; then
die -q "You need to specify a version"
fi
remove_symlinks
set_symlinks $target
}
## List action
describe_list() {
echo 'Lists available luajit versions'
}
do_list() {
local targets
local a
targets=( $(find_targets) )
a=$(get_active_version)
for (( i = 0; i < ${#targets[@]}; i++ )) ; do
[[ $a == ${targets[i]} ]] && targets[i]=$(highlight_marker "${targets[i]}")
done
write_numbered_list -m '(none found)' "${targets[@]}"
}
## Show action
describe_show() {
echo 'Show the active luajit version'
}
do_show() {
get_active_version
}
## update action
describe_update() {
echo 'Automatically update the luajit version'
}
describe_update_options() {
echo 'ifunset : Do not override existing implementation'
}
do_update() {
[[ -n ${1} && ! ( ${1} == ifunset || ${1} == '--if-unset' ) ]] && \
die -q 'Usage error'
[[ ( ${1} == ifunset || ${1} == '--if-unset' ) && -n $(get_active_version) ]] && \
return
remove_symlinks
local targets=( $(find_targets) )
if [[ -n ${#targets[@]} ]] ; then
local target=${targets[${#targets[@]} - 1]}
set_symlinks $target || echo 'Nothing to update'
fi
}
|