Don't ask questions when replacing README.
[bpt/emacs.git] / make-dist
1 #!/bin/sh
2
3 #### make-dist: create an Emacs distribution tar file from the current
4 #### source tree. This basically creates a duplicate directory
5 #### structure, and then hard links into it only those files that should
6 #### be distributed. This means that if you add a file with an odd name,
7 #### you should make sure that this script will include it.
8
9 # Copyright (C) 1995, 1997 Free Software Foundation, Inc.
10 #
11 # This file is part of GNU Emacs.
12 #
13 # GNU Emacs is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2, or (at your option)
16 # any later version.
17 #
18 # GNU Emacs is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with GNU Emacs; see the file COPYING. If not, write to the
25 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 # Boston, MA 02111-1307, USA.
27
28 progname="$0"
29
30 ### Exit if a command fails.
31 ### set -e
32
33 ### Print out each line we read, for debugging's sake.
34 ### set -v
35
36 ## Don't protect any files.
37 umask 0
38
39 update=yes
40 clean_up=no
41 make_tar=no
42 newer=""
43
44 while [ $# -gt 0 ]; do
45 case "$1" in
46 ## This option tells make-dist to delete the staging directory
47 ## when done. It is useless to use this unless you make a tar file.
48 "--clean-up" )
49 clean_up=yes
50 ;;
51 ## This option tells make-dist to make a tar file.
52 "--tar" )
53 make_tar=yes
54 ;;
55 ## This option tells make-dist not to recompile or do analogous things.
56 "--no-update" )
57 update=no
58 ;;
59 ## This option tells make-dist to make the distribution normally, then
60 ## remove all files older than the given timestamp file. This is useful
61 ## for creating incremental or patch distributions.
62 "--newer")
63 newer="$2"
64 new_extension=".new"
65 shift
66 ;;
67 ## This option tells make-dist to use `compress' instead of gzip.
68 ## Normally, make-dist uses gzip whenever it is present.
69 "--compress")
70 default_gzip="compress"
71 ;;
72 * )
73 echo "${progname}: Unrecognized argument: $1" >&2
74 exit 1
75 ;;
76 esac
77 shift
78 done
79
80 ### Make sure we're running in the right place.
81 if [ ! -d src -o ! -f src/lisp.h -o ! -d lisp -o ! -f lisp/version.el ]; then
82 echo "${progname}: Can't find \`src/lisp.h' and \`lisp/version.el'." >&2
83 echo "${progname} must be run in the top directory of the Emacs" >&2
84 echo "distribution tree. cd to that directory and try again." >&2
85 exit 1
86 fi
87
88 ### Find where to run Emacs.
89 if [ $update = yes ];
90 then
91 if [ -f src/emacs ];
92 then
93 EMACS=`pwd`/src/emacs
94 else
95 if [ x$EMACS = x ];
96 then
97 echo You must specify the EMACS environment variable 2>&1
98 exit 1
99 fi
100 fi
101 fi
102
103 ### Find out which version of Emacs this is.
104 shortversion=`grep 'defconst[ ]*emacs-version' lisp/version.el \
105 | sed -e 's/^.*"\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/'`
106 version=`grep 'defconst[ ]*emacs-version' lisp/version.el \
107 | sed -e 's/^[^"]*"\([^"]*\)".*$/\1/'`
108 if [ ! "${version}" ]; then
109 echo "${progname}: can't find current Emacs version in \`./lisp/version.el'" >&2
110 exit 1
111 fi
112
113 echo Version numbers are $version and $shortversion
114
115 if [ $update = yes ];
116 then
117 if grep -s "GNU Emacs version ${shortversion}" ./man/emacs.texi > /dev/null; then
118 true
119 else
120 echo "You must update the version number in \`./man/emacs.texi'"
121 sleep 5
122 fi
123 fi
124
125 ### Make sure we don't already have a directory emacs-${version}.
126
127 emacsname="emacs-${version}${new_extension}"
128
129 if [ -d ${emacsname} ]
130 then
131 echo Directory "${emacsname}" already exists >&2
132 exit 1
133 fi
134
135 ### Make sure the subdirectory is available.
136 tempparent="make-dist.tmp.$$"
137 if [ -d ${tempparent} ]; then
138 echo "${progname}: staging directory \`${tempparent}' already exists.
139 Perhaps a previous invocation of \`${progname}' failed to clean up after
140 itself. Check that directories whose names are of the form
141 \`make-dist.tmp.NNNNN' don't contain any important information, remove
142 them, and try again." >&2
143 exit 1
144 fi
145
146 ### Check for .elc files with no corresponding .el file.
147 ls -1 lisp/[a-z]*.el lisp/[a-z]*/[a-z]*.el \
148 leim/[a-z]*.el leim/[a-z]*/[a-z]*.el | sed 's/\.el$/.elc/' > /tmp/el
149 ls -1 lisp/[a-z]*.elc lisp/[a-z]*/[a-z]*.elc \
150 leim/[a-z]*.elc leim/[a-z]*/[a-z]*.elc > /tmp/elc
151 bogosities="`comm -13 /tmp/el /tmp/elc`"
152 if [ "${bogosities}" != "" ]; then
153 echo "The following .elc files have no corresponding .el files:"
154 echo "${bogosities}"
155 fi
156 rm -f /tmp/el /tmp/elc
157
158 ### Check for .el files with no corresponding .elc file.
159 ((cd lisp; ls -1 [a-z]*.el [a-z]*/[a-z]*.el)
160 (cd leim; ls -1 [a-z]*.el [a-z]*/[a-z]*.el)) > /tmp/el
161 ((cd lisp; ls -1 [a-z]*.elc [a-z]*/[a-z]*.elc)
162 (cd leim; ls -1 [a-z]*.elc [a-z]*/[a-z]*.elc)) | sed 's/\.elc$/.el/' > /tmp/elc
163 losers="`comm -23 /tmp/el /tmp/elc`"
164 bogosities=
165 for file in $losers; do
166 file1=`echo $file | sed -e "s|.*/||"`
167 if ! grep -q "dontcompilefiles:.* $file1\($\| \)" lisp/Makefile; then
168 case $file in
169 site-init.el | site-load.el | site-start.el | default.el)
170 ;;
171 term/*)
172 ;;
173 *)
174 bogosities="$file $bogosities"
175 ;;
176 esac
177 fi
178 done
179 if [ x"${bogosities}" != x"" ]; then
180 echo "The following .el files have no corresponding .elc files:"
181 echo "${bogosities}"
182 fi
183 rm -f /tmp/el /tmp/elc
184
185 ### Check for .el files that would overflow the 14-char limit if compiled.
186 long=`find lisp leim -name '[a-zA-Z0-9]??????????*.el' -print`
187 if [ "$long" != "" ]; then
188 echo "The following .el file names are too long:"
189 echo "$long"
190 fi
191
192 ### Make sure configure is newer than configure.in.
193 if [ "x`ls -t configure configure.in | head -1`" != "xconfigure" ]; then
194 echo "\`./configure.in' is newer than \`./configure'" >&2
195 echo "Running autoconf" >&2
196 autoconf || { x=$?; echo Autoconf FAILED! >&2; exit $x; }
197 fi
198
199 if [ $update = yes ];
200 then
201 echo "Updating Info files"
202
203 (cd man; make info)
204
205 echo "Updating finder, custom and autoload data"
206
207 (cd lisp; make updates EMACS=$EMACS)
208
209 echo "Updating leim-list.el"
210
211 (cd leim; make leim-list.el EMACS=$EMACS)
212
213 echo "Recompiling Lisp files"
214
215 $EMACS -batch -f batch-byte-recompile-directory lisp leim
216 fi
217
218 echo "Making lisp/MANIFEST"
219
220 (cd lisp; head -1 [!=]*.el | grep '^;' | sed -e 's/;;; //' > MANIFEST)
221
222 echo "Creating staging directory: \`${tempparent}'"
223
224 mkdir ${tempparent}
225 tempdir="${tempparent}/${emacsname}"
226
227 ### This trap ensures that the staging directory will be cleaned up even
228 ### when the script is interrupted in mid-career.
229 if [ "${clean_up}" = yes ]; then
230 trap "echo 'Interrupted...cleaning up the staging directory'; rm -rf ${tempparent}; exit 1" 1 2 15
231 fi
232
233 echo "Creating top directory: \`${tempdir}'"
234 mkdir ${tempdir}
235
236 ### We copy in the top-level files before creating the subdirectories in
237 ### hopes that this will make the top-level files appear first in the
238 ### tar file; this means that people can start reading the INSTALL and
239 ### README while the rest of the tar file is still unpacking. Whoopee.
240 echo "Making links to top-level files"
241 ln GETTING.GNU.SOFTWARE INSTALL PROBLEMS README BUGS move-if-change ${tempdir}
242 ln ChangeLog Makefile.in configure configure.in ${tempdir}
243 ln config.bat make-dist update-subdirs vpath.sed ${tempdir}
244 ### Copy these files; they're cross-filesystem symlinks.
245 cp mkinstalldirs ${tempdir}
246 cp config.sub ${tempdir}
247 cp config.guess ${tempdir}
248 cp install.sh ${tempdir}
249
250 echo "Updating version number in README"
251 (cd ${tempdir}
252 awk \
253 '$1 " " $2 " " $3 " " $4 " " $5 == "This directory tree holds version" { $6 = version; print $0 }
254 $1 " " $2 " " $3 " " $4 " " $5 != "This directory tree holds version"' \
255 version=${version} README > tmp.README
256 mv -f tmp.README README)
257
258
259 echo "Creating subdirectories"
260 for subdir in lisp site-lisp leim real-leim real-leim/CXTERM-DIC \
261 real-leim/SKK-DIC real-leim/skk real-leim/quail \
262 src src/m src/s src/bitmaps lib-src oldXMenu lwlib \
263 nt nt/inc nt/inc/sys nt/inc/arpa nt/inc/netinet \
264 etc etc/e lock cpp info man msdos vms; do
265 mkdir ${tempdir}/${subdir}
266 done
267
268 echo "Initializing \`leim' subdirectory"
269 cp leim-Makefile.in ${tempdir}/leim/Makefile.in
270
271 echo "Making links to \`lisp' and its subdirectories"
272 ### Don't distribute TAGS, =*.el files, site-init.el, site-load.el, or default.el.
273 (cd lisp
274 ln [a-zA-Z]*.el ../${tempdir}/lisp
275 ln [a-zA-Z]*.elc ../${tempdir}/lisp
276 ln [a-zA-Z]*.dat ../${tempdir}/lisp
277 ## simula.el doesn't keep abbreviations in simula.defns any more.
278 ## ln [a-zA-Z]*.defns ../${tempdir}/lisp
279 ln ChangeLog Makefile makefile.nt ChangeLog.? README ../${tempdir}/lisp
280 (cd ../${tempdir}/lisp
281 rm -f TAGS =*
282 rm -f site-init site-init.el site-init.elc
283 rm -f site-load site-load.el site-load.elc
284 rm -f site-start site-start.el site-start.elc
285 rm -f default default.el default.elc
286 )
287
288 ## Find all subdirs of lisp dir
289 for file in `find . -type d -print`; do
290 case $file in
291 . | .. | */Old | */RCS | */=*)
292 ;;
293 *)
294 if [ -d $file ]; then
295 subdirs="$file $subdirs"
296 fi
297 ;;
298 esac
299 done
300
301 for file in $subdirs; do
302 echo " lisp/$file"
303 mkdir ../${tempdir}/lisp/$file
304 ln $file/[a-zA-Z]*.el ../${tempdir}/lisp/$file
305 ln $file/[a-zA-Z]*.elc ../${tempdir}/lisp/$file
306 if [ -f $file/README ]; then
307 ln $file/README ../${tempdir}/lisp/$file
308 fi
309 done )
310
311 echo "Making links to \`leim' and its subdirectories for the LEIM distribution"
312 ### Don't distribute TAGS, or =*.el files.
313 (cd leim
314 ln Makefile.in makefile.nt ../${tempdir}/real-leim
315 ln ChangeLog README ../${tempdir}/real-leim
316
317 ln CXTERM-DIC/*.tit ../${tempdir}/real-leim/CXTERM-DIC
318 ln SKK-DIC/README SKK-DIC/SKK-JISYO.L ../${tempdir}/real-leim/SKK-DIC
319 ln skk/*.el skk/*.elc ../${tempdir}/real-leim/skk
320 ln quail/*.el quail/*.elc ../${tempdir}/real-leim/quail
321
322 cd ../${tempdir}/real-leim
323 rm -f TAGS =* */=*)
324
325 ### Move the real-leim directory outside of Emacs proper.
326 (cd ${tempparent}
327 mkdir ${emacsname}-leim
328 mkdir ${emacsname}-leim/${emacsname}
329 mv ${emacsname}/real-leim ${emacsname}-leim/${emacsname}/leim)
330
331 echo "Making links to \`src'"
332 ### Don't distribute =*.[ch] files, or the configured versions of
333 ### config.in, paths.in, or Makefile.in, or TAGS.
334 (cd src
335 echo " (It is ok if ln fails in some cases.)"
336 ln [a-zA-Z]*.c ../${tempdir}/src
337 ln [a-zA-Z]*.h ../${tempdir}/src
338 ln [a-zA-Z]*.s ../${tempdir}/src
339 ln [a-zA-Z]*.in ../${tempdir}/src
340 ln [a-zA-Z]*.opt ../${tempdir}/src
341 ## If we ended up with a symlink, or if we did not get anything
342 ## due to a cross-device symlink, copy the file.
343 for file in [a-zA-Z]*.[hcs] [a-zA-Z]*.in [a-zA-Z]*.opt; do
344 if test -f ../${tempdir}/src/$file; then
345 # test -f appears to succeed for a symlink
346 if test -L ../${tempdir}/src/$file; then
347 rm ../${tempdir}/src/$file
348 cp -p $file ../${tempdir}/src
349 chmod a-w ../${tempdir}/src/$file
350 fi
351 else
352 rm ../${tempdir}/src/$file
353 cp -p $file ../${tempdir}/src
354 chmod a-w ../${tempdir}/src/$file
355 fi
356 done
357 ln README ChangeLog ChangeLog.*[0-9] ../${tempdir}/src
358 ln makefile.nt vms-pp.trans ../${tempdir}/src
359 ln .gdbinit .dbxinit ../${tempdir}/src
360 cd ../${tempdir}/src
361 rm -f config.h paths.h Makefile Makefile.c
362 rm -f =* TAGS)
363
364 echo "Making links to \`src/bitmaps'"
365 (cd src/bitmaps
366 ln README *.xbm ../../${tempdir}/src/bitmaps)
367
368 echo "Making links to \`src/m'"
369 (cd src/m
370 # We call files for miscellaneous input (to linker etc) .inp.
371 ln README [a-zA-Z0-9]*.h *.inp ../../${tempdir}/src/m)
372
373 echo "Making links to \`src/s'"
374 (cd src/s
375 ln README [a-zA-Z0-9]*.h ../../${tempdir}/src/s)
376
377 echo "Making links to \`lib-src'"
378 (cd lib-src
379 ln [a-zA-Z]*.[chy] ../${tempdir}/lib-src
380 ln ChangeLog Makefile.in README testfile vcdiff ../${tempdir}/lib-src
381 ln emacs.csh rcs2log rcs-checkin makefile.nt ../${tempdir}/lib-src
382 ## If we ended up with a symlink, or if we did not get anything
383 ## due to a cross-device symlink, copy the file.
384 for file in [a-zA-Z]*.[chy]; do
385 if test -f ../${tempdir}/lib-src/$file; then
386 # test -f appears to succeed for a symlink
387 if test -L ../${tempdir}/lib-src/$file; then
388 rm ../${tempdir}/lib-src/$file
389 cp $file ../${tempdir}/lib-src
390 chmod a-w ../${tempdir}/lib-src/$file
391 fi
392 else
393 rm ../${tempdir}/lib-src/$file
394 cp $file ../${tempdir}/lib-src
395 chmod a-w ../${tempdir}/lib-src/$file
396 fi
397 done
398 cd ../${tempdir}/lib-src
399 rm -f Makefile.c
400 rm -f =* TAGS)
401
402 echo "Making links to \`nt'"
403 (cd nt
404 ln emacs.ico emacs.rc config.nt [a-z]*.in [a-z]*.c ../${tempdir}/nt
405 ln [a-z]*.bat [a-z]*.h makefile.def makefile.nt ../${tempdir}/nt
406 ln TODO ChangeLog INSTALL README ../${tempdir}/nt)
407
408 echo "Making links to \`nt/inc'"
409 (cd nt/inc
410 ln [a-z]*.h ../../${tempdir}/nt/inc)
411
412 echo "Making links to \`nt/inc/sys'"
413 (cd nt/inc/sys
414 ln [a-z]*.h ../../../${tempdir}/nt/inc/sys)
415
416 echo "Making links to \`nt/inc/arpa'"
417 (cd nt/inc/arpa
418 ln [a-z]*.h ../../../${tempdir}/nt/inc/arpa)
419
420 echo "Making links to \`nt/inc/netinet'"
421 (cd nt/inc/netinet
422 ln [a-z]*.h ../../../${tempdir}/nt/inc/netinet)
423
424 echo "Making links to \`msdos'"
425 (cd msdos
426 ln ChangeLog emacs.ico emacs.pif ../${tempdir}/msdos
427 ln is_exec.c sigaction.c mainmake mainmake.v2 sed*.inp ../${tempdir}/msdos
428 cd ../${tempdir}/msdos
429 rm -f =*)
430
431 echo "Making links to \`oldXMenu'"
432 (cd oldXMenu
433 ln *.c *.h *.in ../${tempdir}/oldXMenu
434 ln README Imakefile ChangeLog ../${tempdir}/oldXMenu
435 ln compile.com descrip.mms ../${tempdir}/oldXMenu)
436
437 echo "Making links to \`lwlib'"
438 (cd lwlib
439 ln *.c *.h *.in ../${tempdir}/lwlib
440 ln README Imakefile ChangeLog ../${tempdir}/lwlib
441 cd ../${tempdir}/lwlib
442 rm -f lwlib-Xol*)
443
444 echo "Making links to \`etc'"
445 ### Don't distribute = files, TAGS, DOC files, backups, autosaves, or
446 ### tex litter.
447 (cd etc
448 files=`ls -d * | grep -v 'RCS' | grep -v 'Old' | grep -v '^e$'`
449 ln $files ../${tempdir}/etc
450 ## If we ended up with a symlink, or if we did not get anything
451 ## due to a cross-device symlink, copy the file.
452 for file in $files; do
453 if test -f ../${tempdir}/etc/$file; then
454 # test -f appears to succeed for a symlink
455 if test -L ../${tempdir}/etc/$file; then
456 rm ../${tempdir}/etc/$file
457 cp $file ../${tempdir}/etc
458 chmod a-w ../${tempdir}/etc/$file
459 fi
460 else
461 rm ../${tempdir}/etc/$file
462 cp $file ../${tempdir}/etc
463 chmod a-w ../${tempdir}/etc/$file
464 fi
465 done
466 cd ../${tempdir}/etc
467 rm -f DOC* *~ \#*\# *.dvi *.log *.orig *.rej *,v =* core
468 rm -f TAGS)
469
470 echo "Making links to \`etc/e'"
471 (cd etc/e
472 ln `ls -d * | grep -v 'RCS'` ../../${tempdir}/etc/e
473 cd ../../${tempdir}/etc/e
474 rm -f *~ \#*\# *,v =* core)
475
476 echo "Making links to \`cpp'"
477 (cd cpp
478 ln cccp.c cexp.y Makefile README ../${tempdir}/cpp)
479
480 echo "Making links to \`info'"
481 # Don't distribute backups or autosaves.
482 (cd info
483 ln [a-zA-Z]* ../${tempdir}/info
484 cd ../${tempdir}/info
485 # Avoid an error when expanding the wildcards later.
486 ln emacs dummy~ ; ln emacs \#dummy\#
487 rm -f *~ \#*\# core)
488
489 echo "Making links to \`man'"
490 (cd man
491 ln *.texi *.aux *.cps *.fns *.kys *.vrs ../${tempdir}/man
492 test -f README && ln README ../${tempdir}/man
493 test -f Makefile.in && ln Makefile.in ../${tempdir}/man
494 ln ChangeLog split-man ../${tempdir}/man
495 cp texinfo.tex ../${tempdir}/man
496 cd ../${tempdir}/man
497 rm -f \#*\# =* *~ core emacs-index* *.Z *.z xmail
498 rm -f emacs.?? termcap.?? gdb.?? *.log *.toc *.dvi *.oaux)
499
500 echo "Making links to \`vms'"
501 (cd vms
502 ln [0-9a-zA-Z]* ../${tempdir}/vms
503 cd ../${tempdir}/vms
504 rm -f *~)
505
506 ### It would be nice if they could all be symlinks to etc's copy, but
507 ### you're not supposed to have any symlinks in distribution tar files.
508 echo "Making sure copying notices are all copies of \`etc/COPYING'"
509 rm -f ${tempdir}/etc/COPYING
510 cp etc/COPYING ${tempdir}/etc/COPYING
511 for subdir in lisp src lib-src info msdos; do
512 if [ -f ${tempdir}/${subdir}/COPYING ]; then
513 rm ${tempdir}/${subdir}/COPYING
514 fi
515 cp etc/COPYING ${tempdir}/${subdir}
516 done
517
518 #### Make sure that there aren't any hard links between files in the
519 #### distribution; people with afs can't deal with that. Okay,
520 #### actually we just re-copy anything with a link count greater
521 #### than two. (Yes, strictly greater than 2 is correct; since we
522 #### created these files by linking them in from the original tree,
523 #### they'll have exactly two links normally.)
524 ####
525 #### Commented out since it's not strictly necessary; it should suffice
526 #### to just break the link on alloca.c.
527 #echo "Breaking intra-tree links."
528 #find ${tempdir} ! -type d -links +2 \
529 # -exec cp -p {} $$ \; -exec rm -f {} \; -exec mv $$ {} \;
530 rm -f $tempdir/lib-src/alloca.c
531 cp $tempdir/src/alloca.c $tempdir/lib-src/alloca.c
532
533 if [ "${newer}" ]; then
534 echo "Removing files older than $newer"
535 ## We remove .elc files unconditionally, on the theory that anyone picking
536 ## up an incremental distribution already has a running Emacs to byte-compile
537 ## them with.
538 find ${tempparent} \( -name '*.elc' -o ! -newer ${newer} \) -exec rm -f {} \;
539 fi
540
541 if [ "${make_tar}" = yes ]; then
542 if [ "${default_gzip}" = "" ]; then
543 echo "Looking for gzip"
544 temppath=`echo $PATH | sed 's/^:/.:/
545 s/::/:.:/g
546 s/:$/:./
547 s/:/ /g'`
548 default_gzip=`(
549 for dir in ${temppath}; do
550 if [ -f ${dir}/gzip ]; then echo 'gzip --best'; exit 0; fi
551 done
552 echo compress
553 )`
554 fi
555 case "${default_gzip}" in
556 compress* ) gzip_extension=.Z ;;
557 * ) gzip_extension=.gz ;;
558 esac
559 echo "Creating tar files"
560 (cd ${tempparent} ; tar cvf - ${emacsname} ) \
561 | ${default_gzip} \
562 > ${emacsname}.tar${gzip_extension}
563 (cd ${tempparent}/${emacsname}-leim ; tar cvf - ${emacsname} ) \
564 | ${default_gzip} \
565 > ${emacsname}-leim.tar${gzip_extension}
566 fi
567
568 if [ "${clean_up}" = yes ]; then
569 echo "Cleaning up the staging directory"
570 rm -rf ${tempparent}
571 else
572 (cd ${tempparent}; mv ${emacsname} ${emacsname}-leim ..)
573 rm -rf ${tempparent}
574 fi
575
576 ### make-dist ends here