make-dist 10.8 KB
Newer Older
Jim Blandy's avatar
Jim Blandy committed
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 6 7
#### structure, and then hard links into it only those files that should
#### be distributed.  This means that if you add a file with an odd name,
#### you should make sure that this script will include it.
Jim Blandy's avatar
Jim Blandy committed
8 9 10

progname="$0"

11 12
### Exit if a command fails.
### set -e
Jim Blandy's avatar
Jim Blandy committed
13

14 15
### Print out each line we read, for debugging's sake.
### set -v
Jim Blandy's avatar
Jim Blandy committed
16

Jim Blandy's avatar
Jim Blandy committed
17 18
clean_up=yes
make_tar=yes
Eric S. Raymond's avatar
Eric S. Raymond committed
19
newer=""
Jim Blandy's avatar
Jim Blandy committed
20 21 22

while [ $# -gt 0 ]; do
  case "$1" in
23 24
    ## This option tells make-dist not to delete the staging directory
    ## after it's done making the tar file.
Eric S. Raymond's avatar
Eric S. Raymond committed
25
    "--no-clean-up" )
Jim Blandy's avatar
Jim Blandy committed
26 27
      clean_up=no
    ;;
28 29 30
    ## This option tells make-dist not to make a tar file.  Since it's 
    ## rather pointless to build the whole staging directory and then
    ## nuke it, using this option also selects '--no-clean-up'.
Jim Blandy's avatar
Jim Blandy committed
31 32 33
    "--no-tar" )
      make_tar=no
      clean_up=no
Jim Blandy's avatar
Jim Blandy committed
34
    ;;
35
    ## This option tells make-dist to make the distribution normally, then
36 37
    ## remove all files older than the given timestamp file.  This is useful
    ## for creating incremental or patch distributions.
Eric S. Raymond's avatar
Eric S. Raymond committed
38
    "--newer")
Jim Blandy's avatar
Jim Blandy committed
39 40
      newer="$2"
      new_extension=".new"
Eric S. Raymond's avatar
Eric S. Raymond committed
41 42
      shift
    ;;
43 44 45 46 47
    ## This option tells make-dist to use `compress' instead of gzip.
    ## Normally, make-dist uses gzip whenever it is present.
    "--compress")
      default_gzip="compress"
    ;;
Jim Blandy's avatar
Jim Blandy committed
48 49 50 51 52 53 54 55
    * )
      echo "${progname}: Unrecognized argument: $1" >&2
      exit 1
    ;;
  esac
  shift
done

56
### Make sure we're running in the right place.
Jim Blandy's avatar
Jim Blandy committed
57
if [ ! -d src -o ! -f src/lisp.h -o ! -d lisp -o ! -f lisp/version.el ]; then
Eric S. Raymond's avatar
Eric S. Raymond committed
58 59
  echo "${progname}: Can't find \`src/lisp.h' and \`lisp/version.el'." >&2
  echo "${progname} must be run in the top directory of the Emacs" >&2
Jim Blandy's avatar
Jim Blandy committed
60 61 62 63
  echo "distribution tree.  Cd to that directory and try again." >&2
  exit 1
fi

64
### Find out which version of Emacs this is.
Jim Blandy's avatar
Jim Blandy committed
65
version=`grep 'defconst[	 ]*emacs-version' lisp/version.el \
Jim Blandy's avatar
Jim Blandy committed
66
	 | sed -e 's/^.*"\([0-9][0-9]*\.[0-9][0-9]*\)\..*$/\1/'`
Jim Blandy's avatar
Jim Blandy committed
67
if [ ! "${version}" ]; then
Eric S. Raymond's avatar
Eric S. Raymond committed
68
  echo "${progname}: can't find current emacs version in \`./lisp/version.el'." >&2
Jim Blandy's avatar
Jim Blandy committed
69 70 71
  exit 1
fi

72 73 74 75 76 77 78
if grep -s "GNU Emacs version ${version}" ./man/emacs.texi > /dev/null; then
  true
else
  echo "You must update the version number in \`./man/emacs.texi'"
  exit 1
fi

