Fixes: debbugs:15923
[bpt/emacs.git] / make-dist
CommitLineData
067d23c9
KY
1#!/bin/sh
2### make-dist: create an Emacs distribution tar file from current srcdir
3
ff62aabc 4## Copyright (C) 1995, 1997-1998, 2000-2013 Free Software Foundation, Inc.
067d23c9
KY
5
6## This file is part of GNU Emacs.
7
8## GNU Emacs is free software: you can redistribute it and/or modify
9## it under the terms of the GNU General Public License as published by
10## the Free Software Foundation, either version 3 of the License, or
11## (at your option) any later version.
12
13## GNU Emacs is distributed in the hope that it will be useful,
14## but WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16## GNU General Public License for more details.
17
18## You should have received a copy of the GNU General Public License
19## along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
20
21### Commentary:
22
23## This basically creates a duplicate directory structure, and then
24## hard links into it only those files that should be distributed.
25## This means that if you add a file with an odd name, you should make
26## sure that this script will include it.
27
28### Code:
29
30progname="$0"
31
32### Exit if a command fails.
33#set -e
34
35### Print out each line we read, for debugging's sake.
36#set -v
37
38LANGUAGE=C
39LC_ALL=C
40LC_MESSAGES=
41LANG=
42export LANGUAGE LC_ALL LC_MESSAGES LANG
43
44## Don't restrict access to any files.
45umask 0
46
47update=yes
48check=yes
49clean_up=no
50make_tar=no
51default_gzip=gzip
52newer=""
ff62aabc 53with_tests=no
067d23c9
KY
54
55while [ $# -gt 0 ]; do
56 case "$1" in
57 ## This option tells make-dist to delete the staging directory
58 ## when done. It is useless to use this unless you make a tar file.
59 "--clean-up" )
60 clean_up=yes
61 ;;
62 ## This option tells make-dist to make a tar file.
63 "--tar" )
64 make_tar=yes
65 ;;
66 ## This option tells make-dist not to recompile or do analogous things.
67 "--no-update" )
68 update=no
69 ;;
70 ## This option says don't check for bad file names, etc.
71 "--no-check" )
72 check=no
73 ;;
74 ## This option tells make-dist to make the distribution normally, then
75 ## remove all files older than the given timestamp file. This is useful
76 ## for creating incremental or patch distributions.
77 "--newer")
78 newer="$2"
79 new_extension=".new"
80 shift
81 ;;
82 ## This option tells make-dist to use `bzip2' instead of gzip.
83 "--bzip2")
84 default_gzip="bzip2"
85 ;;
86 ## Same with lzma.
87 "--lzma")
88 default_gzip="lzma"
89 ;;
39aff4a7
GM
90 ## Same with xz.
91 "--xz")
92 default_gzip="xz"
93 ;;
94 "--no-compress")
95 default_gzip="cat"
96 ;;
067d23c9
KY
97
98 "--snapshot")
99 clean_up=yes
100 make_tar=yes
101 update=no
102 check=no
103 ;;
104
ff62aabc
GM
105 ## Include the test/ directory.
106 ## This option is mainly for the hydra build server.
107 "--tests")
108 with_tests=yes
109 ;;
110
067d23c9
KY
111 "--help")
112 echo "Usage: ${progname} [options]"
113 echo ""
114 echo " --bzip2 use bzip2 instead of gzip"
115 echo " --clean-up delete staging directories when done"
116 echo " --lzma use lzma instead of gzip"
39aff4a7
GM
117 echo " --xz use xz instead of gzip"
118 echo " --no-compress don't compress"
067d23c9
KY
119 echo " --newer=TIME don't include files older than TIME"
120 echo " --no-check don't check for bad file names etc."
121 echo " --no-update don't recompile or do analogous things"
122 echo " --snapshot same as --clean-up --no-update --tar --no-check"
123 echo " --tar make a tar file"
ff62aabc 124 echo " --tests include the test/ directory"
067d23c9
KY
125 echo ""
126 exit 0
127 ;;
128
129 * )
130 echo "${progname}: Unrecognized argument: $1" >&2
131 exit 1
132 ;;
133 esac
134 shift
135done
136
137### Make sure we're running in the right place.
138if [ ! -d src -o ! -f src/lisp.h -o ! -d lisp -o ! -f lisp/subr.el ]; then
139 echo "${progname}: Can't find \`src/lisp.h' and \`lisp/subr.el'." >&2
140 echo "${progname} must be run in the top directory of the Emacs" >&2
141 echo "distribution tree. cd to that directory and try again." >&2
142 exit 1
143fi
144
145### Find where to run Emacs.
146### (Accept only absolute file names.)
147if [ $update = yes ];
148then
149 if [ -f src/emacs ];
150 then
151 EMACS=`pwd`/src/emacs
152 else
153 case $EMACS in
154 /*) ;;
155 *)
156 if [ ! -f "$EMACS" ]; then
157 echo "$0: You must set the EMACS environment variable " \
158 "to an absolute file name." 2>&1
159 exit 1
160 fi;;
161 esac
162 fi
163fi
164
165### Find out which version of Emacs this is.
16fab143 166version=`
c4444d16 167 sed -n 's/^AC_INIT(emacs,[ ]*\([^ )]*\).*/\1/p' <configure.ac
16fab143 168` || version=
067d23c9
KY
169if [ ! "${version}" ]; then
170 echo "${progname}: can't find current Emacs version in \`./src/emacs.c'" >&2
171 exit 1
172fi
173
174echo Version number is $version
175
176if [ $update = yes ]; then
177 if ! grep -q "@set EMACSVER *${version}" doc/emacs/emacsver.texi || \
178 ! grep -q "tree holds version *${version}" README; then
179 echo "WARNING: README and/or emacsver.texi have the wrong version number"
180 echo "Consider running M-x set-version from admin/admin.el"
181 sleep 5
182 fi
183fi
184
185### Make sure we don't already have a directory emacs-${version}.
186
187emacsname="emacs-${version}${new_extension}"
188
189if [ -d ${emacsname} ]
190then
191 echo Directory "${emacsname}" already exists >&2
192 exit 1
193fi
194
195### Make sure the subdirectory is available.
196tempparent="make-dist.tmp.$$"
197if [ -d ${tempparent} ]; then
198 echo "${progname}: staging directory \`${tempparent}' already exists.
199Perhaps a previous invocation of \`${progname}' failed to clean up after
200itself. Check that directories whose names are of the form
201\`make-dist.tmp.NNNNN' don't contain any important information, remove
202them, and try again." >&2
203 exit 1
204fi
205
206if [ $check = yes ]; then
207 ls -1 lisp/[a-zA-Z]*.el lisp/[a-z]*/[a-zA-Z0-9]*.el \
208 lisp/[a-z]*/[a-z]*/[a-zA-Z0-9]*.el \
209 lisp/[a-z]*/[a-z]*/[a-z]*/[a-zA-Z0-9]*.el \
210 leim/[a-z]*/[a-z]*.el > /tmp/el
211
212 ls -1 lisp/[a-zA-Z]*.elc lisp/[a-z]*/[a-zA-Z0-9]*.elc \
213 lisp/[a-z]*/[a-z]*/[a-zA-Z0-9]*.elc \
214 lisp/[a-z]*/[a-z]*/[a-z]*/[a-zA-Z0-9]*.elc \
215 leim/[a-z]*/[a-z]*.elc > /tmp/elc
216
217 ## Check for .elc files with no corresponding .el file.
218 sed 's/\.el$/.elc/' /tmp/el > /tmp/elelc
219
220 bogosities="`comm -13 /tmp/elelc /tmp/elc`"
221 if [ x"${bogosities}" != x"" ]; then
222 echo "The following .elc files have no corresponding .el files:"
223 echo "${bogosities}"
224 fi
225
226 ### Check for .el files with no corresponding .elc file.
227 sed 's/\.elc$/.el/' /tmp/elc > /tmp/elcel
228 losers="`comm -23 /tmp/el /tmp/elcel`"
229
230 rm -f /tmp/el /tmp/elc /tmp/elcel /tmp/elelc
231
232 bogosities=
233 for file in $losers; do
234 grep -q "no-byte-compile: t" $file && continue
235 case $file in
236 site-init.el | site-load.el | site-start.el | default.el) continue ;;
237 esac
238
239 bogosities="$file $bogosities"
240
241 done
242 if [ x"${bogosities}" != x"" ]; then
243 echo "The following .el files have no corresponding .elc files:"
244 echo "${bogosities}"
245 fi
246fi
247
248if [ $update = yes ]; then
249
c4444d16 250 ## Make sure configure is newer than configure.ac, etc.
a02d99e7
GM
251 ## It is better to let autoreconf do what is needed than
252 ## for us to try and duplicate all its checks.
253 echo "Running autoreconf"
254 autoreconf -i -I m4 || { x=$?; echo Autoreconf FAILED! >&2; exit $x; }
067d23c9 255
c4444d16 256 ## Make sure src/stamp-h.in is newer than configure.ac.
a02d99e7
GM
257 rm -f src/stamp-h.in
258 echo timestamp > src/stamp-h.in
067d23c9
KY
259
260 echo "Updating Info files"
a02d99e7 261 make info-real
067d23c9
KY
262
263 echo "Updating finder, custom and autoload data"
a02d99e7 264 (cd lisp && make updates EMACS="$EMACS")
067d23c9 265
a02d99e7
GM
266 echo "Updating leim-list.el"
267 (cd leim && make leim-list.el EMACS="$EMACS")
067d23c9
KY
268
269 echo "Recompiling Lisp files"
270 $EMACS -batch -f batch-byte-recompile-directory lisp leim
271fi # $update = yes
272
273echo "Creating staging directory: \`${tempparent}'"
274
275mkdir ${tempparent}
276tempdir="${tempparent}/${emacsname}"
277
278### This trap ensures that the staging directory will be cleaned up even
279### when the script is interrupted in mid-career.
280if [ "${clean_up}" = yes ]; then
281 trap "echo 'Cleaning up the staging directory'; rm -rf ${tempparent}" EXIT
282fi
283
284echo "Creating top directory: \`${tempdir}'"
285mkdir ${tempdir}
286
287### We copy in the top-level files before creating the subdirectories in
288### hopes that this will make the top-level files appear first in the
289### tar file; this means that people can start reading the INSTALL and
290### README while the rest of the tar file is still unpacking. Whoopee.
291echo "Making links to top-level files"
24e0f6b1 292ln INSTALL README BUGS ${tempdir}
b8b0239f 293ln ChangeLog Makefile.in autogen.sh configure configure.ac ${tempdir}
ff0c3cfb 294ln config.bat make-dist .dir-locals.el ${tempdir}
9a514d4a 295ln aclocal.m4 ${tempdir}
067d23c9
KY
296
297echo "Creating subdirectories"
298for subdir in site-lisp \
299 leim leim/CXTERM-DIC leim/MISC-DIC \
300 leim/SKK-DIC leim/ja-dic leim/quail \
24e0f6b1 301 build-aux build-aux/snippet \
d66b744d 302 src src/bitmaps lib lib-src oldXMenu lwlib \
067d23c9 303 nt nt/inc nt/inc/sys nt/inc/arpa nt/inc/netinet nt/icons \
ff62aabc 304 `find etc lisp admin test -type d` \
067d23c9 305 doc doc/emacs doc/misc doc/man doc/lispref doc/lispintro \
07f3add9 306 info m4 msdos \
83da1b55
GM
307 nextstep nextstep/templates \
308 nextstep/Cocoa nextstep/Cocoa/Emacs.base \
067d23c9
KY
309 nextstep/Cocoa/Emacs.base/Contents \
310 nextstep/Cocoa/Emacs.base/Contents/Resources \
067d23c9
KY
311 nextstep/GNUstep \
312 nextstep/GNUstep/Emacs.base \
313 nextstep/GNUstep/Emacs.base/Resources
314do
ff62aabc
GM
315
316 if [ "$with_tests" != "yes" ]; then
317 case $subdir in
318 test*) continue ;;
319 esac
320 fi
321
067d23c9
KY
322 ## site-lisp for in-place installs (?).
323 [ "$subdir" = "site-lisp" ] || [ -d "$subdir" ] || \
324 echo "WARNING: $subdir not found, making anyway"
325 echo " ${tempdir}/${subdir}"
326 mkdir ${tempdir}/${subdir}
327done
328
329echo "Making links to \`lisp' and its subdirectories"
330files=`find lisp \( -name '*.el' -o -name '*.elc' -o -name 'ChangeLog*' \
331 -o -name 'README*' \)`
332
333### Don't distribute site-init.el, site-load.el, or default.el.
334for file in lisp/Makefile.in lisp/makefile.w32-in $files; do
335 case $file in
336 */site-init*|*/site-load*|*/default*) continue ;;
337 esac
338 ln $file $tempdir/$file
339done
340
341echo "Making links to \`leim' and its subdirectories"
342(cd leim
343 ln makefile.w32-in ../${tempdir}/leim
344 ln ChangeLog README ../${tempdir}/leim
345 ln CXTERM-DIC/README CXTERM-DIC/*.tit ../${tempdir}/leim/CXTERM-DIC
346 ln SKK-DIC/README SKK-DIC/SKK-JISYO.L ../${tempdir}/leim/SKK-DIC
347 ln MISC-DIC/README MISC-DIC/*.* ../${tempdir}/leim/MISC-DIC
348 ln ja-dic/*.el ja-dic/*.elc ../${tempdir}/leim/ja-dic
349 ln Makefile.in ../${tempdir}/leim/Makefile.in
350 ln leim-ext.el ../${tempdir}/leim/leim-ext.el
351 ## Lisp files that start with a capital (also 4Corner.el) are
352 ## generated from TIT dictionaries so we don't distribute them.
353 ln quail/[a-z]*.el quail/[a-z]*.elc ../${tempdir}/leim/quail
354 rm -f ../${tempdir}/leim/quail/quick-b5.*
355 rm -f ../${tempdir}/leim/quail/quick-cns.*
356 rm -f ../${tempdir}/leim/quail/tsang-b5.*
357 rm -f ../${tempdir}/leim/quail/tsang-cns.*)
358
24e0f6b1
PE
359echo "Making links to \`build-aux'"
360(cd build-aux
361 ln compile config.guess config.sub depcomp ../${tempdir}/build-aux
ff0c3cfb 362 ln install-sh missing move-if-change update-subdirs ../${tempdir}/build-aux)
24e0f6b1
PE
363
364echo "Making links to \`build-aux/snippet'"
365(cd build-aux/snippet
366 ln *.h ../../${tempdir}/build-aux/snippet)
367
067d23c9
KY
368echo "Making links to \`src'"
369### Don't distribute the configured versions of
370### config.in, paths.in, buildobj.h, or Makefile.in.
371(cd src
372 echo " (It is ok if ln fails in some cases.)"
373 ln [a-zA-Z]*.[chm] ../${tempdir}/src
374 ln [a-zA-Z]*.in ../${tempdir}/src
375 ln [a-zA-Z]*.mk ../${tempdir}/src
376 ln README ChangeLog ChangeLog.*[0-9] ../${tempdir}/src
377 ln makefile.w32-in ../${tempdir}/src
378 ln .gdbinit .dbxinit ../${tempdir}/src
379 cd ../${tempdir}/src
57e96f8e 380 rm -f globals.h config.h epaths.h Makefile buildobj.h)
067d23c9
KY
381
382echo "Making links to \`src/bitmaps'"
383(cd src/bitmaps
384 ln README *.xbm ../../${tempdir}/src/bitmaps)
385
9a514d4a 386echo "Making links to \`lib'"
24e0f6b1 387(snippet_h=`(cd build-aux/snippet && ls *.h)`
9a514d4a
PE
388 cd lib
389 ln [a-zA-Z]*.[ch] ../${tempdir}/lib
6e99ef20 390 ln gnulib.mk Makefile.am Makefile.in makefile.w32-in ../${tempdir}/lib
9a514d4a 391 cd ../${tempdir}/lib
24e0f6b1
PE
392 script='/[*]/d; s/\.in\.h$/.h/'
393 rm -f `(echo "$snippet_h"; ls *.in.h) | sed "$script"`)
9a514d4a 394
067d23c9
KY
395echo "Making links to \`lib-src'"
396(cd lib-src
397 ln [a-zA-Z]*.[ch] ../${tempdir}/lib-src
276d5f5d 398 ln ChangeLog Makefile.in README testfile ../${tempdir}/lib-src
418cd726 399 ln grep-changelog rcs2log ../${tempdir}/lib-src
84bbb1ad 400 ln makefile.w32-in ../${tempdir}/lib-src)
067d23c9
KY
401
402echo "Making links to \`m4'"
403(cd m4
404 ln *.m4 ../${tempdir}/m4)
405
067d23c9
KY
406echo "Making links to \`nt'"
407(cd nt
50a60e02
EZ
408 ln emacs-x86.manifest emacs-x64.manifest emacs.rc ../${tempdir}/nt
409 ln config.nt emacsclient.rc emacs-src.tags ../${tempdir}/nt
410 ln nmake.defs gmake.defs subdirs.el [a-z]*.bat [a-z]*.[ch] ../${tempdir}/nt
3e44c782 411 ln ChangeLog INSTALL README README.W32 makefile.w32-in ../${tempdir}/nt)
067d23c9
KY
412
413echo "Making links to \`nt/inc' and its subdirectories"
414for f in `find nt/inc -type f -name '[a-z]*.h'`; do
415 ln $f $tempdir/$f
416done
417
418echo "Making links to \`nt/icons'"
419(cd nt/icons
420 ln README [a-z]*.ico ../../${tempdir}/nt/icons
421 ln [a-z]*.cur ../../${tempdir}/nt/icons)
422
423echo "Making links to \`msdos'"
424(cd msdos
425 ln ChangeLog INSTALL README emacs.ico emacs.pif ../${tempdir}/msdos
0bd3cb7b 426 ln depfiles.bat inttypes.h ../${tempdir}/msdos
067d23c9
KY
427 ln is_exec.c sigaction.c mainmake.v2 sed*.inp ../${tempdir}/msdos)
428
429echo "Making links to \`nextstep'"
430(cd nextstep
92f7c6f1 431 ln ChangeLog README INSTALL Makefile.in ../${tempdir}/nextstep)
067d23c9 432
83da1b55
GM
433echo "Making links to \`nextstep/templates'"
434(cd nextstep/templates
51eed9b8 435 ln Emacs.desktop.in Info-gnustep.plist.in Info.plist.in InfoPlist.strings.in ../../${tempdir}/nextstep/templates)
83da1b55 436
067d23c9
KY
437echo "Making links to \`nextstep/Cocoa/Emacs.base/Contents'"
438(cd nextstep/Cocoa/Emacs.base/Contents
83da1b55 439 ln PkgInfo ../../../../${tempdir}/nextstep/Cocoa/Emacs.base/Contents)
067d23c9
KY
440
441echo "Making links to \`nextstep/Cocoa/Emacs.base/Contents/Resources'"
442(cd nextstep/Cocoa/Emacs.base/Contents/Resources
443 ln Credits.html *.icns ../../../../../${tempdir}/nextstep/Cocoa/Emacs.base/Contents/Resources)
444
067d23c9
KY
445echo "Making links to \`nextstep/GNUstep/Emacs.base/Resources'"
446(cd nextstep/GNUstep/Emacs.base/Resources
83da1b55 447 ln README emacs.tiff ../../../../${tempdir}/nextstep/GNUstep/Emacs.base/Resources )
067d23c9
KY
448
449echo "Making links to \`oldXMenu'"
450(cd oldXMenu
451 ln *.[ch] *.in ../${tempdir}/oldXMenu
452 ln README ChangeLog ../${tempdir}/oldXMenu)
453
454echo "Making links to \`lwlib'"
455(cd lwlib
456 ln *.[ch] *.in ../${tempdir}/lwlib
457 ln README ChangeLog ../${tempdir}/lwlib)
458
6166381e
CY
459echo "Making links to \`admin' and its subdirectories"
460for f in `find admin -type f`; do
461 ln $f $tempdir/$f
462done
463
ff62aabc
GM
464if [ "$with_tests" = "yes" ]; then
465 echo "Making links to \`test' and its subdirectories"
466 for f in `find test -type f`; do
467 case $f in
468 test/automated/flymake/warnpred/a.out) continue ;;
469 test/automated/Makefile) continue ;;
470 esac
471 ln $f $tempdir/$f
472 done
473fi
474
067d23c9
KY
475echo "Making links to \`etc' and its subdirectories"
476for f in `find etc -type f`; do
477 case $f in
838db889 478 etc/DOC*|etc/*.pyc) continue ;;
067d23c9
KY
479 esac
480 ln $f $tempdir/$f
481done
482
483echo "Making links to \`info'"
484ln `find info -type f -print` ${tempdir}/info
485
486echo "Making links to \`doc/emacs'"
487(cd doc/emacs
488 ln *.texi *.in makefile.w32-in ChangeLog* ../../${tempdir}/doc/emacs)
489
490echo "Making links to \`doc/misc'"
491(cd doc/misc
492 ln *.texi *.tex *.in makefile.w32-in gnus-news.el ChangeLog* ../../${tempdir}/doc/misc)
493
494echo "Making links to \`doc/lispref'"
495(cd doc/lispref
496 ln *.texi *.in makefile.w32-in README ChangeLog* ../../${tempdir}/doc/lispref
5122804a
GM
497 ln spellfile ../../${tempdir}/doc/lispref
498 ln two-volume.make two-volume-cross-refs.txt ../../${tempdir}/doc/lispref)
067d23c9
KY
499
500echo "Making links to \`doc/lispintro'"
501(cd doc/lispintro
502 ln *.texi *.in makefile.w32-in *.eps *.pdf ../../${tempdir}/doc/lispintro
503 ln README ChangeLog* ../../${tempdir}/doc/lispintro
504 cd ../../${tempdir}/doc/lispintro)
505
506echo "Making links to \`doc/man'"
507(cd doc/man
508 ln ChangeLog* *.1 ../../${tempdir}/doc/man
509 cd ../../${tempdir}/doc/man)
510
511### It would be nice if they could all be symlinks to top-level copy, but
512### you're not supposed to have any symlinks in distribution tar files.
513echo "Making sure copying notices are all copies of \`COPYING'"
9a514d4a 514for subdir in . etc info leim lib lib-src lisp lwlib msdos nt src; do
067d23c9
KY
515 rm -f ${tempdir}/${subdir}/COPYING
516 cp COPYING ${tempdir}/${subdir}
517done
518
519if [ "${newer}" ]; then
520 echo "Removing files older than $newer"
521 ## We remove .elc files unconditionally, on the theory that anyone picking
522 ## up an incremental distribution already has a running Emacs to byte-compile
523 ## them with.
524 find ${tempparent} \( -name '*.elc' -o ! -newer ${newer} \) -exec rm -f {} \;
525fi
526
527## Don't distribute backups, autosaves, etc.
528echo "Removing unwanted files"
529find ${tempparent} \( -name '*~' -o -name '#*#' -o -name '.*ignore' -o -name '=*' -o -name 'TAGS' \) -exec rm -f {} \;
530
531if [ "${make_tar}" = yes ]; then
532 echo "Looking for $default_gzip"
533 found=0
534 temppath=`echo $PATH | sed -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \
535 -e 's/:/ /g'`
536 for dir in ${temppath}; do
537 [ -x ${dir}/$default_gzip ] || continue
538 found=1; break
539 done
540 if [ "$found" = "0" ]; then
541 echo "WARNING: \`$default_gzip' not found, will not compress" >&2
542 default_gzip=cat
543 fi
544 case "${default_gzip}" in
545 bzip2) gzip_extension=.bz2 ;;
546 lzma) gzip_extension=.lzma ;;
39aff4a7 547 xz) gzip_extension=.xz ;;
067d23c9
KY
548 gzip) gzip_extension=.gz ; default_gzip="gzip --best";;
549 *) gzip_extension= ;;
550 esac
551 echo "Creating tar file"
552 (cd ${tempparent} ; tar cvf - ${emacsname} ) \
553 | ${default_gzip} \
554 > ${emacsname}.tar${gzip_extension}
555fi
556
557if [ "${clean_up}" != yes ]; then
558 (cd ${tempparent}; mv ${emacsname} ..)
559 rm -rf ${tempparent}
560fi
561
562### make-dist ends here