* make-dist: Check for .elc files with no corresponding .el file.
[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 progname="$0"
10
11 ### Exit if a command fails.
12 ### set -e
13
14 ### Print out each line we read, for debugging's sake.
15 ### set -v
16
17 clean_up=yes
18 make_tar=yes
19 newer=""
20
21 while [ $# -gt 0 ]; do
22 case "$1" in
23 ## This option tells make-dist not to delete the staging directory
24 ## after it's done making the tar file.
25 "--no-clean-up" )
26 clean_up=no
27 ;;
28 ## This option tells make-dist not to make a tar file. Since it's
29 ## rather pointless to build the whole staging directory and then
30 ## nuke it, using this option also selects '--no-clean-up'.
31 "--no-tar" )
32 make_tar=no
33 clean_up=no
34 ;;
35 ## This option tells make-dist to make the distribution normally, then
36 ## remove all files older than the given timestamp file. This is useful
37 ## for creating incremental or patch distributions.
38 "--newer")
39 newer="$2"
40 new_extension=".new"
41 shift
42 ;;
43 ## This option tells make-dist to use `compress' instead of gzip.
44 ## Normally, make-dist uses gzip whenever it is present.
45 "--compress")
46 default_gzip="compress"
47 ;;
48 * )
49 echo "${progname}: Unrecognized argument: $1" >&2
50 exit 1
51 ;;
52 esac
53 shift
54 done
55
56 ### Make sure we're running in the right place.
57 if [ ! -d src -o ! -f src/lisp.h -o ! -d lisp -o ! -f lisp/version.el ]; then
58 echo "${progname}: Can't find \`src/lisp.h' and \`lisp/version.el'." >&2
59 echo "${progname} must be run in the top directory of the Emacs" >&2
60 echo "distribution tree. Cd to that directory and try again." >&2
61 exit 1
62 fi
63
64 ### Find out which version of Emacs this is.
65 version=`grep 'defconst[ ]*emacs-version' lisp/version.el \
66 | sed -e 's/^.*"\([0-9][0-9]*\.[0-9][0-9]*\)\..*$/\1/'`
67 if [ ! "${version}" ]; then
68 echo "${progname}: can't find current emacs version in \`./lisp/version.el'." >&2
69 exit 1
70 fi
71
72 if grep -s "GNU Emacs version ${version}" ./man/emacs.texi > /dev/null; then
73 true
74 else
75 echo "You must update the version number in \`./man/emacs.texi'"
76 exit 1
77 fi
78
79 ### Make sure the subdirectory is available.
80 tempparent="make-dist.tmp.$$"
81 if [ -d ${tempparent} ]; then
82 echo "${progname}: staging directory \`${tempparent}' already exists.
83 Perhaps a previous invocation of \`${progname}' failed to clean up after
84 itself. Check that directories whose names are of the form
85 \`make-dist.tmp.NNNNN' don't contain any important information, remove
86 them, and try again." >&2
87 exit 1
88 fi
89
90 ### Check for .elc files with no corresponding .el file.
91 ls -1 lisp/*.el | sed 's/\.el$/.elc/' > /tmp/el
92 ls -1 lisp/*.elc > /tmp/elc
93 comm -13 /tmp/el /tmp/elc
94
95 echo "Creating staging directory: \`${tempparent}'"
96 mkdir ${tempparent}
97 emacsname="emacs-${version}${new_extension}"
98 tempdir="${tempparent}/${emacsname}"
99
100 ### This trap ensures that the staging directory will be cleaned up even
101 ### when the script is interrupted in mid-career.
102 if [ "${clean_up}" = yes ]; then
103 trap "echo 'Interrupted...cleaning up the staging directory.'; rm -rf ${tempparent}; exit 1" 1 2 15
104 fi
105
106 echo "Creating top directory: \`${tempdir}'"
107 mkdir ${tempdir}
108
109 ### We copy in the top-level files before creating the subdirectories in
110 ### hopes that this will make the top-level files appear first in the
111 ### tar file; this means that people can start reading the INSTALL and
112 ### README while the rest of the tar file is still unpacking. Whoopee.
113 echo "Making links to top-level files."
114 ln GETTING.GNU.SOFTWARE INSTALL PROBLEMS README move-if-change ${tempdir}
115 ln ChangeLog Makefile.in build-install.in configure configure.in ${tempdir}
116 ln make-dist ${tempdir}
117 ### Copy config.sub; it's a cross-filesystem symlink.
118 cp config.sub ${tempdir}
119
120 echo "Updating version number in README."
121 (cd ${tempdir}
122 awk \
123 '$1 " " $2 " " $3 " " $4 " " $5 == "This directory tree holds version" { $6 = version; print $0 }
124 $1 " " $2 " " $3 " " $4 " " $5 != "This directory tree holds version"' \
125 version=${version} README > tmp.README
126 mv tmp.README README)
127
128
129 echo "Creating subdirectories."
130 # I think we're not going to distribute anything in external-lisp, so
131 # I've removed it from this list.
132 for subdir in lisp lisp/term local-lisp \
133 src src/m src/s src/bitmaps lib-src oldXMenu \
134 etc lock cpp info man shortnames vms; do
135 mkdir ${tempdir}/${subdir}
136 done
137
138 echo "Making links to \`lisp'."
139 ### Don't distribute TAGS, =*.el files, site-init.el, site-load.el, or default.el.
140 (cd lisp
141 ln [a-zA-Z]*.el ../${tempdir}/lisp
142 ln [a-zA-Z]*.elc ../${tempdir}/lisp
143 ## simula.el doesn't keep abbreviations in simula.defns any more.
144 ## ln [a-zA-Z]*.defns ../${tempdir}/lisp
145 ln ChangeLog README ../${tempdir}/lisp
146 cd ../${tempdir}/lisp
147 rm -f TAGS =*
148 rm -f site-init site-init.el site-init.elc
149 rm -f site-load site-load.el site-load.elc
150 rm -f default default.el default.elc)
151
152 #echo "Making links to \`lisp/calc-2.02'."
153 #### Don't distribute =*.el files, TAGS or backups.
154 #(cd lisp/calc-2.02
155 # ln [a-zA-Z]*.el ../../${tempdir}/lisp/calc-2.02
156 # ln [a-zA-Z]*.elc ../../${tempdir}/lisp/calc-2.02
157 # ln calc.info* calc.texinfo calc-refcard.* ../../${tempdir}/lisp/calc-2.02
158 # ln INSTALL Makefile README README.prev ../../${tempdir}/lisp/calc-2.02
159 # cd ../../${tempdir}/lisp/calc-2.02
160 # rm -f *~ TAGS)
161
162 echo "Making links to \`lisp/term'."
163 ### Don't distribute =*.el files or TAGS.
164 (cd lisp/term
165 ln [a-zA-Z]*.el ../../${tempdir}/lisp/term
166 ln [a-zA-Z]*.elc ../../${tempdir}/lisp/term
167 ln README ChangeLog ../../${tempdir}/lisp/term
168 rm -f =* TAGS)
169
170 ### echo "Making links to \`external-lisp'."
171 ### ### Don't distribute =*.el files or TAGS.
172 ### (cd external-lisp
173 ### ln [a-zA-Z]*.el ../${tempdir}/external-lisp
174 ### ln [a-zA-Z]*.elc ../${tempdir}/external-lisp
175 ### ln ChangeLog README ../${tempdir}/external-lisp
176 ### rm -f =* TAGS)
177
178 echo "Making links to \`src'."
179 ### Don't distribute =*.[ch] files, or the configured versions of
180 ### config.h.in, paths.h.in, or Makefile.in, or TAGS.
181 (cd src
182 echo " (If we can't link gmalloc.c, that's okay.)"
183 ln [a-zA-Z]*.c ../${tempdir}/src
184 ## Might be a symlink to a file on another filesystem.
185 test -f ../${tempdir}/src/gmalloc.c || cp gmalloc.c ../${tempdir}/src
186 ln [a-zA-Z]*.h ../${tempdir}/src
187 ln [a-zA-Z]*.s ../${tempdir}/src
188 ln README Makefile.in ymakefile ChangeLog config.h.in paths.h.in \
189 ../${tempdir}/src
190 ln .gdbinit .dbxinit ../${tempdir}/src
191 ln *.opt vms-pp.trans ../${tempdir}/src
192 cd ../${tempdir}/src
193 rm -f config.h paths.h Makefile
194 if [ -z "${newer}" ]; then
195 etags *.h *.c ../lisp/*.el
196 fi
197 rm -f =* TAGS)
198
199 echo "Making links to \`src/bitmaps'."
200 (cd src/bitmaps
201 ln README *.xbm ../../${tempdir}/src/bitmaps)
202
203 echo "Making links to \`src/m'."
204 (cd src/m
205 ln README [a-zA-Z0-9]*.h ../../${tempdir}/src/m)
206
207 echo "Making links to \`src/s'."
208 (cd src/s
209 ln README [a-zA-Z0-9]*.h ../../${tempdir}/src/s)
210
211 echo "Making links to \`lib-src'."
212 (cd lib-src
213 ln [a-zA-Z]*.[chy] [a-zA-Z]*.lex ../${tempdir}/lib-src
214 ln ChangeLog Makefile.in README testfile vcdiff rcs2log ../${tempdir}/lib-src
215 ln emacs.csh rcs-checkin ../${tempdir}/lib-src
216 cd ../${tempdir}/lib-src
217 rm -f getdate.c getdate.tab.c y.tab.c y.tab.h
218 rm -f =* TAGS)
219
220 echo "Making links to \`oldXMenu'."
221 (cd oldXMenu
222 ln *.c *.h *.in ../${tempdir}/oldXMenu
223 ln README Imakefile ChangeLog ../${tempdir}/oldXMenu
224 ln compile.com descrip.mms ../${tempdir}/oldXMenu)
225
226 echo "Making links to \`etc'."
227 ### Don't distribute = files, TAGS, DOC files, backups, autosaves, or
228 ### tex litter.
229 (cd etc
230 ln `ls -d * | grep -v 'RCS' | grep -v 'Old'` ../${tempdir}/etc
231 cd ../${tempdir}/etc
232 rm -f DOC* *~ \#*\# *.dvi *.log *,v =* core
233 rm -f TAGS)
234
235 echo "Making links to \`cpp'."
236 (cd cpp
237 ln cccp.c cexp.y Makefile README ../${tempdir}/cpp)
238
239 echo "Making links to \`info'."
240 # Don't distribute backups or autosaves.
241 (cd info
242 ln [a-zA-Z]* ../${tempdir}/info
243 cd ../${tempdir}/info
244 # Avoid an error when expanding the wildcards later.
245 ln emacs dummy~ ; ln emacs \#dummy\#
246 rm -f *~ \#*\# core)
247
248 echo "Making links to \`man'."
249 (cd man
250 ln *.texinfo *.texi *.aux *.cps *.fns *.kys *.vrs ../${tempdir}/man
251 test -f README && ln README ../${tempdir}/man
252 test -f Makefile && ln Makefile ../${tempdir}/man
253 ln ChangeLog split-man ../${tempdir}/man
254 cp texinfo.tex texindex.c ../${tempdir}/man
255 cd ../${tempdir}/man
256 rm -f \#*\# =* *~ core emacs-index* *.Z *.z xmail
257 rm -f emacs.?? termcap.?? gdb.?? *.log *.toc *.dvi *.oaux)
258
259 echo "Making links to \`shortnames'."
260 (cd shortnames
261 ln *.c ../${tempdir}/shortnames
262 ln Makefile reserved special ../${tempdir}/shortnames)
263
264 echo "Making links to \`vms'."
265 (cd vms
266 ln [0-9a-zA-Z]* ../${tempdir}/vms
267 cd ../${tempdir}/vms
268 rm -f *~)
269
270 ### It would be nice if they could all be symlinks to etc's copy, but
271 ### you're not supposed to have any symlinks in distribution tar files.
272 echo "Making sure copying notices are all copies of \`etc/COPYING'."
273 rm -f ${tempdir}/etc/COPYING
274 cp etc/COPYING ${tempdir}/etc/COPYING
275 # I think we're not going to distribute anything in external-lisp, so
276 # I've removed it from this list.
277 for subdir in lisp src lib-src info shortnames; do
278 if [ -f ${tempdir}/${subdir}/COPYING ]; then
279 rm ${tempdir}/${subdir}/COPYING
280 fi
281 cp etc/COPYING ${tempdir}/${subdir}
282 done
283
284 #### Make sure that there aren't any hard links between files in the
285 #### distribution; people with afs can't deal with that. Okay,
286 #### actually we just re-copy anything with a link count greater
287 #### than two.
288 echo "Breaking intra-tree links."
289 find ${tempdir} ! -type d -links +2 \
290 -exec cp {} $$ \; -exec rm -f {} \; -exec mv $$ {} \;
291
292 if [ "${newer}" ]; then
293 echo "Removing files older than $newer."
294 ## We remove .elc files unconditionally, on the theory that anyone picking
295 ## up an incremental distribution already has a running Emacs to byte-compile
296 ## them with.
297 find ${tempparent} \( -name '*.elc' -o ! -newer ${newer} \) -exec rm -f {} \;
298 fi
299
300 if [ "${make_tar}" = yes ]; then
301 if [ "${default_gzip}" = "" ]; then
302 echo "Looking for gzip."
303 temppath=`echo $PATH | sed 's/^:/.:/
304 s/::/:.:/g
305 s/:$/:./
306 s/:/ /g'`
307 default_gzip=`(
308 for dir in ${temppath}; do
309 if [ -f ${dir}/gzip ]; then echo 'gzip --best'; exit 0; fi
310 done
311 echo compress
312 )`
313 fi
314 case "${default_gzip}" in
315 compress* ) gzip_extension=.Z ;;
316 * ) gzip_extension=.z ;;
317 esac
318 echo "Creating tar file."
319 (cd ${tempparent} ; tar cvf - ${emacsname} ) \
320 | ${default_gzip} \
321 > ${emacsname}.tar${gzip_extension}
322 fi
323
324 if [ "${clean_up}" = yes ]; then
325 echo "Cleaning up the staging directory."
326 rm -rf ${tempparent}
327 fi
328
329 ### make-dist ends here