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