summaryrefslogtreecommitdiff
path: root/scripts/autotools-install
blob: 7e37cebf5feba7b5f3616120306c2ae41d4e0002 (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
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
#!/bin/sh
VERSION='2015-10-06 12:49' # UTC

# Building coreutils from a git-cloned directory may require versions of
# tools like autoconf, automake, gettext, etc. that are newer than the ones
# provided by the distribution on which you want to build.  In that case,
# you can use this script to bootstrap the "autotools" tool chain, starting
# with m4 (prereq of autoconf), then autoconf (prereq of automake), etc.
# It also builds a few others, including gettext and pkg-config.
# The results are installed in a directory whose --prefix you specify, and
# it tells you how to update envvars like PATH and (if you use pkg-config)
# PKG_CONFIG_PATH.

# On principle, I find it best to ensure that packages I care about work
# with the latest versions of all of these tools.  While these tools are
# paragons of portability, you should ensure that recent distribution
# versions work, too.

# Written by Jim Meyering

# For systems with limited/botched make (the case of most vendor makes!),
# allow the user to override it.
MAKE=${MAKE-make}

prog_name=`basename $0`
die () { echo "$prog_name: $*" >&2; exit 1; }

tarballs='
  http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz
  http://ftp.gnu.org/gnu/m4/m4-1.4.17.tar.gz
  http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
  http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz
  http://ftp.gnu.org/gnu/libtool/libtool-2.4.6.tar.gz
  http://ftp.gnu.org/gnu/gettext/gettext-0.19.6.tar.gz
'

usage() {
  echo >&2 "\
Usage: $0 [OPTION]...
Download, build, and install some tools.

Options:
 --prefix=PREFIX    install tools under specified directory
 --skip-check       do not run \"make check\" (this can save 50+ min)
 --help             display this help and exit

For example, to install programs into \$HOME/autotools/bin, run this command:

  $prog_name --prefix=\$HOME/autotools

If you've already verified that your system/environment can build working
versions of these tools, you can make this script complete in just a
minute or two (rather than about an hour if you let all \"make check\"
tests run) by invoking it like this:

  $prog_name --prefix=\$HOME/autotools --skip-check

"
}

# Get the public keys associated with each .sig file.
# for i in *.sig; do k=$(gpgv $i 2>&1 | sed -n 's/.*key ID //p'); \
# gpg --keyserver pgp.mit.edu --recv-key $k; done

# Get the listed tarballs into the current directory.
get_sources()
{
  case `wget --help` in
    *'--no-cache'*)
      WGET_COMMAND='wget -nv --no-cache';;
    *'--cache=on/off'*)
      WGET_COMMAND='wget -nv --cache=off';;
    *'--non-verbose'*)
      WGET_COMMAND='wget -nv';;
    *)
      die 'no wget program found; please install it and try again';;
  esac

  # Download the each tar-ball along with its signature, if there is one.
  pkgs=
  for t in $tarballs; do
    base=`basename $t`
    pkgs="$pkgs $base"
    test -f $base || $WGET_COMMAND $t

    # No signatures for some :-(
    case $base in pkg-config*) continue;; esac

    test -f $base.sig || $WGET_COMMAND $t.sig
    # Verify each signature.
    gpg --quiet --verify --trust-model=always   \
        --trusted-key=32419B785D0CDCFC          \
        --trusted-key=3859C03B2E236E47          \
        --trusted-key=B93F60C6B5C4CE13          \
        --trusted-key=F382AE19F4850180          \
        --trusted-key=FC818E17429F96EA          \
        --trusted-key=60F906016E407573          \
        --trusted-key=D605848ED7E69871          \
        $base.sig > /dev/null 2>&1              \
      || echo "info: not verifying GPG signature for $base" 1>&2
  done
  printf 'ok\n' 1>&2
  echo $pkgs
}

#################################################################
set -e

# Parse options.

make_check=yes
prefix=

for option
do
  case $option in
    --help) usage; exit;;
    --skip-check) make_check=no;;
    --prefix=*) prefix=`expr "$option" : '--prefix=\(.*\)'`;;
    *) die "$option: unknown option";;
  esac
done

test -n "$prefix" \
  || die "you must specify a --prefix"

case $prefix in
  /*) ;;
  *) die 'invalid prefix: '"$prefix"': it must be an absolute name';;
esac

# Don't run as root.
# Make sure id -u succeeds.
my_uid=`id -u` && test -n "$my_uid" || die "'id -u' failed"
test $my_uid -ne 0 || die "please don't run this program as root"

# Ensure that prefix is not /usr/bin or /bin, /sbin, etc.
case $prefix in
  /bin|/sbin|/usr/bin|/usr/sbin)
    die "don't set PREFIX to a system directory";;
  *) ;;
esac

# Create a build directory, then cd into it for the rest....
tmpdir=.build-auto-tools
mkdir -p $tmpdir
cd $tmpdir

pkgs=`get_sources`

export PATH=$prefix/bin:$PATH
for pkg in $pkgs; do
  echo building/installing $pkg...
  dir=`basename $pkg .tar.gz`
  rm -rf $dir
  gzip -dc $pkg | tar xf -
  cd $dir
  ./configure CFLAGS=-O2 LDFLAGS=-s --prefix=$prefix >makerr-config 2>&1
  $MAKE >makerr-build 2>&1
  if test $make_check = yes; then
    case $pkg in
      # FIXME: these are out of date and very system-sensitive
      automake*) expected_duration_minutes=40;;
      autoconf*) expected_duration_minutes=15;;
      libtool*) expected_duration_minutes=3;;
      *);;
    esac
    if test -n "$expected_duration_minutes"; then
      echo "running 'make check' for $pkg; NB: this can take over" \
           "$expected_duration_minutes minutes"
    fi
    $MAKE check >makerr-check 2>&1
  fi
  $MAKE install >makerr-install 2>&1
  echo "done at `date +%Y-%m-%d.%T`"
  cd ..
done

# Without checks (and with existing tarballs), it takes just one minute.
# Including all checks, it takes nearly an hour on an AMD64/3400+

case $PKG_CONFIG_PATH in
  $prefix/lib/pkgconfig:/usr/lib/pkgconfig)
    echo 'Good! your PKG_CONFIG_PATH envvar is already set';;
  *) cat <<EOF;;
**************************************************************************
Be sure that PKG_CONFIG_PATH is set in your environment, e.g.,
PKG_CONFIG_PATH=$prefix/lib/pkgconfig:/usr/lib/pkgconfig
**************************************************************************
EOF
esac

case $PATH in
  "$prefix/bin:"*) echo 'Good! your PATH is fine';;
  *) cat <<EOF;;
**************************************************************************
Be sure that "$prefix/bin" is earlier in your PATH than /bin, /usr/bin, etc.
**************************************************************************
EOF
esac

cat <<EOF
**************************************************************************
You may want to remove the tool build directory:
rm -rf $tmpdir
**************************************************************************
EOF

## Local Variables:
## eval: (add-hook 'write-file-hooks 'time-stamp)
## time-stamp-start: "VERSION='"
## time-stamp-format: "%:y-%02m-%02d %02H:%02M"
## time-stamp-time-zone: "UTC"
## time-stamp-end: "' # UTC"
## End: