(finder-compile-keywords): Don't insert a keyword to the generated
[emacs.git] / mac / make-package
blob7b5c189934a3bdf5894209702a56c75cc73ca49c
1 #!/bin/sh
3 #### make-package: create a Mac OS X package for use by the installer.
4 #### The installer will place the Emacs OSX application in
5 #### /Application/Emacs and the rest of emacs in the usual unix places
6 #### under /usr/local or some other location if specified as the first
7 #### argument. The disc image will be in the file EmacsInstaller.dmg.
8 ####
9 #### Upon installation, this will leave two versions of emacs on the
10 #### computer, 20.7 and 21.1.
11 ####
12 #### Examples:
13 #### ./make-package
14 #### Will create an installer that will place the emacs support
15 #### files inside /usr/local.
16 #### ./make-package /usr
17 #### Will create an installer that will place the emacs support
18 #### files inside /usr. This will replace the default version of
19 #### emacs included with Mac OS X.
21 # Copyright (C) 2002 Free Software Foundation, Inc.
23 # This file is part of GNU Emacs.
25 # GNU Emacs is free software; you can redistribute it and/or modify
26 # it under the terms of the GNU General Public License as published by
27 # the Free Software Foundation; either version 2, or (at your option)
28 # any later version.
30 # GNU Emacs is distributed in the hope that it will be useful,
31 # but WITHOUT ANY WARRANTY; without even the implied warranty of
32 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 # GNU General Public License for more details.
35 # You should have received a copy of the GNU General Public License
36 # along with GNU Emacs; see the file COPYING. If not, write to the
37 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
38 # Boston, MA 02111-1307, USA.
40 # Contributed by Steven Tamm (steventamm@mac.com).
42 progname="$0"
44 srcdir="`pwd`/.."
45 builddir=..
47 ## Default location to place it is /usr/local
48 prefix=/usr/local
49 appsdir=/Applications
50 emapp=Emacs.app
51 with_config=yes
52 with_app=yes
53 with_x=no
54 comp_diskimage=yes
55 self_contained=no
56 app_symlink=no
57 full_dist=yes
58 keep_directory=no
60 ac_prev=
61 display_usage=false;
62 config_options=;
63 while test $# != 0
65 if test -n "$ac_prev"; then
66 eval "$ac_prev=\$1"
67 ac_prev=
68 continue
70 case $1 in
71 -help | --help | --hel | --he | -h)
72 display_usage=yes ;;
73 -p | -prefix | --p | --prefix)
74 ac_prev=prefix ;;
75 -p=* | -prefix=* | --p=* | --prefix=*)
76 prefix=`expr "x$1" : 'x[^=]*=\(.*\)'` ;;
77 -no-configure | -no-conf | --no-configure | --no-conf | --without-config)
78 with_config=no ;;
79 -no-app | --no-app | -without-app | --without-app)
80 with_app=no ;;
81 -without-x | --without-x)
82 with_x=no ;;
83 -with-x | --with-x)
84 with_x=yes
85 with_app=no ;;
86 --without-full-dist | -without-full-dist | -no-full-dist | -no-full)
87 full_dist=no ;;
88 -self-contained | --with-self-contained-app | -sc)
89 self_contained=yes ;;
90 -app-symlink | --app-symlink | -symlink | --symlink | --asl)
91 app_symlink=yes ;;
92 --keep-dir)
93 keep_directory=yes ;;
94 -C,* | -c,*)
95 config_options="$config_options `expr "x$1" : 'x[^,]*,\(.*\)'`" ;;
96 -M,* | -m,*)
97 make_options="$make_options `expr "x$1" : 'x[^,]*,\(.*\)'`" ;;
99 esac
100 shift
101 done
103 if test "$with_x" = "no"; then
104 config_options="--without-x $config_options"
107 if test "$display_usage" = "yes"; then
108 cat <<EOF
109 \`make-package' generates a Mac OS X installer package from an Emacs
110 distribution. By default, this first runs ./configure on the emacs
111 directory. Then make install to create the emacs distribution.
112 Then some mac-specific commands to generate the required information
113 for the mac package. The installer will, by default, create a
114 Carbon application called Emacs in the ${appsdir} directory, with the
115 shared emacs files in /usr/local
117 Usage: $0 [OPTION]
119 Options:
120 -h, --help display this help and exit
121 --prefix=DIR Set install location for the Mac OS X package
122 of the emacs related file. By default /usr/local
123 --no-conf Do not run the configure script before running
124 make install.
125 --without-app Do not create the Emacs application bundle
126 --with-x Setup the install to use X Windows for its
127 windowed display, instead of carbon. Implies
128 --without-app.
129 --without-full-dist Do not include all the .el files in the distribution.
130 This is discouraged except if disk space is critical.
131 --app-symlink Have the Emacs.app executable be a symlink
132 to the install in [prefix]/bin/emacs and have
133 the emacs executable link to emacs-${version}
134 --self-contained Create an Emacs.app that is self-contained;
135 prefix will be ignored and all files installed
136 inside the application
137 -C,option Pass option to configure
138 -M,option Pass option to make
140 exit 0
143 ### Exit if a command fails.
144 #set -e
146 ### Print out each line we read, for debugging's sake.
147 #set -v
149 LANGUAGE=C
150 LC_ALL=C
151 LC_MESSAGES=
152 LANG=
153 export LANGUAGE LC_ALL LC_MESSAGES LANG
155 ## Don't restrict access to any files.
156 umask 0
158 ### Make sure we're running in the right place.
159 if [ -f Emacs.pkg ]; then
160 echo "${progname}: Package Emacs.pkg already exists.
161 Perhaps a previous invocation of \`${progname}' failed to clean up after
162 itself. Move or delete Emacs.pkg and try again." >&2
163 exit 1
166 if test $with_app == "yes" && [ ! -f ${emapp}/Contents/PkgInfo ]; then
167 echo "${progname}: Can't find \`${emapp}/Contents/PkgInfo'" >&2
168 echo "${progname} must be run in the \`mac' directory of the Emacs" >&2
169 echo "distribution tree. cd to that directory and try again." >&2
170 exit 1
173 ### Check whether file ../lisp/version.el exists.
174 if [ ! -f ../lisp/version.el ]; then
175 echo "${progname}: Can't find \`../lisp/version.el'" >&2
176 exit 1
179 ### Find out which version of Emacs this is.
180 shortversion=`grep 'defconst[ ]*emacs-version' ../lisp/version.el \
181 | sed -e 's/^.*"\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/'`
182 version=`grep 'defconst[ ]*emacs-version' ../lisp/version.el \
183 | sed -e 's/^[^"]*"\([^"]*\)".*$/\1/'`
184 if [ ! "${version}" ]; then
185 echo "${progname}: can't find current Emacs version in \`./lisp/version.el'" >&2
186 exit 1
189 echo Version numbers are $version and $shortversion
191 ### Make sure we don't already have a directory emacs-${version}.
193 emacsname="emacs-${version}${new_extension}"
195 if [ -d ${emacsname} ]
196 then
197 echo Directory "${emacsname}" already exists >&2
198 exit 1
201 ### Make sure the subdirectory is available.
202 tempparent="make-package.tmp.$$"
203 if [ -d ${tempparent} ]; then
204 echo "${progname}: staging directory \`${tempparent}' already exists.
205 Perhaps a previous invocation of \`${progname}' failed to clean up after
206 itself. Check that directories whose names are of the form
207 \`make-dist.tmp.NNNNN' don't contain any important information, remove
208 them, and try again." >&2
209 exit 1
212 if [ -d /Volumes/Emacs ]; then
213 echo "${progname}: Already have an Emacs disc image mounted. Please
214 eject that disc image and try again." >&2
215 exit 1
218 tempparentfull="`pwd`/${tempparent}"
219 tempparentdist=${tempparentfull}/dist
221 echo Installing into directory ${tempparentfull} >&2
223 # Run configure in the new tempparent directory
224 if test "$with_config" = "yes"; then
225 (cd ..; ./configure ${config_options} --prefix=${prefix})
228 installprefix=${tempparentfull}${prefix}
229 if test "$self_contained" = "yes"; then
230 # If selfcontained, the local directory is Resources directory
231 installprefix=$tempparentfull/$appsdir/$emapp/Contents/Resources
234 ### This trap ensures that the staging directory will be cleaned up even
235 ### when the script is interrupted in mid-career.
236 trap "echo 'Interrupted...cleaning up the staging directory'; rm -rf ${tempparent}; rm -rf Emacs.pkg; exit 1" 1 2 15
238 ## Make bootstrap if .elc files are missing from distribution
239 if [ ! -f ../lisp/abbrev.elc ]; then
240 echo "Required .elc files missing; making bootstrap..."
241 if ! (cd ${builddir}; make bootstrap prefix=$installprefix $make_options); then
242 echo "Make bootstrap failed... Aborting make-package."
243 exit 2
247 if ! (cd ${builddir}; make install prefix=$installprefix $make_options); then
248 echo "Make failed... Aborting make-package."
249 exit 1
252 if test "$full_dist" == "no"; then
253 echo "Removing unneeded .el files"
254 sharedir=$installprefix/share/emacs/$version
255 find $sharedir/lisp $sharedir/leim -name "*.elc" -print | sed 's|\(.*\)\.elc$|/bin/rm -f \1.el|' | /bin/sh -s
258 if test "$with_app" == "yes"; then
259 echo "Creating Emacs.app application"
260 tempappdir=${tempparentfull}${appsdir}
261 mkdir ${tempappdir}
263 ## Copy Emacs application
264 cp -r Emacs.app ${tempappdir}
265 ## Delete any CVS files
266 find ${tempappdir} -name "CVS" -type d -execdir rm -rf {} \;
267 ## Have application be a symlink to ${prefix}/bin/emacs
268 if test "$app_symlink" == "yes"; then
269 echo "Creating application symlink"
270 tempemapp=${tempappdir}/${emapp}/Contents/MacOS/Emacs
271 rm ${tempemapp}
272 if test "$self_contained" = "yes"; then
273 ln -s ../../Contents/Resources/bin/${emacsname} ${tempemapp}
274 else
275 ln -s ${prefix}/bin/${emacsname} ${tempemapp}
280 # Remove unnecessary .el files
281 #if test "$full_dist" = no; then
284 echo "Creating Package Info file"
286 mkdir Emacs.pkg
287 mkdir Emacs.pkg/Contents
288 mkdir Emacs.pkg/Contents/Resources
289 mkdir Emacs.pkg/Contents/Resources/English.lproj
290 echo 'pmkrpkg1' > Emacs.pkg/Contents/PkgInfo
292 infofile=Emacs.pkg/Contents/Resources/English.lproj/Emacs.info
294 echo 'Title Emacs' > ${infofile}
295 echo "Version ${version}" >> ${infofile}
296 echo "Description Install GNU Emacs ${version} as a command-line app and a Mac OS Application" >> ${infofile}
297 echo 'DefaultLocation /' >> ${infofile}
298 echo 'DeleteWarning' >> ${infofile}
299 echo 'NeedsAuthorization YES' >> ${infofile}
300 echo 'Required NO' >> ${infofile}
301 echo 'Relocatable NO' >> ${infofile}
302 echo 'RequiresReboot NO' >> ${infofile}
303 echo 'UseUserMask NO' >> ${infofile}
304 echo 'OverwritePermissions NO' >> ${infofile}
305 echo 'InstallFat NO' >> ${infofile}
307 ### Set the install directory to install files as root...
308 ### Not sure if this is a good diea
309 # echo "Setting owner to root"
310 # chown -Rh 0 ${tempparentfull}
312 echo "Creating pax file"
313 (cd ${tempparentfull}; pax -w -f ../Emacs.pkg/Contents/Resources/Emacs.pax .; cd ..)
314 echo "Compressing pax file"
315 gzip Emacs.pkg/Contents/Resources/Emacs.pax
317 echo "Creating bom file"
318 mkbom ${tempparentfull} Emacs.pkg/Contents/Resources/Emacs.bom
320 echo "Generating sizes file"
321 sizesfile=Emacs.pkg/Contents/Resources/Emacs.sizes
323 numFiles=`du -a ${tmpparent} | wc -l`
324 installedSize=`du -s ${tmpparent} | cut -f1`
325 compressedSize=`du -s Emacs.pkg | cut -f1`
327 echo "NumFiles ${numFiles}" > ${sizesfile}
328 echo "InstalledSize ${installedSize}" >> ${sizesfile}
329 echo "CompressedSize ${compressedSize}" >> ${sizesfile}
330 cat ${sizesfile}
332 mv ${tempparentfull} ${emacsname}
334 echo "Creating Disc Image"
335 ## Allocate an extra 5000 sectors (about 2.5 mg)
336 ## Note a sector appears to be ~500k
337 sectorsAlloced=`echo 2*${compressedSize}+5000|bc`
338 hdiutil create -ov EmacsRW -sectors ${sectorsAlloced}
339 ## Need to format the disc image before mounting
340 mountLoc=`hdid -nomount EmacsRW.dmg | grep HFS | cut -f1`
341 /sbin/newfs_hfs -v Emacs ${mountLoc}
342 hdiutil eject ${mountLoc}
343 echo "Copying Package to Disc Image"
344 hdid EmacsRW.dmg
346 if test "$keep_directory" = "no"; then
347 rm -rf ${emacsname}
350 if [ ! -d /Volumes/Emacs ]; then
351 echo "Could not create disc image. The Emacs installer package (Emacs.pkg)
352 in this directory should be correct. Please use the Disc Copy program to
353 create a disc image." >&2
354 exit 0
357 cp -R Emacs.pkg /Volumes/Emacs
359 ## Converting Disk Image to read-only
360 echo 'Converting Disc Image to read-only'
361 hdiutil eject ${mountLoc}
362 hdiutil resize EmacsRW.dmg -sectors min
363 if test "$comp_diskimage" = "yes"; then
364 hdiutil convert EmacsRW.dmg -format UDZO -imagekey zlib-level=2 -o EmacsInstaller.dmg
365 else
366 hdiutil convert EmacsRW.dmg -format UDRO -o EmacsInstaller.dmg
368 rm EmacsRW.dmg
370 echo "Cleaning up the staging directory"
371 rm -rf Emacs.pkg
373 ### make-package ends here