-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdevel.sh
More file actions
219 lines (196 loc) · 3.86 KB
/
Copy pathdevel.sh
File metadata and controls
219 lines (196 loc) · 3.86 KB
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
# Helpers for developing/debugging installs.
#
# Source this in your shell to use it.
_pkgshell_installer_dir=$(readlink -f $(dirname $BASH_SOURCE))
# Open a shell with the environment setup by a package's env.sh
#
# Usage:
# pkgshell <package name>
#
function pkgshell() {
pkg=$1
pkg_dir=$_pkgshell_installer_dir/packages/$pkg
if [ ! -d $pkg_dir ]; then
echo "No package dir $pkg"
return 1
fi
pkg_env=$pkg_dir/env.sh
tmp_rc=$(mktemp)
cat > $tmp_rc <<EOF
thisdir=$pkg_dir
. $pkg_env
set +e
set +u
EOF
bash --rcfile $tmp_rc
ret=$?
rm $tmp_rc
return $ret
}
# Just echo the standard preamble to a build step
function preamble () {
cat <<"EOF"
#!/bin/bash
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
echo "Don't source me"
return 1
fi
thisdir=$(readlink -f $(dirname $BASH_SOURCE))
. $thisdir/env.sh
EOF
}
function init_pkg() {
local vis
local build
local force=0
local pkg
local PKG
while [[ $# -gt 0 ]]; do
echo $1
case $1 in
-public)
if [ -z "${vis+set}" ]; then
vis=public
shift
else
echo "visibility already set"
return 1
fi
;;
-private)
if [ -z "${vis+set}" ]; then
vis=private
shift
else
echo "visibility already set"
return 1
fi
;;
-cmake)
if [ -z "${build+set}" ]; then
build=cmake
shift
else
echo "build type already set"
return 1
fi
;;
-autotools)
if [ -z "${build+set}" ]; then
build=autotools
shift
else
echo "build type already set"
return 1
fi
;;
-pip)
if [ -z "${build+set}" ]; then
build=pip
shift
else
echo "build type already set"
return 1
fi
;;
-force)
force=1
shift
;;
*)
pkg=$1
shift
if [ $# -gt 0 ]; then
echo "Too many args"
return 1
fi
;;
esac
done
vis=${vis:-public}
build=${build:-unknown}
PKG=${pkg^^}
function should_write_file {
if [ -f $1 ]; then
if [ $force = 1 ]; then
echo "Warning: overwriting file '$1'"
return 0
else
echo "File exists '$1'"
return 1
fi
else
return 0
fi
}
local pkg_dir=$_pkgshell_installer_dir/packages/$pkg
if [ -d $pkg_dir ]; then
echo "Package dir already exists: $pkg_dir"
else
mkdir -p $pkg_dir
fi
local buildbits=""
if [ $build = cmake ]; then
read -d '' buildbits <<EOF
# build_dir_name=set me!
declare -A cmake_vars
EOF
elif [ $build = autotools ]; then
read -d '' buildbits <<EOF
$configure_other_args=
EOF
fi
pushd $pkg_dir
if should_write_file env.sh; then
cat > env.sh <<EOF
if [ -z "\$INSTALLER_${PKG}_ENV_SH" ]; then
INSTALLER_${PKG}_ENV_SH=1
installer_${pkg}_dir=\$(readlink -f \$(dirname \$BASH_SOURCE))
. \$installer_${pkg}_dir/../../env.sh
visibility=$vis
name=$pkg
# version=set me!
# source_dir_name=set me!
$buildbits
installer_init
fi
EOF
fi
if [ $build = pip ]; then
if should_write_file download.sh; then
rm -f download.sh
ln -s "../../generic/${build}/download.sh"
fi
fi
if [ $build != custom ] ; then
for step in configure build install; do
if should_write_file "${step}.sh"; then
rm -f "${step}.sh"
ln -s "../../generic/${build}/${step}.sh"
fi
done
fi
if should_write_file module.sh; then
rm -f module.sh
ln -s "../../generic/module.sh"
fi
if should_write_file all.sh; then
rm -f all.sh
ln -s "../../generic/all.sh"
fi
# Start anything we've not done with the basic preamble
for step in download configure build install module; do
if [ ! -f "${step}.sh" ]; then
preamble > "${step}.sh"
chmod a+x "${step}.sh"
fi
done
if should_write_file modtemplate.tcl; then
cat > modtemplate.tcl <<EOF
#%Module
module-whatis "${pkg} version \${version}"
setenv ${PKG}_DIR "\${prefix}"
EOF
fi
popd
}