forked from TritonDataCenter/smartos-live
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·374 lines (336 loc) · 10.4 KB
/
configure
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#!/usr/bin/bash
#
# CDDL HEADER START
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
# CDDL HEADER END
#
#
# Copyright (c) 2012 Joyent, Inc.
#
shopt -s xpg_echo
unalias -a
PATH=/usr/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/local/sbin
export PATH
conf_arg0=$(basename $0)
conf_arg0_dir=$(dirname $0)
conf_root=$PWD
conf_ips=
conf_priv="pfexec"
function warn
{
local msg="$*"
[[ -z "$msg" ]] && msg="failed"
echo "$conf_arg0: $msg" >&2
}
function fatal
{
local msg="$*"
[[ -z "$msg" ]] && msg="failed"
echo "$conf_arg0: $msg" >&2
exit 1
}
function check_loc
{
[[ "$(readlink -f "$PWD")" != "$(readlink -f "$conf_arg0_dir")" ]] && \
fatal "configure must be run from inside $conf_arg0_dir"
[[ "$(uname -s)" != "SunOS" ]] && fatal "build only works on SunOS"
if [[ "$(uname -v)" =~ "joyent_" ]]; then
[[ "$(zonename)" == "global" ]] && fatal \
"building in a GZ on SmartOS is not supported"
else
echo "Not on SmartOS, assuming IPS and sudo"
conf_ips=1
conf_priv="sudo"
fi
}
function create_projects
{
local dir="projects"
[[ -d "$dir" ]] || mkdir -p "$dir" || fatal "failed to create $dir"
}
function source_vars
{
for file in "$(ls configure.*)"; do
source "$file" || fatal "failed to source $file"
done
}
function install_pkgin
{
for pkg in gmake binutils autoconf automake bison flex libtool-base \
python26 py26-expat libxslt gcc-compiler sun-jre6 sun-jdk6 gmp \
mpfr nodejs p5-XML-Parser gettext; do
if ! pkg_info -qe $pkg; then
$conf_priv pkgin -y install $pkg || fatal \
"failed to install $pkg"
fi
done
}
function install_ips
{
fatal "Building on ips based systems has yet to be implemented"
}
function install_packages
{
if [[ -z "$conf_ips" ]]; then
install_pkgin
else
install_ips
fi
[[ $? -eq 0 ]] || fatal "failed to install packages"
}
function fetch_studio
{
[[ -f "/opt/SUNWspro/prod/bin/cc" ]] && return
[[ -z "$SUNW_SPRO12_URL" ]] && fatal \
"SUNW_SPRO12_URL not set in configure.*"
curl -k "$SUNW_SPRO12_URL" | bzcat | $conf_priv tar xf - -C /opt
[[ $? -eq 0 ]] || fatal "failed to fetch Studio"
[[ -e /opt/SUNspro/sunstudio12.1 ]] && return
$conf_priv ln -s /opt/SUNWspro /opt/SUNWspro/sunstudio12.1 || fatal \
"cannot create Studio symlink"
}
function fetch_illumos
{
local tfile="projects/illumos/usr/src/tools/env/illumos.sh"
[[ -f "$tfile" ]] && return
[[ -z "$GET_ILLUMOS" ]] && fatal "configure must define GET_ILLUMOS"
cd projects >/dev/null || fatal "failed to cd into projects directory"
/bin/bash -c "$GET_ILLUMOS " || fatal "fetching illumos failed"
cd - >/dev/null || fatal "failed to cd out of projects directory"
[[ -f "$tfile" ]] || fatal "fetched illumos appears to be missing files"
}
function fetch_illumos_extra
{
local tfile="projects/illumos-extra/Makefile"
[[ -f "$tfile" ]] && return
[[ -z "$GET_ILLUMOS_EXTRA" ]] && fatal \
"configure must define GET_ILLUMOS_EXTRA"
cd projects >/dev/null || fatal "failed to cd into projects directory"
/bin/bash -c "$GET_ILLUMOS_EXTRA" || fatal \
"fetching illumos-extra failed"
cd - >/dev/null || fatal "failed to cd out of projects directory"
[[ -f "$tfile" ]] || fatal \
"fetched illumos-extra appears to be missing files"
}
function fetch_adjuncts
{
local tgz
[[ -z "$ILLUMOS_ADJUNCT_TARBALL_URL" ]] && fatal \
"ILLUMOS_ADJUNCT_TARBALL_URL missing from configure"
tgz=$(curl -k "$ILLUMOS_ADJUNCT_TARBALL_URL" | grep href | tail -n1 | \
cut -d '"' -f2)
[[ -z "$tgz" ]] && fatal \
"Unable to get adjuncts from ILLUMOS_ADJUNCT_TARBALL_URL"
curl -kO $ILLUMOS_ADJUNCT_TARBALL_URL/$tgz
[[ $? -eq 0 ]] || fatal "failed to fetch adjuncts tarball"
}
function setup_overlays
{
local of="overlay/order"
[[ -z "$OVERLAYS" ]] && fatal \
"OVERLAYS variable missing from configure.*"
rm -f $of
touch $of || fail "failed to create $of"
for o in $OVERLAYS; do
echo -n "$conf_root/overlay/$o " >> $of || fatal \
"failed to append to $of"
done
}
function fetch_closed
{
local ildir="projects/illumos"
local cld="on-closed-bin.i386.tar.bz2"
local clnd="on-closed-bin-nd.i386.tar.bz2"
[[ -z "$ON_CLOSED_BINS_URL" ]] && fatal \
"missing ON_CLOSED_BINS_URL from configure"
[[ -z "$ON_CLOSED_BINS_ND_URL" ]] && fatal \
"missing ON_CLOSED_BINS_ND_URL from configure"
if [[ ! -f $ildir/$cld ]]; then
curl -k $ON_CLOSED_BINS_URL -o $ildir/$cld || fatal \
"failed to fetch closed bins (debug)"
fi
if [[ ! -f $ildir/$clnd ]]; then
curl -k $ON_CLOSED_BINS_ND_URL -o $ildir/$clnd || fatal \
"failed to fetch closed bins (non-debug)"
fi
cd $ildir >/dev/null 2>&1 || fatal "failed to cd into $ildir"
tar xpjf $cld || fatal \
"failed to extract closed bins (debug)"
tar xpjf $clnd || fatal \
"failed to extract closed bins (non-debug)"
cd - >/dev/null 2>&1
}
function generate_env
{
local nopts="-CimNnt"
local lint debug lprefix
if [[ -n "$ILLUMOS_ENABLE_LINT" ]]; then
lint=1
debug=1
fi
if [[ "$ILLUMOS_ENABLE_DEBUG" == "exclusive" ]]; then
debug=2
elif [[ "$ILLUMOS_ENABLE_DEBUG" == "yes" ]]; then
debug=1
elif [[ -n "$ILLUMOS_ENABLE_DEBUG" ]]; then
fatal "Unknown value for $ILLUMOS_ENABLE_DEBUG"
fi
[[ -n "$lint" ]] && nopts="${nopts}l"
[[ "$debug" -eq 1 ]] && nopts="${nopts}D"
[[ "$debug" -eq 2 ]] && nopts="${nopts}DF"
lprefix=$(echo $conf_root | tr / _)
[[ $? -eq 0 ]] || fatal "failed to create lock prefix"
cat > "projects/illumos/illumos.sh" <<EOF
NIGHTLY_OPTIONS="$nopts"; export NIGHTLY_OPTIONS
GATE="${RELEASE_VER}"; export GATE
CODEMGR_WS="$conf_root/projects/illumos"; export CODEMGR_WS
maxjobs() {
ncpu=\`kstat -p cpu_info:::state | grep -c on-line\`
expr \$ncpu + 2
}
DMAKE_MAX_JOBS=\`maxjobs\`; export DMAKE_MAX_JOBS
PARENT_WS=""; export PARENT_WS
CLONE_WS="http://hg.illumos.org/illumos-gate" export CLONE_WS
STAFFER="nobody"; export STAFFER
BUILD_PROJECT=""; export BUILD_PROJECT
LOCKNAME="\`whoami\`_${lprefix}_nightly.lock"; export LOCKNAME
ATLOG="\$CODEMGR_WS/log"; export ATLOG
LOGFILE="\$ATLOG/nightly.log"; export LOGFILE
MACH=\`uname -p\`; export MACH
ON_CLOSED_BINS="\$CODEMGR_WS/closed"; export ON_CLOSED_BINS
REF_PROTO_LIST="\$PARENT_WS/usr/src/proto_list_\${MACH}";
export REF_PROTO_LIST
ROOT="$conf_root/proto"; export ROOT
ADJUNCT_PROTO="$conf_root/proto.strap"; export ADJUNCT_PROTO
NATIVE_ADJUNCT="/opt/local"; export NATIVE_ADJUNCT
SRC="\$CODEMGR_WS/usr/src"; export SRC
VERSION="\$GATE"; export VERSION
PARENT_ROOT="$conf_root/proto"; export PARENT_ROOT
PARENT_TOOLS_ROOT="\$PARENT_WS/usr/src/tools/proto/root_\$MACH-nd"
export PARENT_TOOLS_ROOT
PKGARCHIVE="\${CODEMGR_WS}/packages/\${MACH}/nightly";
export PKGARCHIVE
PKGPUBLISHER_REDIST="${PUBLISHER}"; export PKGPUBLISHER_REDIST
MAKEFLAGS=k; export MAKEFLAGS
UT_NO_USAGE_TRACKING="1"; export UT_NO_USAGE_TRACKING
CW_NO_SHADOW="1"; export CW_NO_SHADOW
BUILD_TOOLS="\${CODEMGR_WS}/usr/src/tools/proto/root_\${MACH}-nd/opt";
export BUILD_TOOLS
SPRO_ROOT=/opt/SUNWspro; export SPRO_ROOT
SPRO_VROOT=\$SPRO_ROOT; export SPRO_VROOT
GNU_ROOT="$conf_root/proto.strap/usr/gnu" export GNU_ROOT
GCC_ROOT="$conf_root/proto.strap/usr"; export GCC_ROOT
# A temporary hack to allow bootstrap of cw(1)
CW_GCC_DIR="\${GCC_ROOT}/bin"; export CW_GCC_DIR
# Use GCC as the primary compiler
__GNUC=""; export __GNUC
# Use GCC4 specific flags
__GNUC4=""; export __GNUC4
JAVA_ROOT=/opt/local/java/sun6; export JAVA_ROOT
FLEX=/opt/local/bin/flex; export FLEX
GNUXGETTEXT=/opt/local/bin/xgettext; export GNUXGETTEXT
PYTHON_26=/opt/local/bin/python2.6; export PYTHON_26
EOF
[[ $? -eq 0 ]] || fatal "failed to write illumos nightly env file"
}
function update_git
{
local path=$1
local branch=$2
local cur
[[ -d "$path" ]] || fatal "can't find directory $path"
[[ -z "$branch" ]] && fatal "unspecified branch"
cd $path >/dev/null 2>&1 || fatal "can't cd into $path"
cur=$(git branch | grep "^*" | awk 'BEGIN{ FS=" " } { print $2 }')
[[ $? -ne 0 || -z "$cur" ]] && fatal "failed to get current branch"
[[ "$cur " == "$branch" ]] && return
git checkout $branch >/dev/null || fatal "failed to checkout $branch"
cd - >/dev/null 2>&1 || fatal "can't return to previous directory"
}
function update_branches
{
local line repo branch
[[ ! -f "configure-branches" ]] && return
while read line; do
line=$(echo $line | sed -e 's/#.*$//')
[[ $? -eq 0 ]] || fatal \
"failed to remove comments in configure-branches"
[[ -z "$line" ]] && continue
repo=${line%%:*}
branch=${line##*:}
[[ -z "$repo" ]] && fatal \
"missing repository entry in line: [$line]"
[[ -z "$branch" ]] && fatal \
"missing branch entry in line: [$branch]"
#
# Handle the legacy name of smartos-live
#
if [[ "$repo" == "smartos-live" || \
"$repo" == "illumos-live" ]]; then
warn "configure-branches can't update smartos-live"
warn "ignoring and continuing on..."
continue
fi
if [[ "$repo" == "illumos-joyent" || \
"$repo" == "illumos" ]]; then
update_git "projects/illumos" $branch && continue
elif [[ "$repo" == "illumos-extra" ]]; then
update_git "projects/illumos-extra" $branch && continue
else
[[ -d "projects/local/$repo" ]] && update_git \
"projects/local/$repo" $branch && continue
fi
fatal "failed to update $repo to $branch"
done < "configure-branches"
}
echo "Doing pre-flight checks... \c "
check_loc
echo "done."
echo "Creating projects directory ... \c "
create_projects
echo "done."
echo "Sourcing configure.* files ... \c "
source_vars
echo "done."
echo "Installing packages ... \c "
install_packages
echo "done."
echo "Fetching studio... \c "
fetch_studio
echo "done."
echo "Fetching illumos... \c "
fetch_illumos
echo "done."
echo "Fetching illumos-extra... \c "
fetch_illumos_extra
echo "done."
echo "Fetching adjuncts tgz... \c "
fetch_adjuncts
echo "done."
echo "Configuring overlays... \c "
setup_overlays
echo "done."
echo "Fetching and extracting closed bins ... \c "
fetch_closed
echo "done."
echo "Generating illumos environment file... \c "
generate_env
echo "done."
echo "Setting up branches... \c "
update_branches
echo "done."
cat <<EOF
Configuration complete. To build the live image run:
gmake world && gmake live
EOF
# Congrats, we made it
exit 0