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