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