]> code.delx.au - gnu-emacs/blob - mac/make-package
* make-package: Fix typo where tmpparent was used instead of
[gnu-emacs] / mac / make-package
1 #!/bin/sh
2
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.
20
21 # Copyright (C) 2002 Free Software Foundation, Inc.
22 #
23 # This file is part of GNU Emacs.
24 #
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.
29 #
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.
34 #
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.
39 #
40 # Contributed by Steven Tamm (steventamm@mac.com).
41
42 progname="$0"
43
44 srcdir="`pwd`/.."
45 builddir=..
46
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
59
60 ac_prev=
61 display_usage=false;
62 config_options=;
63 while test $# != 0
64 do
65 if test -n "$ac_prev"; then
66 eval "$ac_prev=\$1"
67 ac_prev=
68 continue
69 fi
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 | -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[^,]*,\(.*\)'`" ;;
98 *)
99 display_usage=yes ;;
100 esac
101 shift
102 done
103
104 if test "$with_x" = "no"; then
105 config_options="--without-x $config_options"
106 fi
107
108 if test "$display_usage" = "yes"; then
109 cat <<EOF
110 \`make-package' generates a Mac OS X installer package from an Emacs
111 distribution. By default, this first runs ./configure on the emacs
112 directory. Then make install to create the emacs distribution.
113 Then some mac-specific commands to generate the required information
114 for the mac package. The installer will, by default, create a
115 Carbon application called Emacs in the ${appsdir} directory, with the
116 shared emacs files in /usr/local
117
118 Usage: $0 [OPTION]
119
120 Options:
121 -h, --help display this help and exit
122 --prefix=DIR Set install location for the Mac OS X package
123 of the emacs related file. By default /usr/local
124 --no-conf Do not run the configure script before running
125 make install.
126 --without-app Do not create the Emacs application bundle
127 --with-x Setup the install to use X Windows for its
128 windowed display, instead of carbon. Implies
129 --without-app.
130 --without-full-dist Do not include all the .el files in the distribution.
131 This is discouraged except if disk space is critical.
132 --app-symlink Have the Emacs.app executable be a symlink
133 to the install in [prefix]/bin/emacs and have
134 the emacs executable link to emacs-${version}
135 --self-contained Create an Emacs.app that is self-contained;
136 prefix will be ignored and all files installed
137 inside the application
138 -C,option Pass option to configure
139 -M,option Pass option to make
140 EOF
141 exit 0
142 fi
143
144 ### Exit if a command fails.
145 #set -e
146
147 ### Print out each line we read, for debugging's sake.
148 #set -v
149
150 LANGUAGE=C
151 LC_ALL=C
152 LC_MESSAGES=
153 LANG=
154 export LANGUAGE LC_ALL LC_MESSAGES LANG
155
156 ## Don't restrict access to any files.
157 umask 0
158
159 ### Make sure we're running in the right place.
160 if [ -f Emacs.pkg ]; then
161 echo "${progname}: Package Emacs.pkg already exists.
162 Perhaps a previous invocation of \`${progname}' failed to clean up after
163 itself. Move or delete Emacs.pkg and try again." >&2
164 exit 1
165 fi
166
167 if test $with_app == "yes" && [ ! -f ${emapp}/Contents/PkgInfo ]; then
168 echo "${progname}: Can't find \`${emapp}/Contents/PkgInfo'" >&2
169 echo "${progname} must be run in the \`mac' directory of the Emacs" >&2
170 echo "distribution tree. cd to that directory and try again." >&2
171 exit 1
172 fi
173
174 ### Check whether file ../lisp/version.el exists.
175 if [ ! -f ../lisp/version.el ]; then
176 echo "${progname}: Can't find \`../lisp/version.el'" >&2
177 exit 1
178 fi
179
180 ### Find out which version of Emacs this is.
181 shortversion=`grep 'defconst[ ]*emacs-version' ../lisp/version.el \
182 | sed -e 's/^.*"\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/'`
183 version=`grep 'defconst[ ]*emacs-version' ../lisp/version.el \
184 | sed -e 's/^[^"]*"\([^"]*\)".*$/\1/'`
185 if [ ! "${version}" ]; then
186 echo "${progname}: can't find current Emacs version in \`./lisp/version.el'" >&2
187 exit 1
188 fi
189
190 echo Version numbers are $version and $shortversion
191
192 ### Make sure we don't already have a directory emacs-${version}.
193
194 emacsname="emacs-${version}${new_extension}"
195
196 if [ -d ${emacsname} ]
197 then
198 echo Directory "${emacsname}" already exists >&2
199 exit 1
200 fi
201
202 ### Make sure the subdirectory is available.
203 tempparent="make-package.tmp.$$"
204 if [ -d ${tempparent} ]; then
205 echo "${progname}: staging directory \`${tempparent}' already exists.
206 Perhaps a previous invocation of \`${progname}' failed to clean up after
207 itself. Check that directories whose names are of the form
208 \`make-dist.tmp.NNNNN' don't contain any important information, remove
209 them, and try again." >&2
210 exit 1
211 fi
212
213 if [ -d /Volumes/Emacs ]; then
214 echo "${progname}: Already have an Emacs disc image mounted. Please
215 eject that disc image and try again." >&2
216 exit 1
217 fi
218
219 tempparentfull="`pwd`/${tempparent}"
220 tempparentdist=${tempparentfull}/dist
221
222 echo Installing into directory ${tempparentfull} >&2
223
224 # Run configure in the new tempparent directory
225 if test "$with_config" = "yes"; then
226 (cd ..; ./configure ${config_options} --prefix=${prefix})
227 fi
228
229 installprefix=${tempparentfull}${prefix}
230 if test "$self_contained" = "yes"; then
231 # If selfcontained, the local directory is Resources directory
232 installprefix=$tempparentfull/$appsdir/$emapp/Contents/Resources
233 fi
234
235 ### This trap ensures that the staging directory will be cleaned up even
236 ### when the script is interrupted in mid-career.
237 trap "echo 'Interrupted...cleaning up the staging directory'; rm -rf ${tempparent}; rm -rf Emacs.pkg; exit 1" 1 2 15
238
239 ## Make bootstrap if .elc files are missing from distribution
240 if [ ! -f ../lisp/abbrev.elc ]; then
241 echo "Required .elc files missing; making bootstrap..."
242 if ! (cd ${builddir}; make bootstrap prefix=$installprefix $make_options); then
243 echo "Make bootstrap failed... Aborting make-package."
244 exit 2
245 fi
246 fi
247
248 if ! (cd ${builddir}; make install prefix=$installprefix $make_options); then
249 echo "Make failed... Aborting make-package."
250 exit 1
251 fi
252
253 if test "$full_dist" == "no"; then
254 echo "Removing unneeded .el files"
255 sharedir=$installprefix/share/emacs/$version
256 find $sharedir/lisp $sharedir/leim -name "*.elc" -print | sed 's|\(.*\)\.elc$|/bin/rm -f \1.el|' | /bin/sh -s
257 fi
258
259 if test "$with_app" == "yes"; then
260 echo "Creating Emacs.app application"
261 tempappdir=${tempparentfull}${appsdir}
262 tempemapp=${tempappdir}/${emapp}/Contents/MacOS/Emacs
263 mkdir ${tempappdir}
264
265 ## Copy Emacs application
266 cp -r Emacs.app ${tempappdir}
267 ## Delete any CVS files
268 find ${tempappdir} -name "CVS" -type d -exec rm -rf {} \;
269
270 ## Have application be a symlink to ${prefix}/bin/emacs
271 if test "$app_symlink" == "yes"; then
272 echo "Creating application symlink"
273 rm ${tempemapp}
274 ln -s ${prefix}/bin/${emacsname} ${tempemapp}
275 fi
276 fi
277
278 if test "$self_contained" = "yes"; then
279 # Move shared files down to Resources directory
280 mv $installprefix/share/emacs/$version/* $installprefix
281 rm -rf $installprefix/share
282 # These directories might remain in Resources
283 mv $installprefix/bin $installprefix/../MacOS/bin
284 mv $installprefix/libexec $installprefix/../MacOS/libexec
285 # Make the application binary a hard link
286 rm $installprefix/../MacOS/Emacs
287 ln $installprefix/../MacOS/bin/emacs $installprefix/../MacOS/Emacs
288 fi
289
290
291 # Remove unnecessary .el files
292 #if test "$full_dist" = no; then
293 #fi
294
295 echo "Creating Package Info file"
296
297 mkdir Emacs.pkg
298 mkdir Emacs.pkg/Contents
299 mkdir Emacs.pkg/Contents/Resources
300 mkdir Emacs.pkg/Contents/Resources/English.lproj
301 echo 'pmkrpkg1' > Emacs.pkg/Contents/PkgInfo
302
303 infofile=Emacs.pkg/Contents/Resources/English.lproj/Emacs.info
304
305 echo 'Title Emacs' > ${infofile}
306 echo "Version ${version}" >> ${infofile}
307 echo "Description Install GNU Emacs ${version} as a command-line app and a Mac OS Application" >> ${infofile}
308 echo 'DefaultLocation /' >> ${infofile}
309 echo 'DeleteWarning' >> ${infofile}
310 echo 'NeedsAuthorization YES' >> ${infofile}
311 echo 'Required NO' >> ${infofile}
312 echo 'Relocatable NO' >> ${infofile}
313 echo 'RequiresReboot NO' >> ${infofile}
314 echo 'UseUserMask NO' >> ${infofile}
315 echo 'OverwritePermissions NO' >> ${infofile}
316 echo 'InstallFat NO' >> ${infofile}
317
318 ### Set the install directory to install files as root...
319 ### Not sure if this is a good diea
320 # echo "Setting owner to root"
321 # chown -Rh 0 ${tempparentfull}
322
323 echo "Creating pax file"
324 (cd ${tempparentfull}; pax -w -f ../Emacs.pkg/Contents/Resources/Emacs.pax .; cd ..)
325 echo "Compressing pax file"
326 gzip Emacs.pkg/Contents/Resources/Emacs.pax
327
328 echo "Creating bom file"
329 mkbom ${tempparentfull} Emacs.pkg/Contents/Resources/Emacs.bom
330
331 echo "Generating sizes file"
332 sizesfile=Emacs.pkg/Contents/Resources/Emacs.sizes
333
334 numFiles=`du -a ${tempparent} | wc -l`
335 installedSize=`du -s ${tempparent} | cut -f1`
336 compressedSize=`du -s Emacs.pkg | cut -f1`
337
338 echo "NumFiles ${numFiles}" > ${sizesfile}
339 echo "InstalledSize ${installedSize}" >> ${sizesfile}
340 echo "CompressedSize ${compressedSize}" >> ${sizesfile}
341 cat ${sizesfile}
342
343 mv ${tempparentfull} ${emacsname}
344
345 echo "Creating Disc Image"
346 ## Allocate an extra 5000 sectors (about 2.5 mg)
347 ## Note a sector appears to be ~500k
348 sectorsAlloced=`echo 2*${compressedSize}+5000|bc`
349 hdiutil create -ov EmacsRW -sectors ${sectorsAlloced}
350 ## Need to format the disc image before mounting
351 mountLoc=`hdid -nomount EmacsRW.dmg | grep HFS | cut -f1`
352 /sbin/newfs_hfs -v Emacs ${mountLoc}
353 hdiutil eject ${mountLoc}
354 echo "Copying Package to Disc Image"
355 hdid EmacsRW.dmg
356
357 if test "$keep_directory" = "no"; then
358 rm -rf ${emacsname}
359 fi
360
361 if [ ! -d /Volumes/Emacs ]; then
362 echo "Could not create disc image. The Emacs installer package (Emacs.pkg)
363 in this directory should be correct. Please use the Disc Copy program to
364 create a disc image." >&2
365 exit 0
366 fi
367
368 cp -R Emacs.pkg /Volumes/Emacs
369
370 ## Converting Disk Image to read-only
371 echo 'Converting Disc Image to read-only'
372 hdiutil eject ${mountLoc}
373 hdiutil resize EmacsRW.dmg -sectors min
374 if test "$comp_diskimage" = "yes"; then
375 hdiutil convert EmacsRW.dmg -format UDZO -imagekey zlib-level=2 -o EmacsInstaller.dmg
376 else
377 hdiutil convert EmacsRW.dmg -format UDRO -o EmacsInstaller.dmg
378 fi
379 rm EmacsRW.dmg
380
381 echo "Cleaning up the staging directory"
382 rm -rf Emacs.pkg
383
384 ### make-package ends here