quick-install-emacs 9.16 KB
Newer Older
Miles Bader's avatar
Miles Bader committed
1
#!/bin/sh
Glenn Morris's avatar
Glenn Morris committed
2 3
### quick-install-emacs --- do a halfway-decent job of installing emacs quickly

Paul Eggert's avatar
Paul Eggert committed
4
## Copyright (C) 2001-2019 Free Software Foundation, Inc.
Glenn Morris's avatar
Glenn Morris committed
5 6 7 8 9

## Author: Miles Bader <miles@gnu.org>

## This file is part of GNU Emacs.

10
## GNU Emacs is free software: you can redistribute it and/or modify
Glenn Morris's avatar
Glenn Morris committed
11
## it under the terms of the GNU General Public License as published by
12 13
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
Glenn Morris's avatar
Glenn Morris committed
14 15 16 17 18 19 20

## GNU Emacs is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.

## You should have received a copy of the GNU General Public License
21
## along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
22

Glenn Morris's avatar
Glenn Morris committed
23 24 25 26 27

### Commentary:

## This script is mainly intended for emacs maintainer or pretesters who
## install emacs very often.  See the --help output for more details.
Miles Bader's avatar
Miles Bader committed
28 29


30
PUBLIC_LIBSRC_BINARIES='emacsclient etags ctags ebrowse'
Miles Bader's avatar
Miles Bader committed
31

32
AVOID="CVS -DIC README COPYING ChangeLog ~ [.]orig$ [.]rej$ Makefile$ Makefile.in$ makefile$ makefile.w32-in$ stamp-subdir [.]cvsignore [.]arch-ids [{]arch[}] [.][cho]$ make-docfile"
Miles Bader's avatar
Miles Bader committed
33 34 35 36 37 38 39 40 41 42

# Prune old binaries lying around in the source tree
PRUNE=no
# Re-install files even if they already exist
FORCE=no
# Command verbose flag
VERBOSE=''

me="`basename $0`"

43
# Install commands (if the user specifies the '--verbose' option, it is
44 45
# passed to these commands, so that feature only works if these commands
# implement it too)
Miles Bader's avatar
Miles Bader committed
46 47 48
LINK='cp -lf'
COPY='cp -f'
REMOVE='rm -r'
49
MKDIR='mkdir -p'
Miles Bader's avatar
Miles Bader committed
50

51
# Used to execute commands once we create them
Miles Bader's avatar
Miles Bader committed
52 53 54 55
EXEC='sh'

NAWK=/usr/bin/nawk

56 57 58
# avoid non-standard command output from non-C locales
unset LANG LC_ALL LC_MESSAGES

Miles Bader's avatar
Miles Bader committed
59 60
# Some messages
USAGE="Usage: $me [OPTION...] BUILD_TREE [PREFIX]"
61
TRY="Try '$me --help' for more information."
Miles Bader's avatar
Miles Bader committed
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

# Parse command-line options
while :; do
  case "$1" in
    -n|--dry-run)
      EXEC=cat; shift;;
    -p|--prune)
      PRUNE=yes; shift;;
    -P|--no-prune)
      PRUNE=no; shift;;
    --prune-only)
      PRUNE=only; shift;;
    -f|--force)
      FORCE=yes; shift;;
    -v|--verbose)
      VERBOSE="-v"; shift;;
    --help)
      cat <<EOF
$USAGE
Install emacs quickly

  -n, --dry-run              print installation commands instead of
                             executing them

  -f, --force                install even files that haven't changed
  -v, --verbose              print messages describing what is done

  -p, --prune                prune old generated files
  -P, --no-prune             don't prune old generated files (default)
      --prune-only           prune old generated files, but don't install

      --help                 display this help and exit
      --version              output version information and exit

96
$me install emacs "incrementally", that is, it will
Miles Bader's avatar
Miles Bader committed
97 98 99 100 101 102 103 104 105 106
install only those files that have changed since the last time it was
invoked, and remove any obsolete files from the installation
directories.  It also uses hard-links into the source and build trees to
do the install, so it uses much less space than the default Makefile
install target; however, this also means that $me can
not install onto a disk partition other than the one on which the source
and build directories reside.

Optionally, $me can also remove old versions of
automatically generated files that are version-specific (such as the
107 108 109
versioned emacs executables in the 'src' directory).
The latter action is called "pruning", and
can be enabled using the '-p' or '--prune' options.
Miles Bader's avatar
Miles Bader committed
110 111 112 113 114
EOF
      exit 0
      ;;
    --version)
      cat <<EOF
Miles Bader's avatar
Miles Bader committed
115
$me 1.6
Miles Bader's avatar
Miles Bader committed
116 117 118 119 120

Written by Miles Bader <miles@gnu.org>
EOF
      exit 0
      ;;
121
    -[!-]?*)
Miles Bader's avatar
Miles Bader committed
122 123
      # split concatenated single-letter options apart
      FIRST="$1"; shift
