]> code.delx.au - gnu-emacs/blob - mac/make-package
make-package: Now calls make bootstrap if .elc files are missing
[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 ## Default location to place it is /usr/local
44
45 prefix=/usr/local
46 with_config=yes
47
48 ac_prev=
49 display_usage=false;
50 config_options=--without-x
51 while test $# != 0
52 do
53 if test -n "$ac_prev"; then
54 eval "$ac_prev=\$1"
55 ac_prev=
56 continue
57 fi
58 case $1 in
59 -help | --help | --hel | --he | -h)
60 display_usage=yes ;;
61 -p | -prefix | --p | --prefix)
62 ac_prev=prefix ;;
63 -p=* | -prefix=* | --p=* | --prefix=*)
64 prefix=`expr "x$1" : 'x[^=]*=\(.*\)'` ;;
65 -no-configure | -no-conf | --no-configure | --no-conf | --without-config)
66 with_config=no ;;
67 -with-x | --with-x)
68 config_options= ;;
69 esac
70 shift
71 done
72
73 if test "$display_usage" = "yes"; then
74 cat <<EOF
75 \`make-package' generates a Mac OS X package from an Emacs distribution.
76 By default, this first runs ./configure on the emacs directory. Then
77 make install to create the emacs distribution. Then some mac-specific
78 commands to generate the required information for the mac package.
79
80 Usage: $0 [OPTION]
81
82 Options:
83 -h, --help display this help and exit
84 --prefix=DIR Set install location for the Mac OS X package
85 of the emacs related file. By default /usr/local
86 --no-conf Do not run the configure script before running
87 make install.
88 --with-x Setup the install to use X Windows for its
89 windowed display, instead of carbon.
90 EOF
91 exit 0
92 fi
93
94 ### Exit if a command fails.
95 #set -e
96
97 ### Print out each line we read, for debugging's sake.
98 set -v
99
100 LANGUAGE=C
101 LC_ALL=C
102 LC_MESSAGES=
103 LANG=
104 export LANGUAGE LC_ALL LC_MESSAGES LANG
105
106 ## Don't restrict access to any files.
107 umask 0
108
109 ### Make sure we're running in the right place.
110 if [ -f Emacs.pkg ]; then
111 echo "${progname}: Package Emacs.pkg already exists.
112 Perhaps a previous invocation of \`${progname}' failed to clean up after
113 itself. Move or delete Emacs.pkg and try again." >&2
114 exit 1
115 fi
116
117 if [ ! -f Emacs.app/Contents/PkgInfo ]; then
118 echo "${progname}: Can't find \`Emacs.app/Contents/PkgInfo'" >&2
119 echo "${progname} must be run in the \`mac' directory of the Emacs" >&2
120 echo "distribution tree. cd to that directory and try again." >&2
121 exit 1
122 fi
123
124 ### Check whether file ../lisp/version.el exists.
125 if [ ! -f ../lisp/version.el ]; then
126 echo "${progname}: Can't find \`../lisp/version.el'" >&2
127 exit 1
128 fi
129
130 ### Find out which version of Emacs this is.
131 shortversion=`grep 'defconst[ ]*emacs-version' ../lisp/version.el \
132 | sed -e 's/^.*"\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/'`
133 version=`grep 'defconst[ ]*emacs-version' ../lisp/version.el \
134 | sed -e 's/^[^"]*"\([^"]*\)".*$/\1/'`
135 if [ ! "${version}" ]; then
136 echo "${progname}: can't find current Emacs version in \`./lisp/version.el'" >&2
137 exit 1
138 fi
139
140 echo Version numbers are $version and $shortversion
141
142 ### Make sure we don't already have a directory emacs-${version}.
143
144 emacsname="emacs-${version}${new_extension}"
145
146 if [ -d ${emacsname} ]
147 then
148 echo Directory "${emacsname}" already exists >&2
149 exit 1
150 fi
151
152 ### Make sure the subdirectory is available.
153 tempparent="make-package.tmp.$$"
154 if [ -d ${tempparent} ]; then
155 echo "${progname}: staging directory \`${tempparent}' already exists.
156 Perhaps a previous invocation of \`${progname}' failed to clean up after
157 itself. Check that directories whose names are of the form
158 \`make-dist.tmp.NNNNN' don't contain any important information, remove
159 them, and try again." >&2
160 exit 1
161 fi
162
163 if [ -d /Volumes/Emacs ]; then
164 echo "${progname}: Already have an Emacs disc image mounted. Please
165 eject that disc image and try again." >&2
166 exit 1
167 fi
168
169 tempparentfull="`pwd`/${tempparent}"
170
171 echo Installing into directory ${tempparentfull} >&2
172
173 if test "$with_config" = yes; then
174 (cd ..; ./configure ${config_options} --prefix=${prefix};)
175 fi
176
177 ## Make bootstrap if .elc files are missing from distribution
178 if [ ! -f ../lisp/abbrev.elc ]; then
179 echo "Required .elc files missing; making bootstrap..."
180 if ! (cd ..; make bootstrap prefix=${tempparentfull}${prefix}); then
181 echo "Make bootstrap failed... Aborting make-package."
182 exit 2
183 fi
184 fi
185
186 if ! (cd ..; make install prefix=${tempparentfull}${prefix}); then
187 echo "Make failed... Aborting make-package."
188 exit 1
189 fi
190
191 ### This trap ensures that the staging directory will be cleaned up even
192 ### when the script is interrupted in mid-career.
193 trap "echo 'Interrupted...cleaning up the staging directory'; rm -rf ${tempparent}; rm -rf Emacs.pkg; exit 1" 1 2 15
194
195 mkdir ${tempparentfull}/Applications
196
197 cp -r Emacs.app ${tempparentfull}/Applications
198
199 echo "Creating Package Info file"
200
201 mkdir Emacs.pkg
202 mkdir Emacs.pkg/Contents
203 mkdir Emacs.pkg/Contents/Resources
204 mkdir Emacs.pkg/Contents/Resources/English.lproj
205 echo 'pmkrpkg1' > Emacs.pkg/Contents/PkgInfo
206
207 infofile=Emacs.pkg/Contents/Resources/English.lproj/Emacs.info
208
209 echo 'Title Emacs' > ${infofile}
210 echo "Version ${version}" >> ${infofile}
211 echo "Description Install GNU Emacs ${version} as a command-line app and a Mac OS Application" >> ${infofile}
212 echo 'DefaultLocation /' >> ${infofile}
213 echo 'DeleteWarning' >> ${infofile}
214 echo 'NeedsAuthorization YES' >> ${infofile}
215 echo 'Required NO' >> ${infofile}
216 echo 'Relocatable NO' >> ${infofile}
217 echo 'RequiresReboot NO' >> ${infofile}
218 echo 'UseUserMask NO' >> ${infofile}
219 echo 'OverwritePermissions NO' >> ${infofile}
220 echo 'InstallFat NO' >> ${infofile}
221
222 echo "Creating pax file"
223 (cd ${tempparentfull}; pax -w -f ../Emacs.pkg/Contents/Resources/Emacs.pax .; cd ..)
224 #echo "Compressing pax file"
225 #gzip Emacs.pkg/Contents/Resources/Emacs.pax
226
227 echo "Creating bom file"
228 mkbom ${tempparentfull} Emacs.pkg/Contents/Resources/Emacs.bom
229
230 echo "Generating sizes file"
231 sizesfile=Emacs.pkg/Contents/Resources/Emacs.sizes
232
233 numFiles=`du -a ${tmpparent} | wc -l`
234 installedSize=`du -s ${tmpparent} | cut -f1`
235 compressedSize=`du -s Emacs.pkg | cut -f1`
236
237 echo "NumFiles ${numFiles}" > ${sizesfile}
238 echo "InstalledSize ${installedSize}" >> ${sizesfile}
239 echo "CompressedSize ${compressedSize}" >> ${sizesfile}
240 cat ${sizesfile}
241
242 mv ${tempparentfull} ${emacsname}
243
244 echo "Creating Disc Image"
245 ## Allocate an extra 5000 sectors (about 2.5 mg)
246 ## Note a sector appears to be ~500k
247 sectorsAlloced=`echo 2*${compressedSize}+5000|bc`
248 hdiutil create -ov EmacsRW -sectors ${sectorsAlloced}
249 ## Need to format the disc image before mounting
250 mountLoc=`hdid -nomount EmacsRW.dmg | grep HFS | cut -f1`
251 /sbin/newfs_hfs -v Emacs ${mountLoc}
252 hdiutil eject ${mountLoc}
253 echo "Copying Package to Disc Image"
254 hdid EmacsRW.dmg
255
256 rm -rf ${emacsname}
257
258 if [ ! -d /Volumes/Emacs ]; then
259 echo "Could not create disc image. The Emacs installer package in this
260 directory should be correct. Please use the Disc Copy program to create
261 a disc image." >&2
262 exit 0
263 fi
264
265 cp -R Emacs.pkg /Volumes/Emacs
266
267 ## Converting Disk Image to read-only
268 echo 'Converting Disc Image to read-only'
269 hdiutil eject ${mountLoc}
270 hdiutil resize EmacsRW.dmg -sectors min
271 hdiutil convert EmacsRW.dmg -format UDRO -o EmacsInstaller.dmg
272 gzip EmacsInstaller.dmg
273 rm EmacsRW.dmg
274
275 echo "Cleaning up the staging directory"
276 rm -rf Emacs.pkg
277
278 ### make-package ends here