(chinese-calendar-time-zone, chinese-calendar-daylight-time-offset)
[emacs.git] / mac / make-package
bloba37081e8b3f60b53966359c6534a7730e600f84f
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, 2003, 2004, 2005, 2006, 2007, 2008
22 # Free Software Foundation, Inc.
24 # This file is part of GNU Emacs.
26 # GNU Emacs is free software; you can redistribute it and/or modify
27 # it under the terms of the GNU General Public License as published by
28 # the Free Software Foundation; either version 3, or (at your option)
29 # any later version.
31 # GNU Emacs is distributed in the hope that it will be useful,
32 # but WITHOUT ANY WARRANTY; without even the implied warranty of
33 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 # GNU General Public License for more details.
36 # You should have received a copy of the GNU General Public License
37 # along with GNU Emacs; see the file COPYING. If not, write to the
38 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
39 # Boston, MA 02110-1301, USA.
41 # Contributed by Steven Tamm (steventamm@mac.com).
43 progname="$0"
45 srcdir="`pwd`/.."
46 builddir=${srcdir}
48 ## Default location to place it is /usr/local
49 prefix=/usr/local
50 appsdir=/Applications
51 emapp=Emacs.app
52 with_config=yes
53 with_app=yes
54 with_x=no
55 comp_diskimage=no
56 self_contained=no
57 app_symlink=no
58 full_dist=yes
59 compressed_dist=no
60 build_in_place=no
61 keep_directory=no
63 ac_prev=
64 display_usage=false;
65 config_options=;
66 while test $# != 0
68 if test -n "$ac_prev"; then
69 eval "$ac_prev=\$1"
70 ac_prev=
71 continue
73 case $1 in
74 -help | --help | --hel | --he | -h)
75 display_usage=yes ;;
76 -p | -prefix | --p | --prefix)
77 ac_prev=prefix ;;
78 -p=* | -prefix=* | --p=* | --prefix=*)
79 prefix=`expr "x$1" : 'x[^=]*=\(.*\)'` ;;
80 --build-in-place | --build-in-place )
81 build_in_place=yes ;;
82 --build-dir | -build-dir | --builddir | -build-dir)
83 build_in_place=no
84 ac_prev=builddir;;
85 --build-dir=* | -build-dir=* | -builddir=* | --builddir=*)
86 build_in_place=no
87 builddir=`expr "x$1" : 'x[^=]*=\(.*\)'`;;
88 -no-configure | -no-conf | --no-configure | --no-conf | --without-config)
89 with_config=no ;;
90 -no-app | --no-app | -without-app | --without-app)
91 with_app=no ;;
92 -without-x | --without-x)
93 with_x=no ;;
94 -with-x | --with-x)
95 with_x=yes
96 with_app=no ;;
97 --without-full-dist | -without-full-dist | -no-full-dist | -no-full)
98 full_dist=no ;;
99 --compressed-dist)
100 compressed_dist=yes ;;
101 --self-contained | -self-contained | --with-self-contained-app | -sc)
102 self_contained=yes ;;
103 -app-symlink | --app-symlink | -symlink | --symlink | --asl)
104 app_symlink=yes ;;
105 --keep-dir)
106 keep_directory=yes ;;
107 -C,* | -c,*)
108 config_options="$config_options `expr "x$1" : 'x[^,]*,\(.*\)'`" ;;
109 -M,* | -m,*)
110 make_options="$make_options `expr "x$1" : 'x[^,]*,\(.*\)'`" ;;
112 display_usage=yes ;;
113 esac
114 shift
115 done
117 if test "$with_x" = "no"; then
118 config_options="--without-x $config_options"
121 if test "$display_usage" = "yes"; then
122 cat <<EOF
123 \`make-package' generates a Mac OS X installer package from an Emacs
124 distribution. By default, this first runs ./configure on the emacs
125 directory. Then make install to create the emacs distribution.
126 Then some mac-specific commands to generate the required information
127 for the mac package. The installer will, by default, create a
128 Carbon application called Emacs in the ${appsdir} directory, with the
129 shared emacs files in /usr/local
131 Usage: $0 [OPTION]
133 Options:
134 -h, --help display this help and exit
135 --prefix=DIR Set install location for the Mac OS X package
136 of the emacs related file. By default /usr/local
137 --no-conf Do not run the configure script before running
138 make install.
139 --without-app Do not create the Emacs application bundle
140 --with-x Setup the install to use X Windows for its
141 windowed display, instead of carbon. Implies
142 --without-app.
143 --without-full-dist Do not include all the .el files in the distribution.
144 This is discouraged except if disk space is critical.
145 --compressed-dist Compress .el and info files in the distribution.
146 --app-symlink Have the Emacs.app executable be a symlink
147 to the install in [prefix]/bin/emacs and have
148 the emacs executable link to emacs-${version}
149 --self-contained Create an Emacs.app that is self-contained;
150 prefix will be ignored and all files installed
151 inside the application
152 --build-in-place Build the application in the source directory
153 instead of a temporary directory.
154 --build-dir=DIR Build the application in the specified directory
155 instead of a temporary directory. Mutually exclusive
156 with --build-in-place.
157 -C,option Pass option to configure
158 -M,option Pass option to make
160 exit 0
163 ### Exit if a command fails.
164 #set -e
166 ### Print out each line we read, for debugging's sake.
167 #set -v
169 LANGUAGE=C
170 LC_ALL=C
171 LC_MESSAGES=
172 LANG=
173 export LANGUAGE LC_ALL LC_MESSAGES LANG
175 ## Don't restrict access to any files.
176 umask 0
178 ### Make sure we're running in the right place.
179 if [ -f Emacs.pkg ]; then
180 echo "${progname}: Package Emacs.pkg already exists.
181 Perhaps a previous invocation of \`${progname}' failed to clean up after
182 itself. Move or delete Emacs.pkg and try again." >&2
183 exit 1
186 if test $with_app == "yes" && [ ! -f ${emapp}/Contents/PkgInfo ]; then
187 echo "${progname}: Can't find \`${emapp}/Contents/PkgInfo'" >&2
188 echo "${progname} must be run in the \`mac' directory of the Emacs" >&2
189 echo "distribution tree. cd to that directory and try again." >&2
190 exit 1
193 ### Check whether file ../lisp/version.el exists.
194 if [ ! -f ../lisp/version.el ]; then
195 echo "${progname}: Can't find \`../lisp/version.el'" >&2
196 exit 1
199 ### Find out which version of Emacs this is.
200 shortversion=`grep 'defconst[ ]*emacs-version' ../lisp/version.el \
201 | sed -e 's/^.*"\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/'`
202 version=`grep 'defconst[ ]*emacs-version' ../lisp/version.el \
203 | sed -e 's/^[^"]*"\([^"]*\)".*$/\1/'`
204 if [ ! "${version}" ]; then
205 echo "${progname}: can't find current Emacs version in \`./lisp/version.el'" >&2
206 exit 1
209 echo Version numbers are $version and $shortversion
211 ### Make sure we don't already have a directory emacs-${version}.
213 emacsname="emacs-${version}${new_extension}"
215 if [ -d ${emacsname} ]
216 then
217 echo Directory "${emacsname}" already exists >&2
218 exit 1
221 ### Make sure the subdirectory is available.
222 tempparent="make-package.tmp.$$"
223 if [ -d ${tempparent} ]; then
224 echo "${progname}: staging directory \`${tempparent}' already exists.
225 Perhaps a previous invocation of \`${progname}' failed to clean up after
226 itself. Check that directories whose names are of the form
227 \`make-dist.tmp.NNNNN' don't contain any important information, remove
228 them, and try again." >&2
229 exit 1
232 if [ -d /Volumes/Emacs ]; then
233 echo "${progname}: Already have an Emacs disc image mounted. Please
234 eject that disc image and try again." >&2
235 exit 1
238 tempparentfull="`pwd`/${tempparent}"
239 tempparentdist=${tempparentfull}/dist
241 if test "$build_in_place" = "no"; then
242 case ${builddir} in
243 ${srcdir})
244 tempbuild="make-package.build.$$"
245 builddir="`pwd`/${tempbuild}"
246 removable_build_dir=${builddir}
247 mkdir -p ${builddir}
249 [\\/]* | ?:[\\/]* ) #Absolutepath.
250 mkdir -p ${builddir}
253 mkdir -p ${builddir}
254 builddir=`cd $builddir && pwd`
256 esac
258 # Location of install package
259 packagedir=${builddir}/mac/Emacs.pkg
261 echo Building in directory ${builddir}
262 echo Installing into directory ${tempparentfull} >&2
264 ### This trap ensures that the staging directory will be cleaned up even
265 ### when the script is interrupted in mid-career.
266 trap "echo 'Interrupted...cleaning up the staging directory'; rm -rf ${tempparent} ${removable_build_dir} ${packagedir}; exit 1" 1 2 15
268 # Run configure in the new tempparent directory
269 if test "$with_config" = "yes"; then
270 (cd ${builddir}; ${srcdir}/configure ${config_options} --prefix=${prefix})
273 installprefix=${tempparentfull}${prefix}
274 if test "$self_contained" = "yes"; then
275 # If selfcontained, the local directory is Resources directory
276 installprefix=$tempparentfull/$appsdir/$emapp/Contents/Resources
280 make_options="prefix=${installprefix} $make_options"
282 if test "$with_app" = "yes"; then
283 make_options="carbon_appdir=${tempparentfull}/Applications $make_options"
286 ## Make bootstrap if .elc files are missing from distribution
287 if [ ! -f ${srcdir}/lisp/abbrev.elc ]; then
288 echo "Required .elc files missing; making bootstrap..."
289 if ! (cd ${builddir}; make bootstrap $make_options); then
290 echo "Make bootstrap failed... Aborting make-package."
291 exit 2
295 if ! (cd ${builddir}; make install $make_options); then
296 echo "Make failed... Aborting make-package."
297 exit 1
300 if test "$full_dist" == "no"; then
301 echo "Removing unneeded .el files"
302 sharedir=$installprefix/share/emacs/$version
303 find $sharedir/lisp $sharedir/leim -name "*.elc" -print | sed 's|\(.*\)\.elc$|/bin/rm -f \1.el|' | /bin/sh -s
306 if test "$compressed_dist" == "yes" -a "$full_dist" == "yes"; then
307 echo "Compressing .el files"
308 sharedir=$installprefix/share/emacs/$version
309 find $sharedir/lisp $sharedir/leim -name "*.elc" -print | sed 's|\(.*\)\.elc$|/usr/bin/gzip -9 \1.el|' | /bin/sh -s
310 echo "Compressing info files"
311 find $installprefix/info -type f ! -name dir -print | sed 's|\(.*\)$|/usr/bin/gzip -9 \1|' | /bin/sh -s
314 if test "$with_app" == "yes"; then
315 echo "Creating Emacs.app application"
316 tempappdir=${tempparentfull}${appsdir}
317 tempemapp=${tempappdir}/${emapp}/Contents/MacOS/Emacs
318 ## Delete any CVS files
319 find ${tempappdir} -name "CVS" -type d -exec rm -rf {} \;
321 ## Have application be a symlink to ${prefix}/bin/emacs
322 if test "$app_symlink" == "yes"; then
323 echo "Creating application symlink"
324 rm ${tempemapp}
325 ln -s ${prefix}/bin/${emacsname} ${tempemapp}
329 compver=`uname -p`-apple-darwin`uname -r`
331 if test "$self_contained" = "yes"; then
332 # Move shared files down to Resources directory
333 mv $installprefix/share/emacs/$version/* $installprefix
334 mv $installprefix/share/info $installprefix
335 mv $installprefix/share/man $installprefix
336 rm -rf $installprefix/share
337 # These directories might remain in Resources
338 mv $installprefix/bin $installprefix/../MacOS/bin
339 mv $installprefix/libexec/emacs/$version/$compver $installprefix/../MacOS/libexec
340 # Make the application binary a hard link
341 rm $installprefix/../MacOS/Emacs
342 ln $installprefix/../MacOS/bin/emacs $installprefix/../MacOS/Emacs
346 # Remove unnecessary .el files
347 #if test "$full_dist" = no; then
350 echo "Creating Package Info file"
352 mkdir -p ${packagedir}
353 mkdir ${packagedir}/Contents
354 mkdir ${packagedir}/Contents/Resources
355 mkdir ${packagedir}/Contents/Resources/English.lproj
356 echo -n 'pmkrpkg1' > ${packagedir}/Contents/PkgInfo
358 # Create ReadMe and License files
359 cp ${srcdir}/COPYING ${packagedir}/Contents/Resources/License.txt
360 cp ${srcdir}/mac/README ${packagedir}/Contents/Resources/ReadMe.txt
362 infofile=${packagedir}/Contents/Resources/English.lproj/Emacs.info
364 echo 'Title GNU Emacs' > ${infofile}
365 echo "Version ${version}" >> ${infofile}
366 echo "Description Install GNU Emacs ${version} as a command-line app and a Mac OS Application" >> ${infofile}
367 echo 'DefaultLocation /' >> ${infofile}
368 echo 'DeleteWarning' >> ${infofile}
369 echo 'NeedsAuthorization YES' >> ${infofile}
370 echo 'Required NO' >> ${infofile}
371 echo 'Relocatable NO' >> ${infofile}
372 echo 'RequiresReboot NO' >> ${infofile}
373 echo 'UseUserMask NO' >> ${infofile}
374 echo 'OverwritePermissions NO' >> ${infofile}
375 echo 'InstallFat NO' >> ${infofile}
377 ### Set the install directory to install files as root...
378 ### Not sure if this is a good diea
379 # echo "Setting owner to root"
380 # chown -Rh 0 ${tempparentfull}
382 echo "Creating pax file"
383 (cd ${tempparentfull}; pax -w -f ${packagedir}/Contents/Resources/Emacs.pax .)
384 echo "Compressing pax file"
385 gzip ${packagedir}/Contents/Resources/Emacs.pax
387 echo "Creating bom file"
388 mkbom ${tempparentfull} ${packagedir}/Contents/Resources/Emacs.bom
390 echo "Generating sizes file"
391 sizesfile=${packagedir}/Contents/Resources/Emacs.sizes
393 numFiles=`du -a ${tempparent} | wc -l`
394 installedSize=`du -s ${tempparent} | cut -f1`
395 compressedSize=`du -s ${packagedir} | cut -f1`
397 echo "NumFiles ${numFiles}" > ${sizesfile}
398 echo "InstalledSize ${installedSize}" >> ${sizesfile}
399 echo "CompressedSize ${compressedSize}" >> ${sizesfile}
400 cat ${sizesfile}
402 echo "Creating Disc Image"
403 ## From hdiutil man page, a sector is 512k. Allocate an extra 5% for
404 ## directories and partition tables.
405 sectorsAlloced=`echo 2.1*${compressedSize}|bc`
406 hdiutil create -ov ${builddir}/mac/EmacsRW -sectors ${sectorsAlloced}
407 ## Need to format the disc image before mounting
408 mountLoc=`hdid -nomount ${builddir}/mac/EmacsRW.dmg | grep HFS | cut -f1`
409 /sbin/newfs_hfs -v Emacs ${mountLoc}
410 hdiutil eject ${mountLoc}
411 echo "Copying Package to Disc Image"
412 hdid ${builddir}/mac/EmacsRW.dmg
414 if test "$keep_directory" = "no"; then
415 rm -rf ${tempparentfull}
416 else
417 mv ${tempparentfull} ${emacsname}
420 if [ ! -d /Volumes/Emacs ]; then
421 echo "Could not create disc image. The Emacs installer package (Emacs.pkg)
422 in this directory should be correct. Please use the Disc Copy program to
423 create a disc image." >&2
424 exit 0
427 cp -R ${packagedir} /Volumes/Emacs
429 ## Converting Disk Image to read-only
430 echo 'Converting Disc Image to read-only'
431 hdiutil eject ${mountLoc}
432 hdiutil resize ${builddir}/mac/EmacsRW.dmg -sectors min
433 if test "$comp_diskimage" = "yes"; then
434 hdiutil convert ${builddir}/mac/EmacsRW.dmg -format UDZO -imagekey zlib-level=2 -o ${srcdir}/mac/EmacsInstaller.dmg
435 else
436 hdiutil convert ${builddir}/mac/EmacsRW.dmg -format UDRO -o ${srcdir}/mac/EmacsInstaller.dmg
438 rm ${builddir}/mac/EmacsRW.dmg
440 echo "Cleaning up the staging directory"
441 rm -rf ${builddir}/mac/Emacs.pkg ${removable_build_dir}
443 # arch-tag: 1b631d0d-9fde-4f71-80c0-33e0e5815515
444 ### make-package ends here