This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
bootstrap
executable file
·215 lines (181 loc) · 7.01 KB
/
bootstrap
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
#!/usr/bin/env bash
########################################################################
# Regenerate auto-generated files (e.g. configure)
#
# If the -s option is given, save the autogenerated scripts in
# $SAGE_ROOT/upstream/configure-$CONFVERSION.tar.gz where CONFVERSION
# is the sha1 of HEAD `git rev-parse HEAD`
#
# If optional argument -d is given and bootstrapping failed, instead
# extract the files from a local configure tarball, downloading it if
# needed. If -D is given, don't try to bootstrap and always extract or
# download.
#
# If optional argument -u <URL> is given download the configure
# tarball from that base url. That is, "bootstrap -u http://host/path"
# will download http://host/path/configure-$CONFVERSION.tar.gz to
# upstream/configure-$CONFVERSION.tar.gz. This is used by the buildbot
# to download tarballs that are not published.
########################################################################
# Set SAGE_ROOT to the path to this file and then cd into it
SAGE_ROOT="$(cd "$(dirname "$0")" && pwd -P)"
cd "$SAGE_ROOT"
export PATH="$SAGE_ROOT/build/bin:$PATH"
PKG=build/pkgs/configure
MAKE="${MAKE:-make}"
CONFVERSION=$(cat $PKG/package-version.txt)
install_config_rpath() {
# The file config.rpath which comes from gettext is supposed to be
# installed by automake, but due to a bug in most distros it is not;
# see https://trac.sagemath.org/ticket/27823#comment:17
#
# Here we need to determine where gettext stores its data files and
# copy config.rpath from there to config/
gettextize="$(command -v gettextize)"
if [ -z "$gettextize" ]; then
echo >&2 "gettext and the gettextize program must be installed and be in"
echo >&2 "your PATH. E.g. Homebrew installs them in /usr/local/opt/gettext/bin."
return 179
fi
eval `sed -n '/^prefix=.*$/p' $gettextize`
eval `sed -n '/^datarootdir=.*$/p' $gettextize`
eval `sed -n '/^: \${gettext_datadir=.*$/p' $gettextize`
if [ -z "$gettext_datadir" ]; then
eval `sed -n '/^gettext_dir=.*$/p' $gettextize`
# In older versions (before 2014) this is spelled gettext_dir
# See https://github.com/autotools-mirror/gettext/commit/ff18897068486560e2bb421004cfbd42b7cdd0f8
gettext_datadir="$gettext_dir"
fi
if [ -z "$gettext_datadir" ]; then
echo >&2 "Failed to read the gettext_datadir directory from $gettextize"
echo >&2 "The config.rpath file must manually be copied into config/"
echo >&2 "This file is installed with gettext typically in /usr/share/gettext"
return 179
fi
config_rpath="$gettext_datadir/config.rpath"
if [ ! -f "$config_rpath" ]; then
echo >&2 "Missing $config_rpath file; this indicates a broken gettext install."
return 179
fi
echo "bootstrap:$LINENO: installing 'config/config.rpath'"
cp "$config_rpath" config/
}
bootstrap () {
rm -f m4/sage_spkg_configures.m4
spkg_configures=""
for filename in $(find build/pkgs -type f -name spkg-configure.m4 | sort); do
pkgname="$(echo $filename | cut -d/ -f3)"
echo "m4_sinclude([$filename])" >> m4/sage_spkg_configures.m4
spkg_configures="$spkg_configures
SAGE_SPKG_CONFIGURE_$(echo ${pkgname} | tr '[a-z]' '[A-Z]')"
done
echo "$spkg_configures" >> m4/sage_spkg_configures.m4
install_config_rpath && \
aclocal -I m4 && \
automake --add-missing --copy build/make/Makefile-auto && \
autoconf
st=$?
case $st in
0) true;; # Success
179|16|63|127) # install_config_rpath failed|no m4 for pkg-config|autotools not installed|or version too old
if [ $DOWNLOAD = yes ]; then
echo >&2 "Bootstrap failed, downloading required files instead."
bootstrap-download || exit $?
else
if [ $st -eq 127 ]; then
verb="install"
elif [ $st -eq 16 ]; then
verb="install pkg-config m4 macros for"
else
verb="upgrade"
fi
echo >&2 "Bootstrap failed. Either $verb autotools or run bootstrap with"
echo >&2 "the -d option to download the auto-generated files instead."
exit $st
fi;;
*) exit $st;; # Failure
esac
}
# Bootstrap by downloading the auto-generated files
bootstrap-download () {
sage-download-file configure-$CONFVERSION.tar.gz
if [ $? -ne 0 ]; then
echo >&2 "Error: downloading configure-$CONFVERSION.tar.gz failed"
exit 1
fi
# The "m" option to tar ensures that timestamps are set to the
# current time, not taken from the tarball.
# We need these files to be more recent than the input files
# like configure.ac, otherwise "make" gets confused.
tar xzmf $CONFBALL || exit $?
}
save () {
set -e
# Check that config.guess is sufficiently recent
if ! grep '^timestamp=.*201[5-9]' config/config.guess >/dev/null; then
echo >&2 "Error: config.guess is outdated:"
grep >&2 '^timestamp=' config/config.guess
echo >&2 "You should update the 'gnuconfig' or 'automake' package and try again"
exit 63
fi
NEWCONFVERSION=`git rev-parse HEAD`
NEWCONFBALL="upstream/configure-$NEWCONFVERSION.tar.gz"
# Create configure tarball
echo "Creating $NEWCONFBALL..."
mkdir -p upstream
tar zcf "$NEWCONFBALL" configure config/* build/make/Makefile-auto.in
# Update version
echo "$NEWCONFVERSION" >$PKG/package-version.txt
# Compute checksum
./sage --package fix-checksum configure
}
usage () {
echo >&2 "Usage: $0 [-d|-D|-s] [-u <URL>] [-h]"
}
# Parse options
SAVE=no
DOWNLOAD=no
ALWAYSDOWNLOAD=no
CONFTARBALL_URL=""
while getopts "Ddshu:" OPTION
do
case "$OPTION" in
D) ALWAYSDOWNLOAD=yes; DOWNLOAD=yes;;
d) DOWNLOAD=yes;;
s) SAVE=yes;;
u) CONFTARBALL_URL="$OPTARG"; ALWAYSDOWNLOAD=yes; DOWNLOAD=yes;;
h) usage; exit 0;;
?) usage; exit 2;;
esac
done
CONFBALL="upstream/configure-$CONFVERSION.tar.gz"
if [ $DOWNLOAD$SAVE = yesyes ]; then
echo >&2 "$0: refusing to download and save."
usage
exit 2
fi
# Start cleanly (it's not a problem if this fails)
$MAKE bootstrap-clean 2>/dev/null
mkdir config 2>/dev/null
# Get autotools from our own package into PATH (Trac #21214).
# If Sage has not been built yet, this will fail due to a missing
# sage-env-config. We just ignore that error.
source src/bin/sage-env 2>/dev/null
if [ $ALWAYSDOWNLOAD = yes ]; then
if [ -n "$CONFTARBALL_URL" ]; then
URL="$CONFTARBALL_URL"/configure-$CONFVERSION.tar.gz
sage-download-file "$URL" upstream/configure-$CONFVERSION.tar.gz
if [ $? -ne 0 ]; then
echo >&2 "Error: downloading configure-$CONFVERSION.tar.gz from $CONFTARBALL_URL failed"
exit 1
fi
echo >&2 "Downloaded configure-$CONFVERSION.tar.gz from $CONFTARBALL_URL "
else
bootstrap-download || exit $?
fi
else
bootstrap
fi
if [ $SAVE = yes ]; then
save
fi