79
### Make sure the subdirectory is available.
Eric S. Raymond's avatar
Eric S. Raymond committed
80
tempparent="make-dist.tmp.$$"
Jim Blandy's avatar
Jim Blandy committed
81
if [ -d ${tempparent} ]; then
Eric S. Raymond's avatar
Eric S. Raymond committed
82 83 84 85 86
  echo "${progname}: staging directory \`${tempparent}' already exists.
Perhaps a previous invocation of \`${progname}' failed to clean up after
itself.  Check that directories whose names are of the form
\`make-dist.tmp.NNNNN' don't contain any important information, remove
them, and try again." >&2
Jim Blandy's avatar
Jim Blandy committed
87 88 89
  exit 1
fi

90 91 92
### Check for .elc files with no corresponding .el file.
ls -1 lisp/*.el | sed 's/\.el$/.elc/' > /tmp/el
ls -1 lisp/*.elc > /tmp/elc
93 94 95 96 97
bogosities="`comm -13 /tmp/el /tmp/elc`"
if [ "${bogosities}" != "" ]; then
  echo "The following .elc files have no corresponding .el files:"
  echo "${bogosities}"
fi
98
rm -f /tmp/el /tmp/elc
99

Eric S. Raymond's avatar
Eric S. Raymond committed
100
echo "Creating staging directory: \`${tempparent}'"
Jim Blandy's avatar
Jim Blandy committed
101
mkdir ${tempparent}
Jim Blandy's avatar
Jim Blandy committed
102
emacsname="emacs-${version}${new_extension}"
Jim Blandy's avatar
Jim Blandy committed
103 104
tempdir="${tempparent}/${emacsname}"

105 106
### This trap ensures that the staging directory will be cleaned up even
### when the script is interrupted in mid-career.
Eric S. Raymond's avatar
Eric S. Raymond committed
107 108 109 110
if [ "${clean_up}" = yes ]; then
  trap "echo 'Interrupted...cleaning up the staging directory.'; rm -rf ${tempparent}; exit 1" 1 2 15
fi

Eric S. Raymond's avatar
Eric S. Raymond committed
111
echo "Creating top directory: \`${tempdir}'"
Jim Blandy's avatar
Jim Blandy committed
112 113
mkdir ${tempdir}

114 115 116 117
### We copy in the top-level files before creating the subdirectories in
### hopes that this will make the top-level files appear first in the
### tar file; this means that people can start reading the INSTALL and
### README while the rest of the tar file is still unpacking.  Whoopee.
Eric S. Raymond's avatar
Eric S. Raymond committed
118 119
echo "Making links to top-level files." 
ln GETTING.GNU.SOFTWARE INSTALL PROBLEMS README move-if-change ${tempdir}
120
ln ChangeLog Makefile.in build-install.in configure configure.in ${tempdir}
121
ln make-dist ${tempdir}
122 123
### Copy config.sub; it's a cross-filesystem symlink.
cp config.sub ${tempdir}
Jim Blandy's avatar
Jim Blandy committed
124

125 126 127 128 129 130 131 132 133
echo "Updating version number in README."
(cd ${tempdir}
 awk \
   '$1 " " $2 " " $3 " " $4 " " $5 == "This directory tree holds version" { $6 = version; print $0 }
    $1 " " $2 " " $3 " " $4 " " $5 != "This directory tree holds version"' \
   version=${version} README > tmp.README
 mv tmp.README README)


Jim Blandy's avatar
Jim Blandy committed
134
echo "Creating subdirectories."
135 136
# I think we're not going to distribute anything in external-lisp, so
# I've removed it from this list.
137
for subdir in lisp lisp/term site-lisp \
138
	      src src/m src/s src/bitmaps lib-src oldXMenu \
139
	      etc lock cpp info man shortnames vms; do
Jim Blandy's avatar
Jim Blandy committed
140 141 142
  mkdir ${tempdir}/${subdir}
done

Eric S. Raymond's avatar
Eric S. Raymond committed
143
echo "Making links to \`lisp'."
144
### Don't distribute TAGS, =*.el files, site-init.el, site-load.el, or default.el.
Jim Blandy's avatar
Jim Blandy committed
145 146 147
(cd lisp
 ln [a-zA-Z]*.el ../${tempdir}/lisp
 ln [a-zA-Z]*.elc ../${tempdir}/lisp
148 149
 ## simula.el doesn't keep abbreviations in simula.defns any more.
 ## ln [a-zA-Z]*.defns ../${tempdir}/lisp
Jim Blandy's avatar
Jim Blandy committed
150 151
 ln ChangeLog README ../${tempdir}/lisp
 cd ../${tempdir}/lisp
152
 rm -f TAGS =*
Jim Blandy's avatar
Jim Blandy committed
153
 rm -f site-init site-init.el site-init.elc
Jim Blandy's avatar
Jim Blandy committed
154 155
 rm -f site-load site-load.el site-load.elc
 rm -f default default.el default.elc)
Jim Blandy's avatar
Jim Blandy committed
156

157 158 159 160 161 162 163 164 165
#echo "Making links to \`lisp/calc-2.02'."
#### Don't distribute =*.el files, TAGS or backups.
#(cd lisp/calc-2.02
# ln [a-zA-Z]*.el ../../${tempdir}/lisp/calc-2.02
# ln [a-zA-Z]*.elc ../../${tempdir}/lisp/calc-2.02
# ln calc.info* calc.texinfo calc-refcard.* ../../${tempdir}/lisp/calc-2.02
# ln INSTALL Makefile README README.prev ../../${tempdir}/lisp/calc-2.02
# cd ../../${tempdir}/lisp/calc-2.02
# rm -f *~ TAGS)
166

Eric S. Raymond's avatar
Eric S. Raymond committed
167
echo "Making links to \`lisp/term'."
168
### Don't distribute =*.el files or TAGS.
Jim Blandy's avatar
Jim Blandy committed
169 170 171
(cd lisp/term
 ln [a-zA-Z]*.el ../../${tempdir}/lisp/term
 ln [a-zA-Z]*.elc ../../${tempdir}/lisp/term
172
 ln README ChangeLog ../../${tempdir}/lisp/term
173
 rm -f =* TAGS)
Jim Blandy's avatar
Jim Blandy committed
174

175
### echo "Making links to \`external-lisp'."
176
### ### Don't distribute =*.el files or TAGS.
177 178 179
### (cd external-lisp
###  ln [a-zA-Z]*.el ../${tempdir}/external-lisp
###  ln [a-zA-Z]*.elc ../${tempdir}/external-lisp
180 181
###  ln ChangeLog README ../${tempdir}/external-lisp
###  rm -f =* TAGS)
Eric S. Raymond's avatar
Eric S. Raymond committed
182 183

echo "Making links to \`src'."
184
### Don't distribute =*.[ch] files, or the configured versions of
185
### config.h.in, paths.h.in, or Makefile.in, or TAGS.
Jim Blandy's avatar
Jim Blandy committed
186
(cd src
187
 echo "  (If we can't link gmalloc.c, that's okay.)"
Jim Blandy's avatar
Jim Blandy committed
188
 ln [a-zA-Z]*.c ../${tempdir}/src
189
 ## Might be a symlink to a file on another filesystem.
Jim Blandy's avatar
Jim Blandy committed
190
 test -f ../${tempdir}/src/gmalloc.c || cp gmalloc.c ../${tempdir}/src
Jim Blandy's avatar
Jim Blandy committed
191 192 193 194 195
 ln [a-zA-Z]*.h ../${tempdir}/src
 ln [a-zA-Z]*.s ../${tempdir}/src
 ln README Makefile.in ymakefile ChangeLog config.h.in paths.h.in \
    ../${tempdir}/src
 ln .gdbinit .dbxinit ../${tempdir}/src
196
 ln *.opt vms-pp.trans ../${tempdir}/src
Jim Blandy's avatar
Jim Blandy committed
197
 cd ../${tempdir}/src
Jim Blandy's avatar
Jim Blandy committed
198 199 200
 rm -f config.h paths.h Makefile
 if [ -z "${newer}" ]; then
   etags *.h *.c ../lisp/*.el
201 202
 fi
 rm -f =* TAGS)
Jim Blandy's avatar
Jim Blandy committed
203

204 205 206 207
echo "Making links to \`src/bitmaps'."
(cd src/bitmaps
 ln README *.xbm ../../${tempdir}/src/bitmaps)

Eric S. Raymond's avatar
Eric S. Raymond committed
208
echo "Making links to \`src/m'."
Jim Blandy's avatar
Jim Blandy committed
209
(cd src/m
210
 ln README [a-zA-Z0-9]*.h ../../${tempdir}/src/m)
Jim Blandy's avatar
Jim Blandy committed
211

Eric S. Raymond's avatar
Eric S. Raymond committed
212
echo "Making links to \`src/s'."
Jim Blandy's avatar
Jim Blandy committed
213
(cd src/s
214
 ln README [a-zA-Z0-9]*.h ../../${tempdir}/src/s)
Jim Blandy's avatar
Jim Blandy committed
215

Eric S. Raymond's avatar
Eric S. Raymond committed
216
echo "Making links to \`lib-src'."
Jim Blandy's avatar
Jim Blandy committed
217
(cd lib-src
218
 ln [a-zA-Z]*.[chy] [a-zA-Z]*.lex ../${tempdir}/lib-src
Eric S. Raymond's avatar
Eric S. Raymond committed
219
 ln ChangeLog Makefile.in README testfile vcdiff rcs2log ../${tempdir}/lib-src
220
 ln emacs.csh rcs-checkin ../${tempdir}/lib-src
Eric S. Raymond's avatar
Eric S. Raymond committed
221
 cd ../${tempdir}/lib-src
222 223
 rm -f getdate.c getdate.tab.c y.tab.c y.tab.h
 rm -f =* TAGS)
Jim Blandy's avatar
Jim Blandy committed
224

Eric S. Raymond's avatar
Eric S. Raymond committed
225
echo "Making links to \`oldXMenu'."
Jim Blandy's avatar
Jim Blandy committed
226
(cd oldXMenu
227
 ln *.c *.h *.in ../${tempdir}/oldXMenu
228
 ln README Imakefile ChangeLog ../${tempdir}/oldXMenu
229
 ln compile.com descrip.mms ../${tempdir}/oldXMenu)
Jim Blandy's avatar
Jim Blandy committed
230

Eric S. Raymond's avatar
Eric S. Raymond committed
231
echo "Making links to \`etc'."
232 233
### Don't distribute = files, TAGS, DOC files, backups, autosaves, or
### tex litter.
Jim Blandy's avatar
Jim Blandy committed
234
(cd etc
235
 ln `ls -d * | grep -v 'RCS' | grep -v 'Old'` ../${tempdir}/etc
Jim Blandy's avatar
Jim Blandy committed
236
 cd ../${tempdir}/etc
237 238
 rm -f DOC* *~ \#*\# *.dvi *.log *,v =* core
 rm -f TAGS)
Jim Blandy's avatar
Jim Blandy committed
239

240 241 242 243
echo "Making links to \`cpp'."
(cd cpp
 ln cccp.c cexp.y Makefile README ../${tempdir}/cpp)

244 245 246 247 248 249 250 251
echo "Making links to \`info'."
# Don't distribute backups or autosaves.
(cd info
 ln [a-zA-Z]* ../${tempdir}/info
 cd ../${tempdir}/info
 # Avoid an error when expanding the wildcards later.
 ln emacs dummy~ ; ln emacs \#dummy\#
 rm -f *~ \#*\# core)
252 253 254

echo "Making links to \`man'."
(cd man
255
 ln *.texinfo *.texi *.aux *.cps *.fns *.kys *.vrs ../${tempdir}/man
256 257
 test -f README && ln README ../${tempdir}/man
 test -f Makefile && ln Makefile ../${tempdir}/man
258 259
 ln ChangeLog split-man ../${tempdir}/man
 cp texinfo.tex texindex.c ../${tempdir}/man
Richard M. Stallman's avatar
Richard M. Stallman committed
260
 cd ../${tempdir}/man
261 262
 rm -f \#*\# =* *~ core emacs-index* *.Z *.z xmail
 rm -f emacs.?? termcap.?? gdb.?? *.log *.toc *.dvi *.oaux)
Jim Blandy's avatar
Jim Blandy committed
263

Eric S. Raymond's avatar
Eric S. Raymond committed
264
echo "Making links to \`shortnames'."
Jim Blandy's avatar
Jim Blandy committed
265 266 267 268
(cd shortnames
 ln *.c ../${tempdir}/shortnames
 ln Makefile reserved special ../${tempdir}/shortnames)

Jim Blandy's avatar
Jim Blandy committed
269 270 271 272 273 274
echo "Making links to \`vms'."
(cd vms
 ln [0-9a-zA-Z]* ../${tempdir}/vms
 cd ../${tempdir}/vms
 rm -f *~)

275 276 277
### It would be nice if they could all be symlinks to etc's copy, but
### you're not supposed to have any symlinks in distribution tar files.
echo "Making sure copying notices are all copies of \`etc/COPYING'."
Eric S. Raymond's avatar
Eric S. Raymond committed
278 279
rm -f ${tempdir}/etc/COPYING
cp etc/COPYING ${tempdir}/etc/COPYING
280 281 282
# I think we're not going to distribute anything in external-lisp, so
# I've removed it from this list.
for subdir in lisp src lib-src info shortnames; do
Jim Blandy's avatar
Jim Blandy committed
283 284 285
  if [ -f ${tempdir}/${subdir}/COPYING ]; then
    rm ${tempdir}/${subdir}/COPYING
  fi
286
  cp etc/COPYING ${tempdir}/${subdir}
Jim Blandy's avatar
Jim Blandy committed
287 288
done

289 290 291 292 293
#### Make sure that there aren't any hard links between files in the
#### distribution; people with afs can't deal with that.  Okay,
#### actually we just re-copy anything with a link count greater
#### than two.
echo "Breaking intra-tree links."
294 295
find ${tempdir} ! -type d -links +2 \
  -exec cp {} $$ \; -exec rm -f {} \; -exec mv $$ {} \;
296

Eric S. Raymond's avatar
Eric S. Raymond committed
297 298
if [ "${newer}" ]; then
  echo "Removing files older than $newer."
299 300 301
  ## We remove .elc files unconditionally, on the theory that anyone picking
  ## up an incremental distribution already has a running Emacs to byte-compile
  ## them with.
Eric S. Raymond's avatar
Eric S. Raymond committed
302 303 304
  find ${tempparent} \( -name '*.elc' -o ! -newer ${newer} \) -exec rm -f {} \;
fi

Jim Blandy's avatar
Jim Blandy committed
305
if [ "${make_tar}" = yes ]; then
306 307 308 309 310 311 312 313 314 315 316 317 318
  if [ "${default_gzip}" = "" ]; then
    echo "Looking for gzip."
    temppath=`echo $PATH | sed 's/^:/.:/
				s/::/:.:/g
				s/:$/:./
				s/:/ /g'`
    default_gzip=`(
      for dir in ${temppath}; do
	if [ -f ${dir}/gzip ]; then echo 'gzip --best'; exit 0; fi
      done
      echo compress
    )`
  fi
319 320 321 322
  case "${default_gzip}" in
    compress* ) gzip_extension=.Z ;;
    * )         gzip_extension=.z ;;
  esac
Jim Blandy's avatar
Jim Blandy committed
323
  echo "Creating tar file."
324 325 326
  (cd ${tempparent} ; tar cvf - ${emacsname} ) \
    | ${default_gzip} \
    > ${emacsname}.tar${gzip_extension}
Jim Blandy's avatar
Jim Blandy committed
327
fi
Jim Blandy's avatar
Jim Blandy committed
328

Jim Blandy's avatar
Jim Blandy committed
329
if [ "${clean_up}" = yes ]; then
Jim Blandy's avatar
Jim Blandy committed
330
  echo "Cleaning up the staging directory."
331
  rm -rf ${tempparent}
Jim Blandy's avatar
Jim Blandy committed
332
fi
Eric S. Raymond's avatar
Eric S. Raymond committed
333

334
### make-dist ends here