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