Fix rx-any with range with ?\] and ?-
[emacs.git] / make-dist
blobb0a8dff2cc7a7627ed7bcf679a80ab76e9fc8353
1 #!/bin/sh
2 ### make-dist: create an Emacs distribution tar file from current srcdir
4 ## Copyright (C) 1995, 1997-1998, 2000-2016 Free Software Foundation,
5 ## Inc.
7 ## This file is part of GNU Emacs.
9 ## GNU Emacs is free software: you can redistribute it and/or modify
10 ## it under the terms of the GNU General Public License as published by
11 ## the Free Software Foundation, either version 3 of the License, or
12 ## (at your option) any later version.
14 ## GNU Emacs is distributed in the hope that it will be useful,
15 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ## GNU General Public License for more details.
19 ## You should have received a copy of the GNU General Public License
20 ## along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 ### Commentary:
24 ## This basically creates a duplicate directory structure, and then
25 ## hard links into it only those files that should be distributed.
26 ## This means that if you add a file with an odd name, you should make
27 ## sure that this script will include it.
29 ### Code:
31 progname="$0"
33 ### Exit if a command fails.
34 #set -e
36 ### Print out each line we read, for debugging's sake.
37 #set -v
39 LANGUAGE=C
40 LC_ALL=C
41 LC_MESSAGES=
42 LANG=
43 export LANGUAGE LC_ALL LC_MESSAGES LANG
45 ## Remove unnecessary restrictions on file access.
46 umask 022
48 update=yes
49 check=yes
50 clean_up=no
51 make_tar=no
52 default_gzip=gzip
53 newer=""
54 with_tests=no
55 changelog=yes
56 verbose=no
58 while [ $# -gt 0 ]; do
59 case "$1" in
60 ## This option tells make-dist to delete the staging directory
61 ## when done. It is useless to use this unless you make a tar file.
62 "--clean-up" )
63 clean_up=yes
65 ## This option tells make-dist to make a tar file.
66 "--tar" )
67 make_tar=yes
69 ## This option tells make-dist not to recompile or do analogous things.
70 "--no-update" )
71 update=no
73 ## This option says don't check for bad file names, etc.
74 "--no-check" )
75 check=no
77 "--no-changelog" )
78 changelog=no
80 ## This option tells make-dist to make the distribution normally, then
81 ## remove all files older than the given timestamp file. This is useful
82 ## for creating incremental or patch distributions.
83 "--newer")
84 newer="$2"
85 new_extension=".new"
86 shift
88 ## This option tells make-dist to use 'bzip2' instead of gzip.
89 "--bzip2")
90 default_gzip="bzip2"
92 ## Same with xz.
93 "--xz")
94 default_gzip="xz"
96 "--no-compress")
97 default_gzip="cat"
100 "--snapshot")
101 clean_up=yes
102 make_tar=yes
103 update=no
104 check=no
107 ## Include the test/ directory.
108 ## This option is mainly for the hydra build server.
109 "--tests")
110 with_tests=yes
113 "--verbose")
114 verbose=yes
117 "--help")
118 printf '%s\n' "Usage: ${progname} [options]"
119 echo ""
120 echo " --bzip2 use bzip2 instead of gzip"
121 echo " --clean-up delete staging directories when done"
122 echo " --xz use xz instead of gzip"
123 echo " --no-compress don't compress"
124 echo " --newer=TIME don't include files older than TIME"
125 echo " --no-check don't check for bad file names etc."
126 echo " --no-update don't recompile or do analogous things"
127 echo " --no-changelog don't generate the top-level ChangeLog"
128 echo " --snapshot same as --clean-up --no-update --tar --no-check"
129 echo " --tar make a tar file"
130 echo " --tests include the test/ directory"
131 echo " --verbose noisier output"
132 echo ""
133 exit 0
137 printf '%s\n' "${progname}: Unrecognized argument: $1" >&2
138 exit 1
140 esac
141 shift
142 done
144 ### Make sure we're running in the right place.
145 if [ ! -d src -o ! -f src/lisp.h -o ! -d lisp -o ! -f lisp/subr.el ]; then
146 printf '%s\n' "${progname}: Can't find 'src/lisp.h' and 'lisp/subr.el'." >&2
147 printf '%s\n' "${progname} must be run in the top directory of the Emacs" >&2
148 printf '%s\n' "distribution tree. cd to that directory and try again." >&2
149 exit 1
152 ### Find where to run Emacs.
153 ### (Accept only absolute file names.)
154 if [ $update = yes ];
155 then
156 if [ -f src/emacs ];
157 then
158 EMACS=`pwd`/src/emacs
159 else
160 case $EMACS in
161 /*) ;;
163 if [ ! -f "$EMACS" ]; then
164 printf '%s\n' "$0: You must set the EMACS environment variable " \
165 "to an absolute file name." 2>&1
166 exit 1
167 fi;;
168 esac
172 ### Find out which version of Emacs this is.
173 version=`
174 sed -n 's/^AC_INIT(GNU Emacs,[ ]*\([^ ,)]*\).*/\1/p' <configure.ac
175 ` || version=
176 if [ ! "${version}" ]; then
177 printf '%s\n' \
178 "${progname}: can't find current Emacs version in './src/emacs.c'" >&2
179 exit 1
182 echo Version number is $version
184 if [ $update = yes ]; then
185 if ! grep -q "tree holds version *${version}" README; then
186 echo "WARNING: README has the wrong version number"
187 echo "Consider running M-x set-version from admin/admin.el"
188 sleep 5
192 ### Make sure we don't already have a directory emacs-${version}.
194 emacsname="emacs-${version}${new_extension}"
196 if [ -d ${emacsname} ]
197 then
198 echo Directory "${emacsname}" already exists >&2
199 exit 1
202 ### Make sure the subdirectory is available.
203 tempparent="make-dist.tmp.$$"
204 if [ -d ${tempparent} ]; then
205 printf '%s\n' "${progname}: staging directory '${tempparent}' already exists.
206 Perhaps a previous invocation of '${progname}' failed to clean up after
207 itself. Check that directories whose names are of the form
208 'make-dist.tmp.NNNNN' don't contain any important information, remove
209 them, and try again." >&2
210 exit 1
213 if [ $check = yes ]; then
214 ls -1 lisp/[a-zA-Z]*.el lisp/[a-z]*/[a-zA-Z0-9]*.el \
215 lisp/[a-z]*/[a-z]*/[a-zA-Z0-9]*.el \
216 lisp/[a-z]*/[a-z]*/[a-z]*/[a-zA-Z0-9]*.el > /tmp/el
218 ls -1 lisp/[a-zA-Z]*.elc lisp/[a-z]*/[a-zA-Z0-9]*.elc \
219 lisp/[a-z]*/[a-z]*/[a-zA-Z0-9]*.elc \
220 lisp/[a-z]*/[a-z]*/[a-z]*/[a-zA-Z0-9]*.elc > /tmp/elc
222 ## Check for .elc files with no corresponding .el file.
223 sed 's/\.el$/.elc/' /tmp/el > /tmp/elelc
225 bogosities=`comm -13 /tmp/elelc /tmp/elc`
226 if [ x"${bogosities}" != x"" ]; then
227 echo "The following .elc files have no corresponding .el files:"
228 echo "${bogosities}"
231 ### Check for .el files with no corresponding .elc file.
232 sed 's/\.elc$/.el/' /tmp/elc > /tmp/elcel
233 losers=`comm -23 /tmp/el /tmp/elcel`
235 rm -f /tmp/el /tmp/elc /tmp/elcel /tmp/elelc
237 bogosities=
238 for file in $losers; do
239 grep -q "no-byte-compile: t" $file && continue
240 case $file in
241 site-init.el | site-load.el | site-start.el | default.el) continue ;;
242 esac
244 bogosities="$file $bogosities"
246 done
247 if [ x"${bogosities}" != x"" ]; then
248 echo "The following .el files have no corresponding .elc files:"
249 echo "${bogosities}"
253 if [ $update = yes ]; then
255 ## Make sure configure is newer than configure.ac, etc.
256 ## It is better to let autoreconf do what is needed than
257 ## for us to try and duplicate all its checks.
258 echo "Running autoreconf"
259 autoreconf -i -I m4 || { x=$?; echo Autoreconf FAILED! >&2; exit $x; }
261 ## Make sure src/stamp-h.in is newer than configure.ac.
262 rm -f src/stamp-h.in
263 echo timestamp > src/stamp-h.in
265 echo "Updating Info files"
266 make info
268 echo "Updating finder, custom and autoload data"
269 (cd lisp && make updates EMACS="$EMACS")
271 echo "Updating leim-list.el"
272 (cd leim && make leim-list.el EMACS="$EMACS")
274 echo "Recompiling Lisp files"
275 $EMACS -batch -f batch-byte-recompile-directory lisp
276 fi # $update = yes
278 echo "Creating staging directory: '${tempparent}'"
280 mkdir ${tempparent}
281 tempdir="${tempparent}/${emacsname}"
283 ### This trap ensures that the staging directory will be cleaned up even
284 ### when the script is interrupted in mid-career.
285 if [ "${clean_up}" = yes ]; then
286 trap "echo 'Cleaning up the staging directory'; rm -rf ${tempparent}" EXIT
289 echo "Creating top directory: '${tempdir}'"
290 mkdir ${tempdir}
292 if [ "$changelog" = yes ]; then
293 if test -e .git; then
294 echo "Making top-level ChangeLog"
295 make ChangeLog CHANGELOG=${tempdir}/ChangeLog || \
296 { x=$?; echo "make ChangeLog FAILED (try --no-changelog?)" >&2; exit $x; }
297 else
298 echo "No repository, so omitting top-level ChangeLog"
302 ### We copy in the top-level files before creating the subdirectories in
303 ### hopes that this will make the top-level files appear first in the
304 ### tar file; this means that people can start reading the INSTALL and
305 ### README while the rest of the tar file is still unpacking. Whoopee.
306 echo "Making links to top-level files"
307 ln INSTALL README BUGS ${tempdir}
308 ln ChangeLog.*[0-9] Makefile.in autogen.sh configure configure.ac ${tempdir}
309 ln config.bat make-dist .dir-locals.el ${tempdir}
310 ln aclocal.m4 CONTRIBUTE ${tempdir}
312 echo "Creating subdirectories"
313 for subdir in site-lisp \
314 leim leim/CXTERM-DIC leim/MISC-DIC leim/SKK-DIC \
315 build-aux build-aux/snippet \
316 src src/bitmaps lib lib-src oldXMenu lwlib \
317 nt nt/inc nt/inc/sys nt/inc/arpa nt/inc/netinet nt/icons \
318 `find etc lisp admin test -type d` \
319 doc doc/emacs doc/misc doc/man doc/lispref doc/lispintro \
320 info m4 modules modules/mod-test msdos \
321 nextstep nextstep/templates \
322 nextstep/Cocoa nextstep/Cocoa/Emacs.base \
323 nextstep/Cocoa/Emacs.base/Contents \
324 nextstep/Cocoa/Emacs.base/Contents/Resources \
325 nextstep/GNUstep \
326 nextstep/GNUstep/Emacs.base \
327 nextstep/GNUstep/Emacs.base/Resources
330 if [ "$with_tests" != "yes" ]; then
331 case $subdir in
332 test*|*/mod-test*) continue ;;
333 esac
336 ## site-lisp for in-place installs (?).
337 [ "$subdir" = "site-lisp" ] || [ -d "$subdir" ] || \
338 echo "WARNING: $subdir not found, making anyway"
339 [ "$verbose" = "yes" ] && echo " ${tempdir}/${subdir}"
340 mkdir ${tempdir}/${subdir}
341 done
343 echo "Making links to 'lisp' and its subdirectories"
344 files=`find lisp \( -name '*.el' -o -name '*.elc' -o -name 'ChangeLog*' \
345 -o -name 'README' \)`
347 ### Don't distribute site-init.el, site-load.el, or default.el.
348 for file in lisp/Makefile.in $files; do
349 case $file in
350 */site-init*|*/site-load*|*/default*) continue ;;
351 esac
352 ln $file $tempdir/$file
353 done
355 echo "Making links to 'leim' and its subdirectories"
356 (cd leim
357 ln ChangeLog.*[0-9] README ../${tempdir}/leim
358 ln CXTERM-DIC/README CXTERM-DIC/*.tit ../${tempdir}/leim/CXTERM-DIC
359 ln SKK-DIC/README SKK-DIC/SKK-JISYO.L ../${tempdir}/leim/SKK-DIC
360 ln MISC-DIC/README MISC-DIC/*.* ../${tempdir}/leim/MISC-DIC
361 ln Makefile.in ../${tempdir}/leim/Makefile.in
362 ln leim-ext.el ../${tempdir}/leim/leim-ext.el)
364 ## FIXME Can we not just use the "find -type f" method for this one?
365 echo "Making links to 'build-aux'"
366 (cd build-aux
367 ln compile config.guess config.sub depcomp msys-to-w32 ../${tempdir}/build-aux
368 ln gitlog-to-changelog gitlog-to-emacslog ../${tempdir}/build-aux
369 ln install-sh missing move-if-change ../${tempdir}/build-aux
370 ln update-copyright update-subdirs ../${tempdir}/build-aux
371 ln dir_top make-info-dir ar-lib ../${tempdir}/build-aux)
373 echo "Making links to 'build-aux/snippet'"
374 (cd build-aux/snippet
375 ln *.h ../../${tempdir}/build-aux/snippet)
377 echo "Making links to 'src'"
378 ### Don't distribute the configured versions of
379 ### config.in, paths.in, buildobj.h, or Makefile.in.
380 (cd src
381 echo " (It is ok if ln fails in some cases.)"
382 ln [a-zA-Z]*.[chm] ../${tempdir}/src
383 ln [a-zA-Z]*.in ../${tempdir}/src
384 ln deps.mk ../${tempdir}/src
385 ln README ChangeLog.*[0-9] ../${tempdir}/src
386 ln .gdbinit .dbxinit ../${tempdir}/src
387 cd ../${tempdir}/src
388 rm -f globals.h config.h epaths.h Makefile buildobj.h)
390 echo "Making links to 'src/bitmaps'"
391 (cd src/bitmaps
392 ln README *.xbm ../../${tempdir}/src/bitmaps)
394 echo "Making links to 'lib'"
395 (snippet_h=`(cd build-aux/snippet && ls *.h)`
396 cd lib
397 ln [a-zA-Z]*.[ch] ../${tempdir}/lib
398 ln gnulib.mk Makefile.am Makefile.in ../${tempdir}/lib
399 cd ../${tempdir}/lib
400 script='/[*]/d; s/\.in\.h$/.h/'
401 rm -f `(echo "$snippet_h"; ls *.in.h) | sed "$script"`)
403 echo "Making links to 'lib-src'"
404 (cd lib-src
405 ln [a-zA-Z]*.[ch] ../${tempdir}/lib-src
406 ln ChangeLog.*[0-9] Makefile.in README ../${tempdir}/lib-src
407 ln rcs2log ../${tempdir}/lib-src
408 ln update-game-score.exe.manifest ../${tempdir}/lib-src)
410 echo "Making links to 'm4'"
411 (cd m4
412 ln *.m4 ../${tempdir}/m4)
414 echo "Making links to 'modules'"
415 (cd modules
416 ln *.py ../${tempdir}/modules
417 if [ "$with_tests" = "yes" ]; then
418 for f in `find mod-test -type f`; do
419 case $f in
420 *.log|*.o|*.so) continue ;;
421 esac
422 ln $f ../$tempdir/modules/$f
423 done
427 echo "Making links to 'nt'"
428 (cd nt
429 ln emacs-x86.manifest emacs-x64.manifest ../${tempdir}/nt
430 ln [a-z]*.bat [a-z]*.[ch] ../${tempdir}/nt
431 ln *.in gnulib.mk ../${tempdir}/nt
432 ln mingw-cfg.site epaths.nt INSTALL.W64 ../${tempdir}/nt
433 ln ChangeLog.*[0-9] INSTALL README README.W32 ../${tempdir}/nt)
435 echo "Making links to 'nt/inc' and its subdirectories"
436 for f in `find nt/inc -type f -name '[a-z]*.h'`; do
437 ln $f $tempdir/$f
438 done
440 echo "Making links to 'nt/icons'"
441 (cd nt/icons
442 ln README [a-z]*.ico ../../${tempdir}/nt/icons
443 ln [a-z]*.cur ../../${tempdir}/nt/icons)
445 echo "Making links to 'msdos'"
446 (cd msdos
447 ln ChangeLog.*[0-9] INSTALL README emacs.ico emacs.pif ../${tempdir}/msdos
448 ln depfiles.bat inttypes.h ../${tempdir}/msdos
449 ln mainmake.v2 sed*.inp ../${tempdir}/msdos)
451 echo "Making links to 'nextstep'"
452 (cd nextstep
453 ln ChangeLog.*[0-9] README INSTALL Makefile.in ../${tempdir}/nextstep)
455 echo "Making links to 'nextstep/templates'"
456 (cd nextstep/templates
457 ln Emacs.desktop.in Info-gnustep.plist.in Info.plist.in InfoPlist.strings.in ../../${tempdir}/nextstep/templates)
459 echo "Making links to 'nextstep/Cocoa/Emacs.base/Contents'"
460 (cd nextstep/Cocoa/Emacs.base/Contents
461 ln PkgInfo ../../../../${tempdir}/nextstep/Cocoa/Emacs.base/Contents)
463 echo "Making links to 'nextstep/Cocoa/Emacs.base/Contents/Resources'"
464 (cd nextstep/Cocoa/Emacs.base/Contents/Resources
465 ln Credits.html *.icns ../../../../../${tempdir}/nextstep/Cocoa/Emacs.base/Contents/Resources)
467 echo "Making links to 'nextstep/GNUstep/Emacs.base/Resources'"
468 (cd nextstep/GNUstep/Emacs.base/Resources
469 ln README emacs.tiff ../../../../${tempdir}/nextstep/GNUstep/Emacs.base/Resources )
471 echo "Making links to 'oldXMenu'"
472 (cd oldXMenu
473 ln *.[ch] *.in *.mk ../${tempdir}/oldXMenu
474 ln README ChangeLog.*[0-9] ../${tempdir}/oldXMenu)
476 echo "Making links to 'lwlib'"
477 (cd lwlib
478 ln *.[ch] *.in *.mk ../${tempdir}/lwlib
479 ln README ChangeLog.*[0-9] ../${tempdir}/lwlib)
481 ## It is important to distribute admin/ because it contains sources
482 ## for generated lisp/international/uni-*.el files.
483 echo "Making links to 'admin' and its subdirectories"
484 for f in `find admin -type f`; do
485 case $f in
486 */Makefile) [ -f $f.in ] && continue ;;
487 esac
488 ln $f $tempdir/$f
489 done
491 if [ "$with_tests" = "yes" ]; then
492 echo "Making links to 'test' and its subdirectories"
493 for f in `find test -type f`; do
494 case $f in
495 test/automated/*.log) continue ;;
496 test/automated/flymake/warnpred/a.out) continue ;;
497 test/automated/Makefile) continue ;;
498 esac
499 ln $f $tempdir/$f
500 done
503 echo "Making links to 'etc' and its subdirectories"
504 for f in `find etc -type f`; do
505 case $f in
506 etc/DOC*|etc/*.pyc) continue ;;
507 ## Arguably we should not exclude *.ps.
508 etc/refcards/*.aux|etc/refcards/*.dvi|etc/refcards/*.log|etc/refcards/*.ps)
509 continue ;;
510 esac
511 ln $f $tempdir/$f
512 done
514 echo "Making links to 'info'"
515 ln `find info -type f -print` ${tempdir}/info
517 echo "Making links to 'doc/emacs'"
518 (cd doc/emacs
519 ln *.texi *.in ChangeLog.*[0-9] ../../${tempdir}/doc/emacs)
521 echo "Making links to 'doc/misc'"
522 (cd doc/misc
523 ln *.texi *.tex *.in gnus-news.el ChangeLog.*[0-9] \
524 ../../${tempdir}/doc/misc)
526 echo "Making links to 'doc/lispref'"
527 (cd doc/lispref
528 ln *.texi *.in README ChangeLog.*[0-9] ../../${tempdir}/doc/lispref
529 ln spellfile ../../${tempdir}/doc/lispref
530 ln two-volume.make two-volume-cross-refs.txt ../../${tempdir}/doc/lispref)
532 echo "Making links to 'doc/lispintro'"
533 (cd doc/lispintro
534 ln *.texi *.in *.eps *.pdf ../../${tempdir}/doc/lispintro
535 ln README ChangeLog.*[0-9] ../../${tempdir}/doc/lispintro
536 cd ../../${tempdir}/doc/lispintro)
538 echo "Making links to 'doc/man'"
539 (cd doc/man
540 ln *.*[0-9] *.in ../../${tempdir}/doc/man
541 cd ../../${tempdir}/doc/man
542 rm -f emacs.1)
544 ### It would be nice if they could all be symlinks to top-level copy, but
545 ### you're not supposed to have any symlinks in distribution tar files.
546 echo "Making sure copying notices are all copies of 'COPYING'"
547 for subdir in . etc leim lib lib-src lisp lwlib msdos nt src; do
548 rm -f ${tempdir}/${subdir}/COPYING
549 cp COPYING ${tempdir}/${subdir}
550 done
552 if [ "${newer}" ]; then
553 printf '%s\n' "Removing files older than $newer"
554 ## We remove .elc files unconditionally, on the theory that anyone picking
555 ## up an incremental distribution already has a running Emacs to byte-compile
556 ## them with.
557 find ${tempparent} \( -name '*.elc' -o ! -newer ${newer} \) -exec rm -f {} \;
560 ## Don't distribute backups, autosaves, etc.
561 echo "Removing unwanted files"
562 find ${tempparent} \( -name '*~' -o -name '#*#' -o -name '.*ignore' -o -name '=*' -o -name 'TAGS' \) -exec rm -f {} \;
564 if [ "${make_tar}" = yes ]; then
565 echo "Looking for $default_gzip"
566 found=0
567 temppath=`printf '%s\n' "$PATH" |
568 sed -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' -e 's/:/ /g'
570 for dir in ${temppath}; do
571 [ -x ${dir}/$default_gzip ] || continue
572 found=1; break
573 done
574 if [ "$found" = "0" ]; then
575 echo "WARNING: '$default_gzip' not found, will not compress" >&2
576 default_gzip=cat
578 case "${default_gzip}" in
579 bzip2) gzip_extension=.bz2 ;;
580 xz) gzip_extension=.xz ;;
581 gzip) gzip_extension=.gz ; default_gzip="gzip --best";;
582 *) gzip_extension= ;;
583 esac
584 echo "Creating tar file"
585 taropt=
586 [ "$verbose" = "yes" ] && taropt=v
588 (cd ${tempparent} ; tar c${taropt}f - ${emacsname} ) \
589 | ${default_gzip} \
590 > ${emacsname}.tar${gzip_extension}
593 if [ "${clean_up}" != yes ]; then
594 (cd ${tempparent}; mv ${emacsname} ..)
595 rm -rf ${tempparent}
598 ### make-dist ends here