Convert consecutive FSF copyright years to ranges.
[bpt/emacs.git] / admin / quick-install-emacs
CommitLineData
d9a88584 1#!/bin/sh
82be670e
GM
2### quick-install-emacs --- do a halfway-decent job of installing emacs quickly
3
73b0cd50 4## Copyright (C) 2001-2011 Free Software Foundation, Inc.
82be670e
GM
5
6## Author: Miles Bader <miles@gnu.org>
7
8## This file is part of GNU Emacs.
9
9ad5de0c 10## GNU Emacs is free software: you can redistribute it and/or modify
82be670e 11## it under the terms of the GNU General Public License as published by
9ad5de0c
GM
12## the Free Software Foundation, either version 3 of the License, or
13## (at your option) any later version.
82be670e
GM
14
15## GNU Emacs is distributed in the hope that it will be useful,
16## but WITHOUT ANY WARRANTY; without even the implied warranty of
17## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18## GNU General Public License for more details.
19
20## You should have received a copy of the GNU General Public License
9ad5de0c
GM
21## along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
82be670e
GM
23
24### Commentary:
25
26## This script is mainly intended for emacs maintainer or pretesters who
27## install emacs very often. See the --help output for more details.
d9a88584 28
d9a88584 29
3fb78d1f 30PUBLIC_LIBSRC_BINARIES='emacsclient etags ctags ebrowse'
d9a88584
MB
31PUBLIC_LIBSRC_SCRIPTS='grep-changelog rcs-checkin'
32
81ac4f35 33AVOID="CVS -DIC README COPYING ChangeLog ~ [.]orig$ [.]rej$ Makefile$ Makefile.in$ makefile$ makefile.w32-in$ stamp-subdir [.]cvsignore [.]arch-ids [{]arch[}] [.][cho]$ make-docfile testfile test-distrib"
d9a88584
MB
34
35# Prune old binaries lying around in the source tree
36PRUNE=no
37# Re-install files even if they already exist
38FORCE=no
39# Command verbose flag
40VERBOSE=''
41
42me="`basename $0`"
43
9a1c5fbf
MB
44# Install commands (if the user specifies the `--verbose' option, it is
45# passed to these commands, so that feature only works if these commands
46# implement it too)
d9a88584
MB
47LINK='cp -lf'
48COPY='cp -f'
49REMOVE='rm -r'
9a1c5fbf 50MKDIR='mkdir -p'
d9a88584
MB
51
52# Used to execute commands once once we create them
53EXEC='sh'
d9a88584
MB
54
55NAWK=/usr/bin/nawk
56
a819ec1a
MB
57# avoid non-standard command output from non-C locales
58unset LANG LC_ALL LC_MESSAGES
59
d9a88584
MB
60# Some messages
61USAGE="Usage: $me [OPTION...] BUILD_TREE [PREFIX]"
62TRY="Try "\`"$me --help' for more information."
63
64# Parse command-line options
65while :; do
66 case "$1" in
67 -n|--dry-run)
68 EXEC=cat; shift;;
69 -p|--prune)
70 PRUNE=yes; shift;;
71 -P|--no-prune)
72 PRUNE=no; shift;;
73 --prune-only)
74 PRUNE=only; shift;;
75 -f|--force)
76 FORCE=yes; shift;;
77 -v|--verbose)
78 VERBOSE="-v"; shift;;
79 --help)
80 cat <<EOF
81$USAGE
82Install emacs quickly
83
84 -n, --dry-run print installation commands instead of
85 executing them
86
87 -f, --force install even files that haven't changed
88 -v, --verbose print messages describing what is done
89
90 -p, --prune prune old generated files
91 -P, --no-prune don't prune old generated files (default)
92 --prune-only prune old generated files, but don't install
93
94 --help display this help and exit
95 --version output version information and exit
96
97$me install emacs \`incrementally,' that is, it will
98install only those files that have changed since the last time it was
99invoked, and remove any obsolete files from the installation
100directories. It also uses hard-links into the source and build trees to
101do the install, so it uses much less space than the default Makefile
102install target; however, this also means that $me can
103not install onto a disk partition other than the one on which the source
104and build directories reside.
105
106Optionally, $me can also remove old versions of
107automatically generated files that are version-specific (such as the
108versioned emacs executables in the \`src' directory, and the DOC-* files
109in the \`etc' directory). The latter action is called \`pruning,' and
110can be enabled using the \`-p' or \`--prune' options.
111EOF
112 exit 0
113 ;;
114 --version)
115 cat <<EOF
ca2135af 116$me 1.6
d9a88584
MB
117
118Written by Miles Bader <miles@gnu.org>
119EOF
120 exit 0
121 ;;
61c26472 122 -[!-]?*)
d9a88584
MB
123 # split concatenated single-letter options apart
124 FIRST="$1"; shift
125 set -- `echo $FIRST | sed 's/-\(.\)\(.*\)/-\1 -\2/'` "$@"
126 ;;
127 -*)
128 echo 1>&2 "$me: unrecognized option "\`"$1'"
129 echo 1>&2 "$TRY"
130 exit 1
131 ;;
132 *)
133 break;
134 esac
135done
136
137LINK_CMD="$LINK $VERBOSE"
138REMOVE_CMD="$REMOVE $VERBOSE"
139
140case $# in
141 1) BUILD="$1";;
142 2) BUILD="$1"; prefix="$2";;
143 *)
144 echo 1>&2 "$USAGE"
145 echo 1>&2 "$TRY"
146 exit 1
147 ;;
148esac
149
150if test ! -d "$BUILD"; then
151 echo 1>&2 "$me: $BUILD: Build tree not found"
152 exit 2
153elif test ! -r "$BUILD/config.status"; then
154 echo 1>&2 "$me: $BUILD: Not a proper build tree, config.status not found"
155 exit 2
156fi
157
158CONFIG_STATUS="$BUILD/config.status"
feebeb72
MB
159get_config_var ()
160{
d94c90b9
MB
161 { sed -n "s/^S[[]\"$1\"[]]=\"\([^\"]*\)\"/\1/p" $CONFIG_STATUS | sed q | grep ''; } ||
162 { sed -n "s/^s\(.\)@$1@\1\(|#_!!_#|\)*\(.*\)\1.*$/\3/p" $CONFIG_STATUS | sed q | grep ''; } ||
163 {
d9a88584
MB
164 echo 1>&2 "$me: $1: Configuration variable not found in $CONFIG_STATUS"
165 exit 4
d94c90b9 166 }
d9a88584
MB
167}
168
c5915370
MB
169test x"$SRC" = x && { SRC="`get_config_var srcdir`" || exit 4 ; }
170test x"$prefix" = x && { prefix="`get_config_var prefix`" || exit 4 ; }
c5915370 171test x"$ARCH" = x && { ARCH="`get_config_var host`" || exit 4 ; }
d9a88584 172
e45b9e19 173VERSION=`grep 'char emacs_version' $SRC/src/emacs.c \
892de428
MB
174 | sed -e 's/^[^"]*"\([^"]*\)".*$/\1/'`
175
d9a88584
MB
176DST_SHARE="$prefix/share/emacs/$VERSION"
177DST_BIN="$prefix/bin"
178DST_LIBEXEC="$prefix/libexec/emacs/$VERSION/$ARCH"
40c3f434
MB
179
180# There are various common places for the info dir to be, so try to
181# use whatever's already there, defaulting to (and preferring)
182# .../share/info.
183#
184DST_INFO=''
185for D in "$prefix/share/info" "$prefix/info"; do
186 if test -d "$D"; then
187 DST_INFO="$D"
188 break
189 fi
190done
191DST_INFO=${DST_INFO:-"$prefix/share/info"}
d9a88584 192
feebeb72
MB
193maybe_mkdir ()
194{
d9a88584 195 if ! test -d "$1"; then
9a1c5fbf 196 $MKDIR $VERBOSE "$1" 2>&1 | sed "s/^mkdir:/$me:/" 1>&2
d9a88584
MB
197 fi
198}
199
200maybe_mkdir "$DST_BIN"
201maybe_mkdir "$DST_SHARE"
202maybe_mkdir "$DST_SHARE/site-lisp"
203maybe_mkdir "$DST_LIBEXEC"
204maybe_mkdir "$DST_INFO"
205
206( # start of command-generating sub-shell
207
208PRUNED=""
209if test x"$PRUNE" != xno; then
6461c636 210 for D in `ls -1t $BUILD/etc/DOC-* | sed 1d`; do
d9a88584
MB
211 echo $REMOVE_CMD $D
212 PRUNED="$PRUNED $D"
213 done
6461c636 214 for D in `ls -1t $BUILD/src/emacs-$VERSION.* | sed 1d`; do
d9a88584
MB
215 echo $REMOVE_CMD $D
216 PRUNED="$PRUNED $D"
217 done
d9a88584
MB
218fi
219
220test x"$PRUNE" = xonly && exit 0
221
feebeb72
MB
222maybe_emit_copy ()
223{
d9a88584
MB
224 if test "$FORCE" = yes || ! cmp -s $1 $2; then
225 echo $LINK_CMD $1 $2
226 fi
227}
228
229maybe_emit_copy $BUILD/src/emacs $DST_BIN/emacs
230maybe_emit_copy $BUILD/src/emacs $DST_BIN/emacs-$VERSION
231
232for F in $PUBLIC_LIBSRC_BINARIES; do
233 maybe_emit_copy $BUILD/lib-src/$F $DST_BIN/$F
234done
235for F in $PUBLIC_LIBSRC_SCRIPTS; do
236 maybe_emit_copy $SRC/lib-src/$F $DST_BIN/$F
237done
238
239if test x"$SRC" = x"$BUILD"; then
240 PFXS="$BUILD"
241else
242 PFXS="$SRC $BUILD"
243fi
244
245for SUBDIR in lisp leim etc lib-src info; do
246 # defaults
247 SHARED=no
248 FORCED=''
249 AVOID_PAT="`echo "($AVOID)" | tr ' ' '|'`"
250
251 # Set subdir-specific values
252 case $SUBDIR in
253 lisp|leim)
254 DST="$DST_SHARE/$SUBDIR"
255 ;;
256 etc)
257 DST="$DST_SHARE/$SUBDIR"
258 # COPYING is in the avoid list, but there should be a copy of it in
259 # the install etc dir, so make that here.
260 FORCED="$DST/COPYING"
261 ;;
262 lib-src)
263 DST="$DST_LIBEXEC"
264 AVOID_PAT="`echo "($AVOID ($PUBLIC_LIBSRC_BINARIES $PUBLIC_LIBSRC_SCRIPTS)\$)" | tr ' ' '|'`"
265 ;;
266 info)
267 DST="$DST_INFO"
268 SHARED=yes
269 ;;
270 esac
271
272 for PFX in $PFXS; do
273 if [ -d $PFX/$SUBDIR ]; then
274 for DIR in `(cd $PFX/$SUBDIR; find . -type d -print | sed 's@^./@@')`; do
275 if [ -d $DST/$DIR ]; then
276 echo Directory $DST/$DIR exists
277 else
296271c0 278 echo Directory $DST/$DIR non-existent
d9a88584
MB
279 if [ "`echo $DIR | egrep -v "$AVOID_PAT"`" ]; then
280 maybe_mkdir $DST/$DIR
281 fi
282 fi
283 done
284 diff -sqr $PFX/$SUBDIR $DST
285 fi
286 done | $NAWK '
287BEGIN {
288 src_pat = "^'"$SRC"'/'"$SUBDIR"'/"
289 build_pat = "^'"$BUILD"'/'"$SUBDIR"'/"
290 dst_pat = "^'"$DST"'/"
291 dst_pfx = "'"$DST"'/"
292 avoid_pat = "'"$AVOID_PAT"'"
293 force = ("'"$FORCE"'" == "yes")
294 shared = ("'"$SHARED"'" == "yes")
295 init_bool_array(pruned, "'"$PRUNED"'")
296 init_bool_array(forced, "'"$FORCED"'")
297}
298function init_bool_array(array, string, a,k)
299{
300 split (string, a)
301 for (k in a)
302 array[a[k]] = 1
303}
304function install(src, dst)
305{
306 if (! (src in pruned)) {
307 cp[src] = dst;
308 from[dst] = src;
309 delete rm[dst];
310 }
311}
312function update(src, dst, copy)
313{
314 if (src in pruned) {
315 rm[dst] = 1;
316 delete from[dst]
317 } else {
318 if (copy)
319 cp[src] = dst;
320 from[dst] = src;
321 delete rm[dst];
322 }
323}
324function uninstall(dst)
325{
326 if (!(dst in from))
327 rm[dst] = 1;
328}
329/^Directory / {
330 if ($2 ~ avoid_pat) {
331 if ($NF == "exists")
332 uninstall($2)
333 } else
334 update(0, $2, 0)
335 next
336}
337/^Files / {
338 if ($4 ~ avoid_pat && !($4 in forced))
339 uninstall($4)
340 else if ($NF == "identical")
341 update($2, $4, force)
342 else
343 update($2, $4, 1)
344 next
345}
346/^Only / {
347 pfx = $3
348 sub (/:$/, "/", pfx)
349
350 if (pfx ~ dst_pat) {
351 if (! shared)
352 uninstall(pfx $4)
353 } else {
354 subdir = pfx
355 if (subdir ~ src_pat)
356 sub (src_pat, "", subdir)
357 else
358 sub (build_pat, "", subdir)
359
360 dst = dst_pfx subdir $4
361 if (! (dst ~ avoid_pat))
362 install(pfx $4, dst)
363 }
364 next
365}
366END {
367 for (f in rm)
368 print "'"$REMOVE_CMD"' " f
369 for (f in cp)
370 print "'"$LINK_CMD"' " f " " cp[f]
371}
372'
373done
374
375) | eval $EXEC