124
      set -- `printf '%s\n' "$FIRST" | sed 's/-\(.\)\(.*\)/-\1 -\2/'` "$@"
Miles Bader's avatar
Miles Bader committed
125 126
      ;;
    -*)
127 128
      printf '%s\n' >&2 "$me: unrecognized option '$1'"
      printf '%s\n' >&2 "$TRY"
Miles Bader's avatar
Miles Bader committed
129 130 131 132 133 134 135 136 137 138 139 140 141 142
      exit 1
      ;;
    *)
      break;
  esac
done

LINK_CMD="$LINK $VERBOSE"
REMOVE_CMD="$REMOVE $VERBOSE"

case $# in
  1) BUILD="$1";;
  2) BUILD="$1"; prefix="$2";;
  *)
143 144
    printf '%s\n' >&2 "$USAGE"
    printf '%s\n' >&2 "$TRY"
Miles Bader's avatar
Miles Bader committed
145 146 147 148 149
    exit 1
    ;;
esac

if test ! -d "$BUILD"; then
150
  printf '%s\n' >&2 "$me: $BUILD: Build tree not found"
Miles Bader's avatar
Miles Bader committed
151 152
  exit 2
elif test ! -r "$BUILD/config.status"; then
153 154
  printf '%s\n' >&2 \
    "$me: $BUILD: Not a proper build tree, config.status not found"
Miles Bader's avatar
Miles Bader committed
155 156 157 158
  exit 2
fi

CONFIG_STATUS="$BUILD/config.status"
159 160
get_config_var ()
{
161 162 163
  { sed -n "s/^S[[]\"$1\"[]]=\"\([^\"]*\)\"/\1/p" $CONFIG_STATUS | sed q | grep ''; } ||
  { sed -n "s/^s\(.\)@$1@\1\(|#_!!_#|\)*\(.*\)\1.*$/\3/p" $CONFIG_STATUS | sed q | grep ''; } ||
  {
164 165
    printf '%s\n' >&2 \
      "$me: $1: Configuration variable not found in $CONFIG_STATUS"
Miles Bader's avatar
Miles Bader committed
166
    exit 4
167
  }
Miles Bader's avatar
Miles Bader committed
168 169
}

170 171 172
test x"$SRC" = x && { SRC="`get_config_var srcdir`" || exit 4 ; }
test x"$prefix" = x && { prefix="`get_config_var prefix`" || exit 4 ; }
test x"$ARCH" = x && { ARCH="`get_config_var host`" || exit 4 ; }
Miles Bader's avatar
Miles Bader committed
173

174
VERSION=`
175 176 177 178
  sed -n 's/^AC_INIT([	 ]*emacs[	 ]*,[	 ]*\([^	 ),]*\).*/\1/p' <$SRC/configure.ac
` || exit 4
test -n "$VERSION" || VERSION=`
  sed -n 's/^AC_INIT([	 ]*GNU Emacs[	 ]*,[	 ]*\([^	 ),]*\).*/\1/p' <$SRC/configure.ac
179
` || exit 4
180
test -n "$VERSION" || { printf '%s\n' >&2 "$me: no version in configure.ac"; exit 4; }
181

Miles Bader's avatar
Miles Bader committed
182 183 184
DST_SHARE="$prefix/share/emacs/$VERSION"
DST_BIN="$prefix/bin"
DST_LIBEXEC="$prefix/libexec/emacs/$VERSION/$ARCH"
185 186 187 188 189 190 191 192 193 194 195 196 197

# There are various common places for the info dir to be, so try to
# use whatever's already there, defaulting to (and preferring)
# .../share/info.
#
DST_INFO=''
for D in "$prefix/share/info" "$prefix/info"; do
  if test -d "$D"; then
    DST_INFO="$D"
    break
  fi
done
DST_INFO=${DST_INFO:-"$prefix/share/info"}
Miles Bader's avatar
Miles Bader committed
198

199 200
maybe_mkdir ()
{
Miles Bader's avatar
Miles Bader committed
201
  if ! test -d "$1"; then
202
    $MKDIR $VERBOSE "$1" 2>&1 | sed "s/^mkdir:/$me:/" 1>&2
Miles Bader's avatar
Miles Bader committed
203 204 205 206 207 208 209 210 211 212 213 214 215
  fi
}

maybe_mkdir "$DST_BIN"
maybe_mkdir "$DST_SHARE"
maybe_mkdir "$DST_SHARE/site-lisp"
maybe_mkdir "$DST_LIBEXEC"
maybe_mkdir "$DST_INFO"

(  # start of command-generating sub-shell

PRUNED=""
if test x"$PRUNE" != xno; then
216
  for D in `ls -1t $BUILD/src/emacs-$VERSION.* | sed 1d`; do
217
    printf '%s\n' "$REMOVE_CMD $D"
Miles Bader's avatar
Miles Bader committed
218 219 220 221 222 223
    PRUNED="$PRUNED $D"
  done
fi

test x"$PRUNE" = xonly && exit 0

224 225
maybe_emit_copy ()
{
Miles Bader's avatar
Miles Bader committed
226
  if test "$FORCE" = yes || ! cmp -s $1 $2; then
227
    printf '%s\n' "$LINK_CMD $1 $2"
Miles Bader's avatar
Miles Bader committed
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
  fi
}

maybe_emit_copy $BUILD/src/emacs $DST_BIN/emacs
maybe_emit_copy $BUILD/src/emacs $DST_BIN/emacs-$VERSION

for F in $PUBLIC_LIBSRC_BINARIES; do
  maybe_emit_copy $BUILD/lib-src/$F $DST_BIN/$F
done

if test x"$SRC" = x"$BUILD"; then
  PFXS="$BUILD"
else
  PFXS="$SRC $BUILD"
fi

for SUBDIR in lisp leim etc lib-src info; do
  # defaults
  SHARED=no
  FORCED=''
248
  AVOID_PAT="`printf '%s\n' "($AVOID)" | tr ' ' '|'`"
Miles Bader's avatar
Miles Bader committed
249 250 251 252 253 254 255 256 257 258 259 260 261 262

  # Set subdir-specific values
  case $SUBDIR in
    lisp|leim)
      DST="$DST_SHARE/$SUBDIR"
      ;;
    etc)
      DST="$DST_SHARE/$SUBDIR"
      # COPYING is in the avoid list, but there should be a copy of it in
      # the install etc dir, so make that here.
      FORCED="$DST/COPYING"
      ;;
    lib-src)
      DST="$DST_LIBEXEC"
263
      AVOID_PAT="`printf '%s\n' "($AVOID ($PUBLIC_LIBSRC_BINARIES)\$)" | tr ' ' '|'`"
Miles Bader's avatar
Miles Bader committed
264 265 266 267 268 269 270 271 272 273 274
      ;;
    info)
      DST="$DST_INFO"
      SHARED=yes
      ;;
  esac

  for PFX in $PFXS; do
    if [ -d $PFX/$SUBDIR ]; then
      for DIR in `(cd $PFX/$SUBDIR; find . -type d -print | sed 's@^./@@')`; do
	if [ -d $DST/$DIR ]; then
275
	  printf '%s\n' "Directory $DST/$DIR exists"
Miles Bader's avatar
Miles Bader committed
276
	else
277 278
	  printf '%s\n' "Directory $DST/$DIR non-existent"
	  if [ "`printf '%s\n' "$DIR" | grep -Ev "$AVOID_PAT"`" ]; then
Miles Bader's avatar
Miles Bader committed
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
	    maybe_mkdir $DST/$DIR
	  fi
	fi
      done
      diff -sqr $PFX/$SUBDIR $DST
    fi
  done | $NAWK '
BEGIN {
  src_pat = "^'"$SRC"'/'"$SUBDIR"'/"
  build_pat = "^'"$BUILD"'/'"$SUBDIR"'/"
  dst_pat = "^'"$DST"'/"
  dst_pfx = "'"$DST"'/"
  avoid_pat = "'"$AVOID_PAT"'"
  force = ("'"$FORCE"'" == "yes")
  shared = ("'"$SHARED"'" == "yes")
  init_bool_array(pruned, "'"$PRUNED"'")
  init_bool_array(forced, "'"$FORCED"'")
}
function init_bool_array(array, string,  a,k)
{
  split (string, a)
  for (k in a)
    array[a[k]] = 1
}
function install(src, dst)
{
  if (! (src in pruned)) {
    cp[src] = dst;
    from[dst] = src;
    delete rm[dst];
  }
}
function update(src, dst, copy)
{
  if (src in pruned) {
    rm[dst] = 1;
    delete from[dst]
  } else {
    if (copy)
      cp[src] = dst;
    from[dst] = src;
    delete rm[dst];
  }
}
function uninstall(dst)
{
  if (!(dst in from))
    rm[dst] = 1;
}
/^Directory / {
  if ($2 ~ avoid_pat) {
    if ($NF == "exists")
      uninstall($2)
  } else
    update(0, $2, 0)
  next
}
/^Files / {
  if ($4 ~ avoid_pat && !($4 in forced))
    uninstall($4)
  else if ($NF == "identical")
    update($2, $4, force)
  else
    update($2, $4, 1)
  next
}
/^Only /  {
  pfx = $3
  sub (/:$/, "/", pfx)

  if (pfx ~ dst_pat) {
    if (! shared)
      uninstall(pfx $4)
  } else {
    subdir = pfx
    if (subdir ~ src_pat)
      sub (src_pat, "", subdir)
    else
      sub (build_pat, "", subdir)

    dst = dst_pfx subdir $4
    if (! (dst ~ avoid_pat))
      install(pfx $4, dst)
  }
  next
}
END {
  for (f in rm)
    print "'"$REMOVE_CMD"' " f
  for (f in cp)
    print "'"$LINK_CMD"' " f " " cp[f]
}
'
done

) | eval $EXEC