maint: tests: update deprecated perl backreference syntax
[coreutils.git] / scripts / autotools-install
blob04ddec8913ca1113d80ce9b67fa0574d8f7a482e
1 #!/bin/sh
2 VERSION='2017-09-19 07:31' # UTC
4 # Building coreutils from a git-cloned directory may require versions of
5 # tools like autoconf, automake, gettext, etc. that are newer than the ones
6 # provided by the distribution on which you want to build. In that case,
7 # you can use this script to bootstrap the "autotools" tool chain, starting
8 # with m4 (prereq of autoconf), then autoconf (prereq of automake), etc.
9 # It also builds a few others, including gettext and pkg-config.
10 # The results are installed in a directory whose --prefix you specify, and
11 # it tells you how to update envvars like PATH and (if you use pkg-config)
12 # PKG_CONFIG_PATH.
14 # On principle, I find it best to ensure that packages I care about work
15 # with the latest versions of all of these tools. While these tools are
16 # paragons of portability, you should ensure that recent distribution
17 # versions work, too.
19 # Written by Jim Meyering
21 # For systems with limited/botched make (the case of most vendor makes!),
22 # allow the user to override it.
23 MAKE=${MAKE-make}
25 prog_name=`basename $0`
26 die () { echo "$prog_name: $*" >&2; exit 1; }
28 tarballs='
29 https://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz
30 https://ftp.gnu.org/gnu/m4/m4-1.4.17.tar.gz
31 https://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
32 https://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz
33 https://ftp.gnu.org/gnu/libtool/libtool-2.4.6.tar.gz
34 https://ftp.gnu.org/gnu/gettext/gettext-0.19.6.tar.gz
37 usage() {
38 echo >&2 "\
39 Usage: $0 [OPTION]...
40 Download, build, and install some tools.
42 Options:
43 --prefix=PREFIX install tools under specified directory
44 --skip-check do not run \"make check\" (this can save 50+ min)
45 --help display this help and exit
47 For example, to install programs into \$HOME/autotools/bin, run this command:
49 $prog_name --prefix=\$HOME/autotools
51 If you've already verified that your system/environment can build working
52 versions of these tools, you can make this script complete in just a
53 minute or two (rather than about an hour if you let all \"make check\"
54 tests run) by invoking it like this:
56 $prog_name --prefix=\$HOME/autotools --skip-check
61 # Get the public keys associated with each .sig file.
62 # for i in *.sig; do k=$(gpgv $i 2>&1 | sed -n 's/.*key ID //p'); \
63 # gpg --keyserver pgp.mit.edu --recv-key $k; done
65 # Get the listed tarballs into the current directory.
66 get_sources()
68 case `wget --help` in
69 *'--no-cache'*)
70 WGET_COMMAND='wget -nv --no-cache';;
71 *'--cache=on/off'*)
72 WGET_COMMAND='wget -nv --cache=off';;
73 *'--non-verbose'*)
74 WGET_COMMAND='wget -nv';;
76 die 'no wget program found; please install it and try again';;
77 esac
79 # Download the each tar-ball along with its signature, if there is one.
80 pkgs=
81 for t in $tarballs; do
82 base=`basename $t`
83 pkgs="$pkgs $base"
84 test -f $base || $WGET_COMMAND $t
86 # No signatures for some :-(
87 case $base in pkg-config*) continue;; esac
89 test -f $base.sig || $WGET_COMMAND $t.sig
90 # Verify each signature.
91 gpg --quiet --verify --trust-model=always \
92 --trusted-key=32419B785D0CDCFC \
93 --trusted-key=3859C03B2E236E47 \
94 --trusted-key=B93F60C6B5C4CE13 \
95 --trusted-key=F382AE19F4850180 \
96 --trusted-key=FC818E17429F96EA \
97 --trusted-key=60F906016E407573 \
98 --trusted-key=D605848ED7E69871 \
99 $base.sig > /dev/null 2>&1 \
100 || echo "info: not verifying GPG signature for $base" 1>&2
101 done
102 printf 'ok\n' 1>&2
103 echo $pkgs
106 #################################################################
107 set -e
109 # Parse options.
111 make_check=yes
112 prefix=
114 for option
116 case $option in
117 --help) usage; exit;;
118 --skip-check) make_check=no;;
119 --prefix=*) prefix=`expr "$option" : '--prefix=\(.*\)'`;;
120 *) die "$option: unknown option";;
121 esac
122 done
124 test -n "$prefix" \
125 || die "you must specify a --prefix"
127 case $prefix in
128 /*) ;;
129 *) die 'invalid prefix: '"$prefix"': it must be an absolute name';;
130 esac
132 # Don't run as root.
133 # Make sure id -u succeeds.
134 my_uid=`id -u` && test -n "$my_uid" || die "'id -u' failed"
135 test $my_uid -ne 0 || die "please don't run this program as root"
137 # Ensure that prefix is not /usr/bin or /bin, /sbin, etc.
138 case $prefix in
139 /bin|/sbin|/usr/bin|/usr/sbin)
140 die "don't set PREFIX to a system directory";;
141 *) ;;
142 esac
144 # Create a build directory, then cd into it for the rest....
145 tmpdir=.build-auto-tools
146 mkdir -p $tmpdir
147 cd $tmpdir
149 pkgs=`get_sources`
151 export PATH=$prefix/bin:$PATH
152 for pkg in $pkgs; do
153 echo building/installing $pkg...
154 dir=`basename $pkg .tar.gz`
155 rm -rf $dir
156 gzip -dc $pkg | tar xf -
157 cd $dir
158 ./configure CFLAGS=-O2 LDFLAGS=-s --prefix=$prefix >makerr-config 2>&1
159 $MAKE >makerr-build 2>&1
160 if test $make_check = yes; then
161 case $pkg in
162 # FIXME: these are out of date and very system-sensitive
163 automake*) expected_duration_minutes=40;;
164 autoconf*) expected_duration_minutes=15;;
165 libtool*) expected_duration_minutes=3;;
166 *);;
167 esac
168 if test -n "$expected_duration_minutes"; then
169 echo "running 'make check' for $pkg; NB: this can take over" \
170 "$expected_duration_minutes minutes"
172 $MAKE check >makerr-check 2>&1
174 $MAKE install >makerr-install 2>&1
175 echo "done at `date +%Y-%m-%d.%T`"
176 cd ..
177 done
179 # Without checks (and with existing tarballs), it takes just one minute.
180 # Including all checks, it takes nearly an hour on an AMD64/3400+
182 case $PKG_CONFIG_PATH in
183 $prefix/lib/pkgconfig:/usr/lib/pkgconfig)
184 echo 'Good! your PKG_CONFIG_PATH envvar is already set';;
185 *) cat <<EOF;;
186 **************************************************************************
187 Be sure that PKG_CONFIG_PATH is set in your environment, e.g.,
188 PKG_CONFIG_PATH=$prefix/lib/pkgconfig:/usr/lib/pkgconfig
189 **************************************************************************
191 esac
193 case $PATH in
194 "$prefix/bin:"*) echo 'Good! your PATH is fine';;
195 *) cat <<EOF;;
196 **************************************************************************
197 Be sure that "$prefix/bin" is earlier in your PATH than /bin, /usr/bin, etc.
198 **************************************************************************
200 esac
202 cat <<EOF
203 **************************************************************************
204 You may want to remove the tool build directory:
205 rm -rf $tmpdir
206 **************************************************************************
209 ## Local Variables:
210 ## eval: (add-hook 'write-file-hooks 'time-stamp)
211 ## time-stamp-start: "VERSION='"
212 ## time-stamp-format: "%:y-%02m-%02d %02H:%02M"
213 ## time-stamp-time-zone: "UTC"
214 ## time-stamp-end: "' # UTC"
215 ## End: