]> git.lyx.org Git - features.git/blob - development/LyX-Mac-binary-release.sh
b0460897b928196394193463577e5ae46efb50b6
[features.git] / development / LyX-Mac-binary-release.sh
1 #!/bin/sh
2
3 # set -x
4
5 # This script automates creating universal binaries of LyX on Mac.
6 # Author: Bennett Helm (and extended by Konrad Hofbauer)
7 # modified by Stephan Witt
8 # Last modified: 17 April 2010
9
10 # Prerequisite:
11 # * a decent checkout of LyX sources (probably you have it already)
12 # * Qt4 - build with shared or static libraries for the used platforms (default: i386 and ppc)
13 #    or - an unpacked source tree of Qt4 in $QT4SOURCEDIR or in the sibling directory (variable Qt4SourceVersion)
14 # * for aspell support:
15 #   the aspell sources placed in a sibling directory (variable ASpellSourceVersion)
16 # * for hunspell support:
17 #   the hunspell sources placed in a sibling directory (variable HunSpellSourceVersion)
18 # * for dictionary deployment:
19 #   - aspell:   the dictionary files of macports (in /opt/local/share/aspell and /opt/local/lib/aspell-0.60)
20 #   - hunspell: the dictionary files in the sibling directory Dictionaries/dict
21 #   - mythes:   the data and idx files in the sibling directory Dictionaries/thes
22
23 LyXConfigureOptions="--enable-warnings --enable-optimization=-Os --with-included-gettext"
24 AspellConfigureOptions="--enable-warnings --disable-nls --enable-compile-in-filters --disable-pspell-compatibility"
25 HunspellConfigureOptions="--with-warnings --disable-nls --with-included-gettext --disable-static"
26 Qt4ConfigureOptions="-opensource -silent -shared -release -fast -no-exceptions"
27 Qt4ConfigureOptions="${Qt4ConfigureOptions} -no-webkit -no-qt3support -no-javascript-jit -no-dbus"
28 Qt4ConfigureOptions="${Qt4ConfigureOptions} -nomake examples -nomake demos -nomake docs -nomake tools"
29
30 aspell_deployment="yes"
31 hunspell_deployment="yes"
32 thesaurus_deployment="yes"
33 qt4_deployment="yes"
34 MACOSX_DEPLOYMENT_TARGET="10.4" # Tiger support is default
35
36 usage() {
37         echo Build script for LyX on Mac OS X
38         echo
39         echo Optional arguments:
40         echo " --aspell-deployment=yes|no ." default yes
41         echo " --qt4-deployment=yes|no ...." default yes
42         echo " --with-macosx-target=TARGET " default 10.4 "(Tiger)"
43         echo " --with-arch=ARCH ..........." default ppc,i386
44         echo " --with-build-path=PATH ....." default \${lyx-src-dir}/../lyx-build
45         echo " --with-dmg-location=PATH ..." default \${build-path}
46         echo
47         echo "All other arguments with -- are passed to configure"
48         echo "including the defaults: ${LyXConfigureOptions}"
49         echo
50         exit 0
51 }
52
53 while [ $# -gt 0 ]; do
54         case "${1}" in
55         --with-qt4-dir=*)
56                 QTDIR=`echo ${1}|cut -d= -f2`
57                 shift
58                 ;;
59         --with-macosx-target=*)
60                 MACOSX_DEPLOYMENT_TARGET=`echo ${1}|cut -d= -f2`
61                 shift
62                 ;;
63         --aspell-deployment=*)
64                 aspell_deployment=`echo ${1}|cut -d= -f2`
65                 shift
66                 ;;
67         --hunspell-deployment=*)
68                 hunspell_deployment=`echo ${1}|cut -d= -f2`
69                 shift
70                 ;;
71         --thesaurus-deployment=*)
72                 thesaurus_deployment=`echo ${1}|cut -d= -f2`
73                 shift
74                 ;;
75         --qt4-deployment=*)
76                 qt4_deployment=`echo ${1}|cut -d= -f2`
77                 shift
78                 ;;
79         --with-arch=*)
80                 ARCH=`echo ${1}|cut -d= -f2|tr ',' ' '`
81                 ARCH_LIST="${ARCH_LIST} ${ARCH}"
82                 shift
83                 ;;
84         --with-dmg-location=*)
85                 DMGLocation=`echo ${1}|cut -d= -f2`
86                 shift
87                 ;;
88         --with-build-path=*)
89                 LyxBuildDir=`echo ${1}|cut -d= -f2`
90                 shift
91                 ;;
92         --help)
93                 usage
94                 ;;
95         --without-aspell)
96                 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
97                 aspell_deployment="no"
98                 shift
99                 ;;
100         --without-hunspell)
101                 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
102                 hunspell_deployment="no"
103                 shift
104                 ;;
105         --*)
106                 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
107                 shift
108                 ;;
109         *)
110                 break
111                 ;;
112         esac
113 done
114
115 # Set these variables -- to
116 # (1) the location of your Qt4 installation
117 # (2) the location of resulting DMG
118 # (3) the version of private aspell installation
119 #     (to define the location assign ASpellSourceDir instead)
120 # (4) the list of architectures to build for
121
122 QtInstallDir=${QTDIR:-"/opt/qt4"}
123 QtFrameworkVersion="4"
124 ASpellSourceVersion="aspell-0.60.6"
125 HunSpellSourceVersion="hunspell-1.2.9"
126 Qt4SourceVersion="qt-everywhere-opensource-src-4.6.2"
127
128 ARCH_LIST=${ARCH_LIST:-"ppc i386"}
129
130 strip="-strip"
131
132 # detection of script home
133 LyxSourceDir=${1:-`dirname "$0"`}
134 if [ ! -d "${LyxSourceDir}" ]; then
135         echo Missing LyX source directory.
136         exit 2
137 fi
138 case "${LyxSourceDir}" in
139 /*/development)
140         LyxSourceDir=`dirname "${LyxSourceDir}"`
141         ;;
142 /*)
143         ;;
144 */development|development)
145         LyxSourceDir=`dirname "${LyxSourceDir}"`
146         LyxSourceDir=`cd "${LyxSourceDir}";pwd`
147         ;;
148 *)
149         LyxSourceDir=`cd "${LyxSourceDir}";pwd`
150         ;;
151 esac
152
153 LyxBuildDir=${LyxBuildDir:-`dirname "${LyxSourceDir}"`/lyx-build}
154 DMGLocation=${DMGLocation:-"${LyxBuildDir}"}
155
156 ASpellSourceDir=${ASPELLDIR:-`dirname "${LyxSourceDir}"`/${ASpellSourceVersion}}
157 ASpellInstallDir=${ASpellInstallDir:-"${LyxBuildDir}"/SpellChecker.lib}
158 HunSpellSourceDir=${HUNSPELLDIR:-`dirname "${LyxSourceDir}"`/${HunSpellSourceVersion}}
159 HunSpellInstallDir=${HunSpellInstallDir:-"${LyxBuildDir}"/SpellChecker.lib}
160 Qt4SourceDir=${QT4SOURCEDIR:-`dirname "${LyxSourceDir}"`/${Qt4SourceVersion}}
161 Qt4BuildDir="${LyxBuildDir}/qt4-build"
162 DictionarySourceDir=${DICTIONARYDIR:-`dirname "${LyxSourceDir}"`/Dictionaries}
163
164 ASpellInstallHdr="${ASpellInstallDir}/include/aspell.h"
165 HunSpellInstallHdr="${HunSpellInstallDir}/include/hunspell/hunspell.h"
166
167 if [ -z "${LyXVersion}" ]; then
168         LyXVersion=`grep AC_INIT "${LyxSourceDir}"/configure.ac | cut -d, -f2 | tr -d " ()"`
169 fi
170
171 LyxName="LyX"
172 LyxBase="${LyxName}-${LyXVersion}"
173 LyxApp="${LyxBase}.app"
174 LyxAppDir="${LyxBuildDir}"/"${LyxBase}"
175 LyxBuildDir="${LyxAppDir}.build"
176 LyxAppPrefix="${LyxAppDir}.app"
177 # if zip file is needed... remove the comment sign
178 #LyxAppZip="${LyxAppPrefix}.zip"
179
180 BuildSystem=`"${LyxSourceDir}/config/config.guess"`
181
182 # ---------------------------------
183 # DON'T MODIFY ANYTHING BELOW HERE!
184 # ---------------------------------
185
186 # These variables define the identifiers of the
187 # system (both Intel and PowerPC) to compile for.
188 # (Note: darwin8 is 10.4; darwin9 is 10.5.)
189 # Only change these if necessary
190
191 HostSystem_i386="i686-apple-darwin8"
192 HostSystem_ppc="powerpc-apple-darwin8"
193
194 # don't change order here...
195 QtLibraries="QtSvg QtXml QtGui QtNetwork QtCore"
196
197 DMGNAME="${LyxBase}"
198 DMGSIZE="550m"
199 BACKGROUND="${LyxAppDir}.app/Contents/Resources/images/banner.png"
200
201 # Check for existing SDKs
202 SDKs=`echo /Developer/SDKs/MacOSX10*sdk`
203 case "$SDKs" in
204 *10.6*)
205         MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"10.5"}; export MACOSX_DEPLOYMENT_TARGET
206         case "${MACOSX_DEPLOYMENT_TARGET}" in
207         10.5)
208                 SDKROOT="/Developer/SDKs/MacOSX10.5.sdk"; export SDKROOT
209                 ;;
210         10.4)
211                 SDKROOT="/Developer/SDKs/MacOSX10.4u.sdk"; export SDKROOT
212                 CC=gcc-4.0 ; export CC
213                 CXX=g++-4.0 ; export CXX
214                 OBJC=gcc-4.0 ; export OBJC
215                 ;;
216         esac
217         ;;
218 *10.5*)
219         MACOSX_DEPLOYMENT_TARGET="10.4"; export MACOSX_DEPLOYMENT_TARGET
220         SDKROOT="/Developer/SDKs/MacOSX10.4u.sdk"; export SDKROOT
221         ;;
222 *)
223         echo Unknown or missing SDK for Mac OS X.
224         exit 1
225         ;;
226 esac
227 MYCFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}"
228
229 if [ -d "${Qt4SourceDir}" -a ! -d "${Qt4BuildDir}" ]; then
230         echo Build Qt4 library ${Qt4SourceDir}
231
232         (
233                 mkdir -p "${Qt4BuildDir}" && cd "${Qt4BuildDir}"
234                 for arch in ${ARCH_LIST} ; do
235                         ARCHS="${ARCHS} -arch ${arch}"
236                 done
237                 echo configure options:
238                 echo ${Qt4ConfigureOptions} ${ARCHS} -prefix "${QtInstallDir}"
239
240                 echo yes | "${Qt4SourceDir}"/configure ${Qt4ConfigureOptions} ${ARCHS} -prefix "${QtInstallDir}"
241                 make && make install
242         )
243         cd "${QtInstallDir}" && (
244                 mkdir -p include
245                 cd include
246                 for libnm in ${QtLibraries} ; do
247                         test -d ${libnm} -o -L ${libnm} || ln -s ../lib/${libnm}.framework/Headers ${libnm}
248                 done
249         )
250 fi
251
252 if [ -d "${HunSpellSourceDir}" -a ! -f "${HunSpellInstallHdr}" ]; then
253         # we have a private HunSpell source tree at hand...
254         # so let's build and install it
255         if [ -z "${HunSpellVersion}" ]; then
256                 HunSpellVersion=`grep AC_INIT "${HunSpellSourceDir}"/configure.ac | cut -d, -f2|tr -d " ()"`
257         fi
258
259         HunSpellName="Hunspell"
260         HunSpellBase="${HunSpellName}-${HunSpellVersion}"
261
262         echo Build hunspell library ${HunSpellBase}
263         echo configure options:
264         echo --prefix="${HunSpellInstallDir}" ${HunspellConfigureOptions}
265
266         cd "${HunSpellSourceDir}"
267
268         # ----------------------------------------
269         # Build HunSpell for different architectures
270         # ----------------------------------------
271         FILE_LIST="libhunspell-1.2.0.dylib"
272
273         for arch in ${ARCH_LIST} ; do
274                 make distclean
275                 CPPFLAGS=" -arch ${arch} ${MYCFLAGS}"; export CPPFLAGS
276                 LDFLAGS=" -arch ${arch}"; export LDFLAGS
277                 HOSTSYSTEM=`eval "echo \\$HostSystem_$arch"`
278                 "${HunSpellSourceDir}/configure"\
279                         --prefix="${HunSpellInstallDir}"\
280                         ${HunspellConfigureOptions}
281                         #--host="${HOSTSYSTEM}" ${BuildSystem:+"--build=${BuildSystem}"}
282                 make && make install${strip}
283                 for file in ${FILE_LIST} ; do
284                         if [ -f "${HunSpellInstallDir}"/lib/${file} ]; then
285                                 mv "${HunSpellInstallDir}"/lib/${file}\
286                                         "${HunSpellInstallDir}"/lib/${file}-${arch} 
287                         else
288                                 echo Cannot build and install HunSpell for ${arch}.
289                                 exit 1
290                         fi
291                 done
292         done
293         # -------------------------
294         # Create universal binaries
295         # -------------------------
296         for file in ${FILE_LIST} ; do
297                 OBJ_LIST=
298                 for arch in ${ARCH_LIST} ; do
299                         OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
300                 done
301                 (
302                         cd "${HunSpellInstallDir}"
303                         lipo -create ${OBJ_LIST} -o lib/${file}
304                         # check for the "missing link"...
305                         test -f lib/libhunspell.dylib || (cd lib ; ln -s libhunspell-1.2.dylib libhunspell.dylib)
306                 )
307         done
308         # --------
309         # Clean up
310         # --------
311         for arch in ${ARCH_LIST} ; do
312                 rm -f "${HunSpellInstallDir}"/lib/*-${arch}
313         done
314 fi
315
316 #exit 0
317
318
319 if [ -d "${ASpellSourceDir}" -a ! -f "${ASpellInstallHdr}" -a "yes" = "${aspell_deployment}" ]; then
320         # we have a private ASpell source tree at hand...
321         # so let's build and install it
322         if [ -z "${ASpellVersion}" ]; then
323                 ASpellVersion=`grep AC_INIT "${ASpellSourceDir}"/configure.ac | cut -d, -f2|tr -d " ()"`
324         fi
325
326         ASpellName="Aspell"
327         ASpellBase="${ASpellName}-${ASpellVersion}"
328
329         echo Build aspell library ${ASpellBase}
330         echo configure options:
331         echo --prefix="${ASpellInstallDir}" ${AspellConfigureOptions}
332
333         # ASpell builds inplace only :(
334         cd "${ASpellSourceDir}"
335
336         # ----------------------------------------
337         # Build ASpell for different architectures
338         # ----------------------------------------
339         FILE_LIST="libaspell.15.dylib"
340
341         for arch in ${ARCH_LIST} ; do
342                 make distclean
343                 CPPFLAGS=" -arch ${arch} ${MYCFLAGS}"; export CPPFLAGS
344                 LDFLAGS=" -arch ${arch}"; export LDFLAGS
345                 HOSTSYSTEM=`eval "echo \\$HostSystem_$arch"`
346                 "${ASpellSourceDir}/configure"\
347                         --prefix="${ASpellInstallDir}"\
348                         ${AspellConfigureOptions}
349                         #--host="${HOSTSYSTEM}" ${BuildSystem:+"--build=${BuildSystem}"}
350                 make && make install${strip}
351                 for file in ${FILE_LIST} ; do
352                         if [ -f "${ASpellInstallDir}"/lib/${file} ]; then
353                                 mv "${ASpellInstallDir}"/lib/${file}\
354                                         "${ASpellInstallDir}"/lib/${file}-${arch} 
355                         else
356                                 echo Cannot build and install ASpell for ${arch}.
357                                 exit 1
358                         fi
359                 done
360         done
361         # -------------------------
362         # Create universal binaries
363         # -------------------------
364         for file in ${FILE_LIST} ; do
365                 OBJ_LIST=
366                 for arch in ${ARCH_LIST} ; do
367                         OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
368                 done
369                 (
370                         cd "${ASpellInstallDir}"
371                         lipo -create ${OBJ_LIST} -o lib/${file}
372                 )
373         done
374         # --------
375         # Clean up
376         # --------
377         for arch in ${ARCH_LIST} ; do
378                 rm -f "${ASpellInstallDir}"/lib/*-${arch}
379         done
380 fi
381
382 framework_name() {
383         echo "Frameworks/${1}.framework"
384 }
385
386 if [ ! -f "${LyxSourceDir}"/configure ]; then
387         ( cd "${LyxSourceDir}" && sh autogen.sh )
388 fi
389
390 FILE_LIST="lyx lyxclient tex2lyx"
391 BUNDLE_PATH="Contents/MacOS"
392 LYX_BUNDLE_PATH="${LyxAppPrefix}/${BUNDLE_PATH}"
393 build_lyx() {
394         # Clear Output
395         if [ -n "${LyxAppZip}" -a -f "${LyxAppZip}" ]; then rm "${LyxAppZip}"; fi
396         if [ -d "${LyxAppPrefix}" ]; then rm -rf "${LyxAppPrefix}"; fi
397
398         # -------------------------------------
399         # Build LyX for different architectures
400         # -------------------------------------
401
402         if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_deployment}" ]; then
403                 ASpellFramework=`framework_name Aspell`
404                 ASpellFramework=`basename "${ASpellFramework}"`
405                 ConfigureExtraInc="--with-extra-inc=${ASpellInstallDir}/include"
406                 ConfigureExtraLib="--with-extra-lib=${ASpellInstallDir}/lib"
407                 LyXConfigureOptions="${LyXConfigureOptions} --with-aspell-framework=${ASpellFramework}"
408         fi
409
410         if [ -d "${HunSpellInstallDir}" -a "yes" = "${hunspell_deployment}" ]; then
411                 HunSpellFramework=`framework_name Hunspell`
412                 HunSpellFramework=`basename "${HunSpellFramework}"`
413                 ConfigureExtraInc="--with-extra-inc=${HunSpellInstallDir}/include"
414                 ConfigureExtraLib="--with-extra-lib=${HunSpellInstallDir}/lib"
415                 # LyXConfigureOptions="${LyXConfigureOptions} --with-hunspell-framework=${HunSpellFramework}"
416         fi
417         LyXConfigureOptions="${LyXConfigureOptions} ${ConfigureExtraInc}"
418         LyXConfigureOptions="${LyXConfigureOptions} ${ConfigureExtraLib}"
419
420         for arch in ${ARCH_LIST} ; do
421
422                 if [ -d "${LyxBuildDir}" ];  then rm -r "${LyxBuildDir}"; fi
423                 mkdir "${LyxBuildDir}" && cd "${LyxBuildDir}"
424
425                 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"; export CPPFLAGS
426                 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch}"; export LDFLAGS
427                 HOSTSYSTEM=`eval "echo \\$HostSystem_$arch"`
428
429                 echo LDFLAGS="${LDFLAGS}"
430                 echo CPPFLAGS="${CPPFLAGS}"
431                 echo CONFIGURE_OPTIONS="${LyXConfigureOptions}"
432                 "${LyxSourceDir}/configure"\
433                         --prefix="${LyxAppPrefix}" --with-version-suffix="-${LyXVersion}"\
434                         ${QtInstallDir:+"--with-qt4-dir=${QtInstallDir}"} \
435                         ${LyXConfigureOptions}\
436                         --host="${HOSTSYSTEM}" --build="${BuildSystem}" --enable-build-type=rel
437                 make && make install${strip}
438                 for file in ${FILE_LIST} ; do
439                         if [ -f "${LYX_BUNDLE_PATH}/${file}" ]; then
440                                 mv "${LYX_BUNDLE_PATH}/${file}"\
441                                         "${LYX_BUNDLE_PATH}/${file}-${arch}" 
442                         else
443                                 echo ERROR: Cannot build and install LyX for ${arch}.
444                                 exit 1
445                         fi
446                 done
447         done
448 }
449
450 content_directory() {
451         target="$1"
452         content=`dirname "${target}"`
453         content=`dirname "${content}"`
454         echo "${content}"
455 }
456
457 private_framework() {
458         fwdir=`framework_name "$1"`
459         source="$2"
460         target="$3"
461         condir=`content_directory "${target}"`
462         libnm=`basename "${source}"`
463         mkdir -p "${condir}/${fwdir}"
464         if [ ! -f "${condir}/${fwdir}/${libnm}" ]; then
465                 cp -p "${source}" "${condir}/${fwdir}"
466                 echo Set library id in "${condir}/${fwdir}/${libnm}"
467                 install_name_tool -id "@executable_path/../${fwdir}/${libnm}" "${condir}/${fwdir}/${libnm}"
468         fi
469         echo Correct library id reference to "${libnm}" in "${target}"
470         install_name_tool -change "${source}" "@executable_path/../${fwdir}/${libnm}" "${target}"
471 }
472
473 deploy_qtlibs() {
474         source="${QtInstallDir}"
475         target="$1"
476         version="Versions/${QtFrameworkVersion}/"
477         condir=`content_directory "${target}"`
478         mkdir -p "${condir}/Resources"
479         test -f "${condir}/Resources/qt.conf" || cat - > "${condir}/Resources/qt.conf" <<-EOF
480 [Paths]
481 Plugins = PlugIns
482 EOF
483         if [ ! -d "${condir}/PlugIns" ]; then
484                 mkdir -p "${condir}/PlugIns"
485                 find "${source}/plugins" -name \*.dylib -print | while read libname ; do
486                         echo Copy plugin "${libname}"
487                         dylib=`basename "${libname}"`
488                         dirname=`dirname "${libname}"`
489                         dirname=`basename "${dirname}"`
490                         mkdir -p "${condir}/PlugIns/${dirname}"
491                         cp -p "${libname}" "${condir}/PlugIns/${dirname}"
492                 done
493         fi
494         for libnm in ${QtLibraries} ; do
495                 fwdir=`framework_name "$libnm"`
496                 dirname=`basename "${fwdir}"`
497                 test -d "${condir}/${fwdir}" || (
498                         echo Copy framework "${source}/lib/"`basename "${fwdir}"`
499                         cp -pR "${source}/lib/"`basename "${fwdir}"` "${condir}/${fwdir}"
500                         echo Set library id in "${condir}/${fwdir}/${version}${libnm}"
501                         install_name_tool -id "@executable_path/../${fwdir}/${version}${libnm}" "${condir}/${fwdir}/${version}${libnm}"
502                         find "${condir}/PlugIns" "${condir}/"`dirname "${fwdir}"` -name Headers -prune -o -type f -print | while read filename ; do
503                                 otool -L "${filename}" 2>/dev/null | while read library ; do
504                                         # pattern match for: /path/to/qt4/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.6.0, current version 4.6.2)
505                                         case "${library}" in
506                                         *"${libnm}"*"("*")"*)
507                                                 echo Correct library id reference to "${libnm}" in "${filename}"
508                                                 install_name_tool -change\
509                                                         "${source}/lib/${dirname}/${version}${libnm}"\
510                                                         "@executable_path/../${fwdir}/${version}${libnm}"\
511                                                         "${filename}"
512                                                 ;;
513                                         esac
514                                 done
515                         done
516                 )
517                 echo Correct library id reference to "${libnm}" in "${target}"
518                 install_name_tool -change\
519                         "${source}/lib/${dirname}/${version}${libnm}"\
520                         "@executable_path/../${fwdir}/${version}${libnm}"\
521                         "${target}"
522         done
523 }
524
525 # -------------------------
526 # Create universal binaries
527 # -------------------------
528 convert_universal() {
529         cd "${LyxAppPrefix}"
530         for file in ${FILE_LIST} ; do
531                 OBJ_LIST=
532                 for arch in ${ARCH_LIST} ; do
533                         if [ -f "${BUNDLE_PATH}/${file}-${arch}" ]; then
534                                 OBJ_LIST="${OBJ_LIST} ${BUNDLE_PATH}/${file}-${arch}"
535                         fi
536                 done
537                 if [ -n "${OBJ_LIST}" ]; then
538                         lipo -create ${OBJ_LIST} -o "${BUNDLE_PATH}/${file}"
539                 fi
540                 if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_deployment}" ]; then
541                         private_framework Aspell "${ASpellInstallDir}/lib/libaspell.15.dylib" "${LYX_BUNDLE_PATH}/${file}"
542                 fi
543                 if [ -d "${HunSpellInstallDir}" -a "yes" = "${hunspell_deployment}" ]; then
544                         private_framework Hunspell "${HunSpellInstallDir}/lib/libhunspell-1.2.0.dylib" "${LYX_BUNDLE_PATH}/${file}"
545                 fi
546                 if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt4_deployment}" ]; then
547                         deploy_qtlibs "${LYX_BUNDLE_PATH}/${file}"
548                 fi
549                 otool -L "${BUNDLE_PATH}/${file}" | while read reference ; do
550                         case "${reference}" in
551                         *"${LyxBuildDir}"*"("*")")
552                                 echo ERROR: Bad reference to "${reference}" found!!
553                                 ;;
554                         esac
555                 done
556         done
557         for arch in ${ARCH_LIST} ; do
558                 rm -f ${BUNDLE_PATH}/*-${arch}
559         done
560 }
561
562 copy_dictionaries() {
563         if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_deployment}" ]; then
564                 ASpellFramework=`framework_name Aspell`
565                 ASpellResources="${LyxAppPrefix}/Contents/${ASpellFramework}/Resources"
566                 # try to reuse macports dictionaries for now
567                 if [ -d /opt/local/lib/aspell-0.60 ]; then ASpellInstallDir=/opt/local ; fi
568                 mkdir -p "${ASpellResources}"
569                 echo Copy Aspell dictionaries from "${ASpellInstallDir}"
570                 cp -p -r "${ASpellInstallDir}/lib/aspell-0.60" "${ASpellResources}"/data
571                 cp -p -r "${ASpellInstallDir}/share/aspell" "${ASpellResources}"/dict
572         fi
573         if [ -d "${HunSpellInstallDir}" -a "yes" = "${hunspell_deployment}" ]; then
574                 HunSpellResources="${LyxAppPrefix}/Contents/Resources"
575                 if [ -d "${DictionarySourceDir}" ]; then
576                         cp -p -r "${DictionarySourceDir}/dict" "${HunSpellResources}"
577                 fi
578         fi
579         if [ -d "${DictionarySourceDir}" -a "yes" = "${thesaurus_deployment}" ]; then
580                 MyThesResources="${LyxAppPrefix}/Contents/Resources"
581                 cp -p -r "${DictionarySourceDir}/thes" "${MyThesResources}"
582         fi
583 }
584
585 function set_bundle_display_options() {
586         osascript <<-EOF
587     tell application "Finder"
588         set f to POSIX file ("${1}" as string) as alias
589         tell folder f
590             open
591             tell container window
592                 set toolbar visible to false
593                 set statusbar visible to false
594                 set current view to icon view
595                 delay 1 -- sync
596                 set the bounds to {20, 50, $2, $3}
597             end tell
598             delay 1 -- sync
599             set icon size of the icon view options of container window to 64
600             set arrangement of the icon view options of container window to not arranged
601             set position of item "${LyxName}.app" to {100,$4}
602             set position of item "Applications" to {280,$4}
603             set background picture of the icon view options\
604                                         of container window to file "background.png" of folder "Pictures"
605             set the bounds of the container window to {0, 0, $2, $3}
606             update without registering applications
607             delay 5 -- sync
608             close
609         end tell
610         delay 5 -- sync
611     end tell
612 EOF
613 }
614
615 function make_dmg() {
616         cd "${1}"
617
618         BGSIZE=`file "$BACKGROUND" | awk -F , '/PNG/{print $2 }' | tr x ' '`
619         BG_W=`echo ${BGSIZE} | awk '{print $1 }'`
620         BG_H=`echo ${BGSIZE} | awk '{h = $2 + 20 ;print h }'`
621         BG_Y=`echo ${BGSIZE} | awk '{y = $2 - 60 ;print y }'`
622
623         rm -f "${DMGNAME}.sparseimage" "${DMGNAME}.dmg"
624
625         hdiutil create -type SPARSE -size ${DMGSIZE:-"250m"} -fs HFS+ -volname "${LyxBase}" "${DMGNAME}"
626         # Unmount currently mounted disk image
627         test -d /Volumes/"${LyxBase}" && umount /Volumes/"${LyxBase}"
628
629         # Mount the disk image
630         hdiutil attach "${DMGNAME}.sparseimage"
631
632         # Obtain device information
633         DEVS=$(hdiutil attach "${DMGNAME}.sparseimage" | cut -f 1)
634         DEV=$(echo $DEVS | cut -f 1 -d ' ')
635         VOLUME=$(mount |grep ${DEV} | cut -f 3 -d ' ')
636
637         # copy in the application bundle
638         cp -Rp "${LyxAppDir}.app" "${VOLUME}/${LyxName}.app"
639
640         # copy in background image
641         mkdir -p "${VOLUME}/Pictures"
642         cp "${BACKGROUND}" "${VOLUME}/Pictures/background.png"
643         # symlink applications
644         ln -s /Applications/ "${VOLUME}"/Applications
645         set_bundle_display_options "${VOLUME}" ${BG_W} ${BG_H} ${BG_Y}
646         mv "${VOLUME}/Pictures" "${VOLUME}/.Pictures"
647
648         # Unmount the disk image
649         hdiutil detach ${DEV}
650
651         # Convert the disk image to read-only
652         hdiutil convert "${DMGNAME}.sparseimage" -format UDBZ -o "${DMGNAME}.dmg"
653         rm -f "${DMGNAME}.sparseimage"
654 }
655
656 build_lyx
657 convert_universal
658 copy_dictionaries
659
660 # ------------------------------
661 # Building distribution packages
662 # ------------------------------
663
664 test -n "${LyxAppZip}" && (
665         cd "${LyxAppPrefix}" && zip -r "${LyxAppZip}" .
666 )
667
668 test -n "${DMGLocation}" && (
669         make_dmg "${DMGLocation}"
670         if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt4_deployment}" ]; then
671                 rm -f "${DMGLocation}/${DMGNAME}+qt4.dmg"
672                 mv "${DMGLocation}/${DMGNAME}.dmg" "${DMGLocation}/${DMGNAME}+qt4.dmg"
673                 for libnm in ${QtLibraries} ; do
674                         fwdir=`framework_name "$libnm"`
675                         rm -rf "${LyxAppDir}.app/Contents/${fwdir}"
676                 done
677                 make_dmg "${DMGLocation}"
678         fi
679 )