autotools-install 6.6 KB

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