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