]> git.lyx.org Git - features.git/blob - development/LyX-Mac-binary-release.sh
f0a2bfb48c47f02a9be63fd4a58d10e504f9f151
[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 # latest changes by Stephan Witt
8 # Last modified: February 2020
9
10 QtAPI=${QtAPI:-"-cocoa"}
11 QtVersion=${QtVersion:-"4.6.3"}
12 QtSourceVersion=${QtSourceVersion:-"qt-everywhere-opensource-src-${QtVersion}"}
13 QtBuildSubDir="qt-${QtVersion}-build${QtAPI}"
14 QtConfigureOptions=${QtConfigureOptions:-"-release"}
15 QtSkipComponents=${QtSkipComponents:-"qtconnectivity qtscript qtquickcontrols qtmultimedia qtvirtualkeyboard qtwayland qtwebengine"}
16 LibMagicVersion=${LibMagicVersion:-"5.19"}
17 LibMagicSource="file-${LibMagicVersion}"
18 LibMagicLibrary="libmagic.1.dylib"
19
20 ASpellVersion=${ASpellVersion:-"0.60.6.1"}
21 ASpellSource="aspell-${ASpellVersion}"
22 ASpellLibrary="libaspell.15.dylib"
23
24 HunSpellVersion=${HunSpellVersion:-"1.3.3"}
25 HunSpellSource="hunspell-${HunSpellVersion}"
26 HunSpellLibrary="libhunspell-1.3.0.dylib"
27
28 unset DYLD_LIBRARY_PATH LD_LIBRARY_PATH
29
30 # Prerequisite:
31 # * a decent checkout of LyX sources (probably you have it already)
32 # * Qt - build with shared or static libraries for the used platforms (default: i386 and ppc)
33 #   or - an unpacked source tree of Qt in $QTSOURCEDIR or in the sibling directory (variable QtSourceVersion)
34 # * for aspell support:
35 #   the aspell sources placed in a sibling directory (variable ASpellSource)
36 # * for hunspell support:
37 #   the hunspell sources placed in a sibling directory (variable HunSpellSource)
38 # * for dictionary deployment (only hunspell dicts and mythes thesauri are deployed per default):
39 #   - aspell:   the dictionary files of macports (in /opt/local/share/aspell and /opt/local/lib/aspell-0.60)
40 #   - hunspell: the dictionary files in the sibling directory dictionaries/dicts
41 #   - mythes:   the data and idx files in the sibling directory dictionaries/thes
42 # * for magic file type detection support:
43 #   the libmagic sources placed in a sibling directory (variable LibMagicSource)
44
45 LyXConfigureOptions="--enable-warnings --enable-optimization=-Os --with-x=no"
46 LyXConfigureOptions="${LyXConfigureOptions} --disable-stdlib-debug"
47 AspellConfigureOptions="--enable-warnings --enable-optimization=-O0 --enable-debug --disable-nls --enable-compile-in-filters --disable-pspell-compatibility"
48 HunspellConfigureOptions="--with-warnings --disable-nls --disable-static"
49
50 QtMajorVersion=qt4
51 QtConfigureOptions="${QtConfigureOptions} -opensource -silent -shared -confirm-license"
52 # stupid special case...
53 case "${QtVersion}:${QtAPI}" in
54 4.6*:-carbon)
55         QtConfigureOptions="${QtConfigureOptions} -fast -no-exceptions"
56         QtConfigureOptions="${QtConfigureOptions} -no-webkit -no-qt3support -no-javascript-jit -no-dbus"
57         QtConfigureOptions="${QtConfigureOptions} -nomake examples -nomake demos -nomake docs -nomake tools"
58         for arch in ${ARCH_LIST} ; do
59                 QTARCHS="${QTARCHS} -arch ${arch}"
60         done
61         ;;
62 5.0*)
63         QtConfigureOptions="${QtConfigureOptions} -fast -no-strip"
64         QtConfigureOptions="${QtConfigureOptions} -no-javascript-jit -no-pkg-config"
65         QtConfigureOptions="${QtConfigureOptions} -nomake examples -nomake demos -nomake docs -nomake tools"
66         QtMajorVersion=qt5
67         ;;
68 5.6*|5.7*)
69         QtConfigureOptions="${QtConfigureOptions} -no-strip"
70         QtConfigureOptions="${QtConfigureOptions} -no-kms -no-pkg-config"
71         QtConfigureOptions="${QtConfigureOptions} -nomake examples -nomake tools"
72         QtConfigureOptions="${QtConfigureOptions} -skip qtconnectivity -skip qtscript"
73         QtConfigureOptions="${QtConfigureOptions} -skip qtquickcontrols"
74         QtConfigureOptions="${QtConfigureOptions} -skip qttools"
75         QtConfigureOptions="${QtConfigureOptions} -skip qtdeclarative"
76         QtMajorVersion=qt5
77         ;;
78 5.*)
79         QtConfigureOptions="${QtConfigureOptions} -no-strip"
80         QtConfigureOptions="${QtConfigureOptions} -no-kms -no-pkg-config"
81         QtConfigureOptions="${QtConfigureOptions} -nomake examples -nomake tools"
82         for component in ${QtSkipComponents} ; do
83                 QtConfigureOptions="${QtConfigureOptions} -skip ${component}"
84         done
85         QtMajorVersion=qt5
86         ;;
87 *)
88         QtConfigureOptions="${QtConfigureOptions} -fast -no-exceptions"
89         QtConfigureOptions="${QtConfigureOptions} -no-webkit -no-qt3support -no-javascript-jit -no-dbus"
90         QtConfigureOptions="${QtConfigureOptions} -nomake examples -nomake demos -nomake docs -nomake tools"
91         QtConfigureOptions="${QtConfigureOptions} ${QtAPI}"
92         for arch in ${ARCH_LIST} ; do
93                 QTARCHS="${QTARCHS} -arch ${arch}"
94         done
95         ;;
96 esac
97
98 aspell_dictionaries="no"
99 hunspell_dictionaries="yes"
100
101 libmagic_deployment="yes"
102 aspell_deployment="yes"
103 hunspell_deployment="yes"
104 thesaurus_deployment="yes"
105
106 qt_deployment="yes"
107
108 # auto detect Xcode location
109 DEVELOPER_SDKS=$(dirname $(xcrun --show-sdk-path))
110 if [ -n "${DEVELOPER_SDKS}" ]; then
111         XCODE_DEVELOPER=$(dirname $(dirname $(xcrun --show-sdk-platform-path)))
112         MACOSX_DEPLOYMENT_TARGET="10.7" # Lion support is default
113         SDKROOT="${DEVELOPER_SDKS}/MacOSX$(xcrun --show-sdk-version).sdk" # use default SDK
114 elif [ -d "/Developer/SDKs" ]; then
115         DEVELOPER_SDKS="/Developer/SDKs"
116         XCODE_DEVELOPER="/Developer"
117         MACOSX_DEPLOYMENT_TARGET="10.4" # Tiger support is default
118         SDKROOT="${DEVELOPER_SDKS}/MacOSX10.5.sdk" # Leopard build is default
119 fi
120
121 # detection of script home
122 LyxSourceDir=$(dirname "$0")
123 if [ ! -d "${LyxSourceDir}" ]; then
124         echo Missing LyX source directory.
125         exit 2
126 fi
127 case "${LyxSourceDir}" in
128 /*/development)
129         LyxSourceDir=$(dirname "${LyxSourceDir}")
130         ;;
131 /*)
132         ;;
133 */development|development)
134         LyxSourceDir=$(dirname "${LyxSourceDir}")
135         LyxSourceDir=$(cd "${LyxSourceDir}";pwd)
136         ;;
137 *)
138         LyxSourceDir=$(cd "${LyxSourceDir}";pwd)
139         ;;
140 esac
141
142 usage() {
143         echo "*" Build script for LyX on Mac OS X
144         echo
145         echo Optional arguments:
146         echo " --aspell-deployment=yes|no ." default yes
147         echo " --with-qt-frameworks=yes|no." default no
148         echo " --qt-deployment=yes|no ....." default yes
149         echo " --with-macosx-target=TARGET " default 10.4 "(Tiger)"
150         echo " --with-sdkroot=SDKROOT ....." default 10.5 "(Leopard)"
151         echo " --with-arch=ARCH ..........." default ppc,i386
152         echo " --with-build-path=PATH ....." default \${lyx-src-dir}/../lyx-build
153         echo " --with-dmg-location=PATH ..." default \${build-path}
154         echo " --with-binary-strip=yes ...." default no
155         echo
156         echo "All other arguments with -- are passed to configure"
157         echo "including the defaults: ${LyXConfigureOptions}"
158         case "${1}" in
159         --help=short)
160                 ;;
161         *)
162                 if [ -x "${LyxSourceDir}/configure" ]; then
163                         echo
164                         echo "*" Configure options of LyX
165                         echo
166                         "${LyxSourceDir}/configure" --help
167                 fi
168         esac
169         exit 0
170 }
171
172 NCPU=$(sysctl -n hw.ncpu)
173 NCPU=$((NCPU / 2))
174 if [ $NCPU -gt 1 ]; then
175         MAKEJOBS=-j${NCPU}
176 fi
177
178 while [ $# -gt 0 ]; do
179         case "${1}" in
180         --with-qt-frameworks=*)
181                 configure_qt_frameworks=$(echo ${1}|cut -d= -f2)
182                 if [ "$configure_qt_frameworks" = "yes" ]; then
183                         unset QTDIR
184                         qt_deployment="no"
185                 fi
186                 shift
187                 ;;
188         --with-qt-dir=*)
189                 QTDIR=$(echo ${1}|cut -d= -f2)
190                 shift
191                 ;;
192         --with-macosx-target=*)
193                 MACOSX_DEPLOYMENT_TARGET=$(echo ${1}|cut -d= -f2)
194                 shift
195                 ;;
196         --with-sdkroot=*)
197                 SDKROOT=$(echo ${1}|cut -d= -f2)
198                 case "${SDKROOT}" in
199                 10.4)
200                         SDKROOT="${DEVELOPER_SDKS}/MacOSX10.4u.sdk"
201                         export CC=gcc-4.0
202                         export OBJC=gcc-4.0
203                         export CXX=g++-4.0
204                         ;;
205                 *)
206                         SDKROOT="${DEVELOPER_SDKS}/MacOSX${SDKROOT}.sdk"
207                         if [ ! -d "${SDKROOT}" ]; then
208                                 echo Invalid SDKROOT given: "${SDKROOT}"
209                                 usage --help=short
210                         fi
211                         ;;
212                 esac
213                 shift
214                 ;;
215         --codesign-identity=*)
216                 CODESIGN_IDENTITY=$(echo "${1}"|cut -d= -f2)
217                 shift
218                 ;;
219         --libmagic-deployment=*)
220                 libmagic_deployment=$(echo ${1}|cut -d= -f2)
221                 shift
222                 ;;
223         --aspell-deployment=*)
224                 aspell_deployment=$(echo ${1}|cut -d= -f2)
225                 aspell_dictionaries=$aspell_deployment
226                 shift
227                 ;;
228         --hunspell-deployment=*)
229                 hunspell_deployment=$(echo ${1}|cut -d= -f2)
230                 hunspell_dictionaries=$hunspell_deployment
231                 shift
232                 ;;
233         --thesaurus-deployment=*)
234                 thesaurus_deployment=$(echo ${1}|cut -d= -f2)
235                 shift
236                 ;;
237         --qt-deployment=*)
238                 qt_deployment=$(echo ${1}|cut -d= -f2)
239                 shift
240                 ;;
241         --with-arch=*)
242                 ARCH=$(echo ${1}|cut -d= -f2|tr ',' ' ')
243                 ARCH_LIST="${ARCH_LIST} ${ARCH}"
244                 shift
245                 ;;
246         --with-dmg-location=*)
247                 DMGLocation=$(echo ${1}|cut -d= -f2)
248                 shift
249                 ;;
250         --with-binary-strip=yes)
251                 strip="-strip"
252                 shift
253                 ;;
254         --with-build-path=*)
255                 LyxBuildDir=$(echo ${1}|cut -d= -f2)
256                 shift
257                 ;;
258         --with-util-dir=*)
259                 LyXUtilitiesDir=$(echo ${1}|cut -d= -f2)
260                 shift
261                 ;;
262         --help|--help=*)
263                 usage "${1}"
264                 ;;
265         --without-aspell)
266                 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
267                 aspell_deployment="no"
268                 shift
269                 ;;
270         --without-hunspell)
271                 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
272                 hunspell_deployment="no"
273                 shift
274                 ;;
275         --only-qt*=*)
276                 QtOnlyPackage=$(echo ${1}|cut -d= -f2)
277                 shift
278                 ;;
279         --only-package=*)
280                 LyxOnlyPackage=$(echo ${1}|cut -d= -f2)
281                 shift
282                 ;;
283         --enable-cxx11)
284                 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
285                 EnableCXX11="--enable-cxx11"
286                 shift
287                 ;;
288         --*)
289                 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
290                 shift
291                 ;;
292         *)
293                 break
294                 ;;
295         esac
296 done
297
298 if [ "${configure_qt_frameworks}" != "yes" ]; then
299         QtInstallDir=${QTDIR:-"/opt/qt4"}
300 fi
301
302 ARCH_LIST=${ARCH_LIST:-"ppc i386"}
303
304 aspellstrip=
305
306 LyxBuildDir=${LyxBuildDir:-$(dirname "${LyxSourceDir}")/lyx-build}
307 DMGLocation=${DMGLocation:-"${LyxBuildDir}"}
308
309 LyXUtilitiesDir=${LyXUtilitiesDir:-"${LyxBuildDir}"/utilities}
310
311 LibMagicSourceDir=${LIBMAGICDIR:-$(dirname "${LyxSourceDir}")/${LibMagicSource}}
312 LibMagicBuildDir="${LyxBuildDir}"/"${LibMagicSource}"
313 LibMagicInstallDir=${LibMagicInstallDir:-"${LyXUtilitiesDir}"}
314 LibMagicInstallHdr="${LibMagicInstallDir}/include/magic.h"
315
316 ASpellSourceDir=${ASPELLDIR:-$(dirname "${LyxSourceDir}")/${ASpellSource}}
317 ASpellBuildDir="${ASpellSourceDir}"
318 ASpellInstallDir=${ASpellInstallDir:-"${LyXUtilitiesDir}"}
319 ASpellInstallHdr="${ASpellInstallDir}/include/aspell.h"
320
321 HunSpellSourceDir=${HUNSPELLDIR:-$(dirname "${LyxSourceDir}")/${HunSpellSource}}
322 HunSpellBuildDir="${HunSpellSourceDir}"
323 HunSpellInstallDir=${HunSpellInstallDir:-"${LyXUtilitiesDir}"}
324 HunSpellInstallHdr="${HunSpellInstallDir}/include/hunspell/hunspell.h"
325
326 QtSourceDir=${QTSOURCEDIR:-$(dirname "${LyxSourceDir}")/${QtSourceVersion}}
327 QtBuildDir=${QtBuildDir:-"${LyxBuildDir}"/${QtBuildSubDir:-"qt-build"}}
328
329 DictionarySourceDir=${DICTIONARYDIR:-$(dirname "${LyxSourceDir}")/dictionaries}
330 DocumentationDir=$(dirname "${LyxSourceDir}")/Documents
331 DmgBackground="${LyxSourceDir}"/development/MacOSX/dmg-background.png
332
333 if [ -z "${LyXVersion}" ]; then
334         LyXVersion=$(grep AC_INIT "${LyxSourceDir}"/configure.ac | cut -d, -f2 | tr -d " []()")
335 fi
336 LyXVersionSuffix=${LyXVersionSuffix:-$(echo "${LyXVersion}" | cut -d. -f1-2)}
337 case "${LyXVersion}" in
338 *dev*)
339         LyXGitCommitHash=$(cd "${LyxSourceDir}" ; git log -1 --pretty=format:%h)
340         ;;
341 esac
342
343 LyxName="LyX"
344 LyxBase="${LyxName}-${LyXVersion}"
345 LyxApp="${LyxBase}.app"
346 LyxAppDir="${LyxBuildDir}"/"${LyxBase}"
347 LyxBuildDir="${LyxAppDir}.build"
348 LyxAppPrefix="${LyxAppDir}.app"
349 # if zip file is needed... remove the comment sign
350 #LyxAppZip="${LyxAppPrefix}.zip"
351
352 # ---------------------------------
353 # DON'T MODIFY ANYTHING BELOW HERE!
354 # ---------------------------------
355
356 # don't change order here...
357 case "${QtVersion}" in
358 5.0.*|5.1.*)
359         QtLibraries=${QtLibraries:-"QtSvg QtXml QtPrintSupport QtWidgets QtGui QtNetwork QtConcurrent QtCore"}
360         QtFrameworkVersion="5"
361         ;;
362 5.12.*)
363         QtLibraries=${QtLibraries:-"QtDbus QtSvg QtXml QtPrintSupport QtMacExtras QtWidgets QtGui QtNetwork QtConcurrent QtCore"}
364         QtFrameworkVersion="5"
365         ;;
366 5*)
367         QtLibraries=${QtLibraries:-"QtSvg QtXml QtPrintSupport QtMacExtras QtWidgets QtGui QtNetwork QtConcurrent QtCore"}
368         QtFrameworkVersion="5"
369         ;;
370 *)
371         QtLibraries=${QtLibraries:-"QtSvg QtXml QtGui QtNetwork QtCore"}
372         QtFrameworkVersion="4"
373         ;;
374 esac
375
376 DMGNAME="${LyxBase}${LyXGitCommitHash:+-}${LyXGitCommitHash}"
377 DMGSIZE="550m"
378
379 # Check for existing SDKs
380 SDKs=$(echo ${DEVELOPER_SDKS}/MacOSX10*sdk)
381 case $SDKs in
382 *${SDKROOT}*)
383         ;;
384 *10.6*)
385         MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"10.5"}; export MACOSX_DEPLOYMENT_TARGET
386         case "${MACOSX_DEPLOYMENT_TARGET}" in
387         10.6)
388                 SDKROOT="${DEVELOPER_SDKS}/MacOSX10.6.sdk"; export SDKROOT
389                 ;;
390         10.5|10.4)
391                 SDKROOT=${SDKROOT:-"${DEVELOPER_SDKS}/MacOSX10.5.sdk"}; export SDKROOT
392                 ;;
393         esac
394         ;;
395 *10.5*)
396         MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"10.4"}; export MACOSX_DEPLOYMENT_TARGET
397         SDKROOT=${SDKROOT:-"${DEVELOPER_SDKS}/MacOSX10.5.sdk"}; export SDKROOT
398         ;;
399 *)
400         echo Unknown or missing SDK for Mac OS X.
401         exit 1
402         ;;
403 esac
404 MYCFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}"
405 MYLDFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}"
406
407 build_qt() {
408         echo Build Qt library ${QtSourceDir}
409         if [ "${QtInstallDir}" = "${QtBuildDir}" ]; then
410                 echo Bad install directory for Qt.
411                 echo Must be different from build directory "${QtBuildDir}".
412                 exit 1
413         fi
414         (
415                 mkdir -p "${QtBuildDir}" && cd "${QtBuildDir}"
416                 echo configure options:
417                 echo ${QtConfigureOptions} ${QTARCHS} -prefix "${QtInstallDir}"
418                 "${QtSourceDir}"/configure ${QtConfigureOptions} ${QTARCHS} -prefix "${QtInstallDir}"
419                 make -j1 && make -j1 install
420         )
421         if [ -d "${QtInstallDir}" -a ! -f "${QtInstallDir}"/include/QtCore ]; then
422                 cd "${QtInstallDir}" && (
423                         mkdir -p include
424                         cd include
425                         for libnm in ${QtLibraries} ; do
426                                 test -d ${libnm} -o -L ${libnm} || \
427                                 ( ln -s ../lib/${libnm}.framework/Headers ${libnm} && echo Link to framework ${libnm} )
428                         done
429                 )
430         fi
431 }
432
433 case ${QtOnlyPackage:-"no"} in
434 y*)
435         build_qt
436         exit 0
437         ;;
438 *)
439         if [ "${configure_qt_frameworks}" != "yes" -a -d "${QtSourceDir}" -a ! \( -d "${QtBuildDir}" -a -d "${QtInstallDir}" \) ]; then
440                 build_qt
441         fi
442         ;;
443 esac
444
445 if [ -d "${LibMagicSourceDir}" -a ! -f "${LibMagicInstallHdr}" ]; then
446         # we have a private libmagic (file(1)) source tree at hand...
447         # so let's build and install it
448         if [ -z "${LibMagicVersion}" ]; then
449                 LibMagicVersion=$(grep AC_INIT "${LibMagicSourceDir}"/configure.ac | cut -d, -f2|tr -d " []()")
450         fi
451
452         LibMagicName="LibMagic"
453         LibMagicBase="${LibMagicName}-${LibMagicVersion}"
454
455         echo Build libmagic library ${LibMagicBase}
456         echo configure options:
457         echo --prefix="${LibMagicInstallDir}" ${LibMagicConfigureOptions}
458
459         mkdir -p "${LibMagicBuildDir}" && cd "${LibMagicBuildDir}"
460
461         # ----------------------------------------
462         # Build LibMagic for different architectures
463         # ----------------------------------------
464         FILE_LIST="${LibMagicLibrary}"
465
466         for arch in ${ARCH_LIST} ; do
467                 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"; export CPPFLAGS
468                 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYLDFLAGS}"; export LDFLAGS
469                 "${LibMagicSourceDir}/configure"\
470                         --prefix="${LibMagicInstallDir}"\
471                         ${LibMagicConfigureOptions}
472                 make && make install${strip}
473                 for file in ${FILE_LIST} ; do
474                         if [ -f "${LibMagicInstallDir}"/lib/${file} ]; then
475                                 mv "${LibMagicInstallDir}"/lib/${file}\
476                                         "${LibMagicInstallDir}"/lib/${file}-${arch} 
477                         else
478                                 echo Cannot build and install LibMagic for ${arch}.
479                                 exit 1
480                         fi
481                 done
482         done
483         # -------------------------
484         # Create universal binaries
485         # -------------------------
486         for file in ${FILE_LIST} ; do
487                 OBJ_LIST=
488                 for arch in ${ARCH_LIST} ; do
489                         OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
490                 done
491                 (
492                         cd "${LibMagicInstallDir}"
493                         lipo -create ${OBJ_LIST} -o lib/${file}
494                         # check for the "missing link"...
495                         test -f lib/libmagic.dylib || (cd lib ; ln -s "${LibMagicLibrary}" libmagic.dylib)
496                 )
497         done
498         # --------
499         # Clean up
500         # --------
501         for arch in ${ARCH_LIST} ; do
502                 rm -f "${LibMagicInstallDir}"/lib/*-${arch}
503         done
504 fi
505
506 if [ -d "${HunSpellSourceDir}" -a ! -f "${HunSpellInstallHdr}" ]; then
507         # we have a private HunSpell source tree at hand...
508         # so let's build and install it
509         if [ -z "${HunSpellVersion}" ]; then
510                 HunSpellVersion=$(grep AC_INIT "${HunSpellSourceDir}"/configure.ac | cut -d, -f2|tr -d " []()")
511         fi
512
513         HunSpellName="Hunspell"
514         HunSpellBase="${HunSpellName}-${HunSpellVersion}"
515
516         echo Build hunspell library ${HunSpellBase}
517         echo configure options:
518         echo --prefix="${HunSpellInstallDir}" ${HunspellConfigureOptions}
519
520         mkdir -p "${HunSpellBuildDir}" && cd "${HunSpellBuildDir}"
521
522         # ----------------------------------------
523         # Build HunSpell for different architectures
524         # ----------------------------------------
525         FILE_LIST="${HunSpellLibrary}"
526
527         for arch in ${ARCH_LIST} ; do
528                 make distclean
529                 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"; export CPPFLAGS
530                 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYLDFLAGS}"; export LDFLAGS
531                 "${HunSpellSourceDir}/configure"\
532                         --prefix="${HunSpellInstallDir}"\
533                         ${HunspellConfigureOptions}
534                 make && make install${strip}
535                 for file in ${FILE_LIST} ; do
536                         if [ -f "${HunSpellInstallDir}"/lib/${file} ]; then
537                                 mv "${HunSpellInstallDir}"/lib/${file}\
538                                         "${HunSpellInstallDir}"/lib/${file}-${arch} 
539                         else
540                                 echo Cannot build and install HunSpell for ${arch}.
541                                 exit 1
542                         fi
543                 done
544         done
545         # -------------------------
546         # Create universal binaries
547         # -------------------------
548         for file in ${FILE_LIST} ; do
549                 OBJ_LIST=
550                 for arch in ${ARCH_LIST} ; do
551                         OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
552                 done
553                 (
554                         cd "${HunSpellInstallDir}"
555                         lipo -create ${OBJ_LIST} -o lib/${file}
556                         # check for the "missing link"...
557                         test -f lib/libhunspell.dylib || (cd lib ; ln -s "${HunSpellLibrary}" libhunspell.dylib)
558                 )
559         done
560         # --------
561         # Clean up
562         # --------
563         for arch in ${ARCH_LIST} ; do
564                 rm -f "${HunSpellInstallDir}"/lib/*-${arch}
565         done
566 fi
567
568 if [ -d "${ASpellSourceDir}" -a ! -f "${ASpellInstallHdr}" -a "yes" = "${aspell_deployment}" ]; then
569         # we have a private ASpell source tree at hand...
570         # so let's build and install it
571         if [ -z "${ASpellVersion}" ]; then
572                 ASpellVersion=$(grep AC_INIT "${ASpellSourceDir}"/configure.ac | cut -d, -f2|tr -d " []()")
573         fi
574
575         ASpellName="Aspell"
576         ASpellBase="${ASpellName}-${ASpellVersion}"
577
578         echo Build aspell library ${ASpellBase}
579         echo configure options:
580         echo --prefix="${ASpellInstallDir}" ${AspellConfigureOptions}
581
582         # ASpell builds inplace only :(
583         cd "${ASpellSourceDir}"
584
585         # ----------------------------------------
586         # Build ASpell for different architectures
587         # ----------------------------------------
588         FILE_LIST="${ASpellLibrary}"
589
590         for arch in ${ARCH_LIST} ; do
591                 make distclean
592                 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"; export CPPFLAGS
593                 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYLDFLAGS}"; export LDFLAGS
594                 CXXFLAGS=-g "${ASpellSourceDir}/configure"\
595                         --prefix="${ASpellInstallDir}"\
596                         ${AspellConfigureOptions}
597                 make && make install${aspellstrip}
598                 for file in ${FILE_LIST} ; do
599                         if [ -f "${ASpellInstallDir}"/lib/${file} ]; then
600                                 mv "${ASpellInstallDir}"/lib/${file}\
601                                         "${ASpellInstallDir}"/lib/${file}-${arch} 
602                         else
603                                 echo Cannot build and install ASpell for ${arch}.
604                                 exit 1
605                         fi
606                 done
607         done
608         # -------------------------
609         # Create universal binaries
610         # -------------------------
611         for file in ${FILE_LIST} ; do
612                 OBJ_LIST=
613                 for arch in ${ARCH_LIST} ; do
614                         OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
615                 done
616                 (
617                         cd "${ASpellInstallDir}"
618                         lipo -create ${OBJ_LIST} -o lib/${file}
619                 )
620         done
621         # --------
622         # Clean up
623         # --------
624         for arch in ${ARCH_LIST} ; do
625                 rm -f "${ASpellInstallDir}"/lib/*-${arch}
626         done
627 fi
628
629
630 framework_name() {
631         echo "Frameworks/${1}.framework"
632 }
633
634 LYX_FILE_LIST="lyx lyxclient tex2lyx lyxconvert"
635 BUNDLE_PATH="Contents/MacOS"
636 LYX_BUNDLE_PATH="${LyxAppPrefix}/${BUNDLE_PATH}"
637
638 build_lyx() {
639         # Clear Output
640         if [ -n "${LyxAppZip}" -a -f "${LyxAppZip}" ]; then rm "${LyxAppZip}"; fi
641         if [ -d "${LyxAppPrefix}" ]; then rm -rf "${LyxAppPrefix}"; fi
642
643         case "${EnableCXX11}" in
644         "--enable-cxx11")
645                 export CC=cc
646                 export CXX="c++ -stdlib=libc++"
647                 export CXXFLAGS=-std=c++11
648                 ;;
649         esac
650
651         # -------------------------------------
652         # Automate configure check
653         # -------------------------------------
654         if [ ! -f "${LyxSourceDir}"/configure -o "${LyxSourceDir}"/configure -ot "${LyxSourceDir}"/configure.ac ]; then
655                 ( cd "${LyxSourceDir}" && sh autogen.sh )
656         else
657                 find "${LyxSourceDir}" -name Makefile.am -print | while read file ; do
658                         dname=$(dirname "$file")
659                         if [ -f "$dname/Makefile.in" -a "$dname/Makefile.in" -ot "$file" ]; then
660                                 ( cd "${LyxSourceDir}" && sh autogen.sh )
661                                 break
662                         fi
663                 done
664         fi
665         # -------------------------------------
666         # Build LyX for different architectures
667         # -------------------------------------
668
669         if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_deployment}" ]; then
670                 ConfigureExtraInc="--with-extra-inc=${ASpellInstallDir}/include"
671                 ConfigureExtraLib="--with-extra-lib=${ASpellInstallDir}/lib"
672         fi
673
674         if [ -d "${HunSpellInstallDir}" -a "yes" = "${hunspell_deployment}" ]; then
675                 HunSpellFramework=$(framework_name Hunspell)
676                 HunSpellFramework=$(basename "${HunSpellFramework}")
677                 ConfigureExtraInc="--with-extra-inc=${HunSpellInstallDir}/include"
678                 ConfigureExtraLib="--with-extra-lib=${HunSpellInstallDir}/lib"
679                 # LyXConfigureOptions="${LyXConfigureOptions} --with-hunspell-framework=${HunSpellFramework}"
680         fi
681         LyXConfigureOptions="${LyXConfigureOptions} ${ConfigureExtraInc}"
682         LyXConfigureOptions="${LyXConfigureOptions} ${ConfigureExtraLib}"
683
684         for arch in ${ARCH_LIST} ; do
685
686                 if [ -d "${LyxBuildDir}" ];  then rm -r "${LyxBuildDir}"; fi
687                 mkdir -p "${LyxBuildDir}" && cd "${LyxBuildDir}"
688
689                 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"
690                 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYLDFLAGS}"
691
692                 if [ "$configure_qt_frameworks" = "yes" ]; then
693                         export QT_CORE_CFLAGS="-FQtCore"
694                         export QT_CORE_LIBS="-framework QtCore"
695                         export QT_FRONTEND_CFLAGS="-FQtGui"
696                         export QT_FRONTEND_LIBS="-framework QtGui"
697                         CPPFLAGS="${CPPFLAGS} -I${SDKROOT}/Library/Frameworks/QtCore.framework/Headers"
698                         CPPFLAGS="${CPPFLAGS} -I${SDKROOT}/Library/Frameworks/QtGui.framework/Headers"
699                 fi
700
701                 echo LDFLAGS="${LDFLAGS}"
702                 export LDFLAGS
703                 echo CPPFLAGS="${CPPFLAGS}"
704                 export CPPFLAGS
705                 echo CONFIGURE_OPTIONS="${LyXConfigureOptions}" ${QtInstallDir:+"--with-qt-dir=${QtInstallDir}"}
706                 "${LyxSourceDir}/configure"\
707                         --prefix="${LyxAppPrefix}" --with-version-suffix="-${LyXVersionSuffix}"\
708                         ${QtInstallDir:+"--with-qt-dir=${QtInstallDir}"} \
709                         ${LyXConfigureOptions}\
710                         --enable-build-type=rel && \
711                 make ${MAKEJOBS} && make install${strip}
712                 for file in ${LYX_FILE_LIST} ; do
713                         if [ -f "${LYX_BUNDLE_PATH}/${file}" ]; then
714                                 mv "${LYX_BUNDLE_PATH}/${file}"\
715                                         "${LYX_BUNDLE_PATH}/${file}-${arch}" 
716                         else
717                                 echo ERROR: Cannot build and install ${file} for ${arch}.
718                                 exit 1
719                         fi
720                 done
721         done
722 }
723
724 content_directory() {
725         target="$1"
726         content=$(dirname "${target}")
727         content=$(dirname "${content}")
728         echo "${content}"
729 }
730
731 installname() {
732                 echo install_name_tool "$@"
733                 install_name_tool "$@" || exit 1
734 }
735
736 private_framework() {
737         fwname="$1" ; shift
738         source="$1" ; shift
739         target="$1" ; shift
740         version=$(echo ${1:-"1.1.1"}.1.1.1 | cut -d. -f1-3) ; shift
741         fwdir=$(framework_name "${fwname}")
742         condir=$(content_directory "${target}")
743         libnm=$(basename "${source}")
744         libid="org.lyx."$(echo "${libnm}" | cut -d. -f1)
745         svrsn=$(echo "${version}" | cut -d. -f1-2)
746         fwvrsn="1"
747         mkdir -p "${condir}/${fwdir}"/Versions/${fwvrsn}/Headers
748         mkdir -p "${condir}/${fwdir}"/Versions/${fwvrsn}/Resources
749         if [ ! -f "${condir}/${fwdir}/Versions/${fwvrsn}/${fwname}" ]; then
750                 cp -p "${source}" "${condir}/${fwdir}/Versions/${fwvrsn}/${fwname}"
751                 for hfile in "$@" ; do
752                         test -f "${hfile}" && cp -p "${hfile}" "${condir}/${fwdir}"/Versions/${fwvrsn}/Headers
753                 done
754                 ln -s ${fwvrsn} "${condir}/${fwdir}/Versions/Current"
755                 ln -s Versions/Current/Headers "${condir}/${fwdir}/Headers"
756                 ln -s Versions/Current/Resources "${condir}/${fwdir}/Resources"
757                 ln -s Versions/Current/"${fwname}" "${condir}/${fwdir}/${fwname}"
758                 installname -id "@executable_path/../${fwdir}/${fwname}" "${condir}/${fwdir}/${fwname}"
759                 if [ -f "${LyxSourceDir}"/development/LyX-Mac-frameworks-template.plist ]; then
760                         cat "${LyxSourceDir}"/development/LyX-Mac-frameworks-template.plist | sed \
761                                 -e "s/@CFBundleExecutable@/${fwname}/" \
762                                 -e "s/@CFBundleIdentifier@/${libid}/" \
763                                 -e "s/@CFBundleShortVersionString@/${svrsn}/" \
764                                 -e "s/@CFBundleVersion@/${version}/" > "${condir}/${fwdir}"/Resources/Info.plist
765                 fi
766         fi
767         installname -change "${source}" "@executable_path/../${fwdir}/${fwname}" "${target}"
768 }
769
770 deploy_qtlibs() {
771         source="${QtInstallDir}"
772         target="$1"
773         version="Versions/${QtFrameworkVersion}/"
774         condir=$(content_directory "${target}")
775         mkdir -p "${condir}/Resources"
776         test -f "${condir}/Resources/qt.conf" || cat - > "${condir}/Resources/qt.conf" <<-EOF
777 [Paths]
778 Plugins = PlugIns
779 Translations = translations
780 EOF
781         if [ ! -d "${condir}/PlugIns" ]; then
782                 mkdir -p "${condir}/PlugIns"
783                 find "${source}/plugins" -name \*.dylib -print | grep -v _debug.dylib | while read libname ; do
784                         echo Copy plugin "${libname}"
785                         dylib=$(basename "${libname}")
786                         dirname=$(dirname "${libname}")
787                         dirname=$(basename "${dirname}")
788                         mkdir -p "${condir}/PlugIns/${dirname}"
789                         cp -p "${libname}" "${condir}/PlugIns/${dirname}"
790                 done
791         fi
792         for libnm in ${QtLibraries} ; do
793                 fwdir=$(framework_name "$libnm")
794                 dirname=$(dirname "${fwdir}")
795                 mkdir -p "${condir}/${dirname}"
796                 dirname=$(basename "${fwdir}")
797                 test -d "${condir}/${fwdir}" || (
798                         echo Copy framework "${source}/lib/"$(basename "${fwdir}")
799                         cp -pR "${source}/lib/"$(basename "${fwdir}") "${condir}/${fwdir}"
800                         rm -f "${condir}/${fwdir}/${version}${libnm}"_debug
801                         installname -id "@executable_path/../${fwdir}/${version}${libnm}" "${condir}/${fwdir}/${version}${libnm}"
802                         find "${condir}/PlugIns" "${condir}/"$(dirname "${fwdir}") -name Headers -prune -o -type f -print | while read filename ; do
803                                 if [ "${filename}" != "${target}" ]; then
804                                         otool -L "${filename}" 2>/dev/null | sort -u | while read library ; do
805                                                 # pattern match for: /path/to/qt/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.6.0, current version 4.6.2)
806                                                 case "${library}" in
807                                                 *@rpath/*"${libnm}"*"("*version*")"*)
808                                                         # echo rpath based name for ${libnm} is ok.
809                                                         ;;
810                                                 *"${libnm}"*"("*version*")"*)
811                                                         installname -change\
812                                                                 "${source}/lib/${dirname}/${version}${libnm}"\
813                                                                 "@executable_path/../${fwdir}/${version}${libnm}"\
814                                                                 "${filename}"
815                                                         ;;
816                                                 esac
817                                         done
818                                 fi
819                         done
820                 )
821                 installname -change\
822                         "${source}/lib/${dirname}/${version}${libnm}"\
823                         "@executable_path/../${fwdir}/${version}${libnm}"\
824                         "${target}"
825         done
826         if [ -d "${source}"/translations ]; then
827                 if [ ! -d "${condir}/translations" ]; then
828                         mkdir -p "${condir}/translations"
829                 fi
830                 echo Copy Qt translations to "${condir}/translations"
831                 cp -p "${source}"/translations/qt_*.qm "${condir}/translations"
832         fi
833 }
834
835 # -------------------------
836 # Create universal binaries
837 # -------------------------
838 convert_universal() {
839         cd "${LyxAppPrefix}"
840         for file in ${LYX_FILE_LIST} ; do
841                 OBJ_LIST=
842                 for arch in ${ARCH_LIST} ; do
843                         if [ -f "${BUNDLE_PATH}/${file}-${arch}" ]; then
844                                 OBJ_LIST="${OBJ_LIST} ${BUNDLE_PATH}/${file}-${arch}"
845                         fi
846                 done
847                 if [ -n "${OBJ_LIST}" ]; then
848                         lipo -create ${OBJ_LIST} -o "${BUNDLE_PATH}/${file}"
849                 fi
850                 if [ -f "${LibMagicInstallDir}/lib/${LibMagicLibrary}" -a "yes" = "${libmagic_deployment}" ]; then
851                         private_framework LibMagic "${LibMagicInstallDir}/lib/${LibMagicLibrary}" "${LYX_BUNDLE_PATH}/${file}" \
852                                 "${LibMagicVersion}" "${LibMagicInstallHdr}"
853                 fi
854                 if [ -f "${ASpellInstallDir}/lib/${ASpellLibrary}" -a "yes" = "${aspell_deployment}" ]; then
855                         private_framework Aspell "${ASpellInstallDir}/lib/${ASpellLibrary}" "${LYX_BUNDLE_PATH}/${file}" \
856                                 "${ASpellVersion}" "${ASpellInstallHdr}"
857                 fi
858                 if [ -f "${HunSpellInstallDir}/lib/${HunSpellLibrary}" -a "yes" = "${hunspell_deployment}" ]; then
859                         private_framework Hunspell "${HunSpellInstallDir}/lib/${HunSpellLibrary}" "${LYX_BUNDLE_PATH}/${file}" \
860                                 "${HunSpellVersion}" "${HunSpellInstallDir}/include/hunspell/"*.hxx "${HunSpellInstallHdr}"
861                 fi
862                 if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt_deployment}" ]; then
863                         deploy_qtlibs "${LYX_BUNDLE_PATH}/${file}"
864                 fi
865                 otool -L "${BUNDLE_PATH}/${file}" | while read reference ; do
866                         case "${reference}" in
867                         *"${LyxBuildDir}"*"("*")")
868                                 echo ERROR: Bad reference to "${reference}" found!!
869                                 ;;
870                         esac
871                 done
872         done
873         for arch in ${ARCH_LIST} ; do
874                 rm -f "${BUNDLE_PATH}"/*-${arch}
875         done
876 }
877
878 # -------------------------
879 # Create code sign signatures
880 # -------------------------
881 code_sign() {
882         target="$1"
883         condir=$(content_directory "${target}"/lyx)
884         appdir=$(dirname "${condir}")
885         # have to sign frameworks first
886         for csitem in \
887                 "${condir}"/Frameworks/Qt*.framework/Versions/${QtFrameworkVersion} \
888                 "${condir}"/Frameworks/*.framework/lib*.dylib \
889                 "${condir}"/PlugIns/*/lib*.dylib \
890                 "${condir}"/Library/Spotlight/* \
891                 "${target}"/inkscape \
892                 "${target}"/maxima \
893                 "${target}"/tex2lyx \
894                 "${target}"/lyxeditor \
895                 "${target}"/lyxconvert \
896                 "${target}"/lyxclient
897         do
898                 codesign --verbose --force --sign "${CODESIGN_IDENTITY}" "${csitem}"
899         done
900
901         /usr/bin/codesign --verbose --force --sign "${CODESIGN_IDENTITY}" "${appdir}" || {
902                 echo Warning: codesign failed with certificate named '"'${CODESIGN_IDENTITY}'"'
903         }
904 }
905
906 deduplicate() {
907         find "$@" -type f -print | while read file ; do
908                 echo $(md5 -q "$file") "$file"
909         done | sort | while read hash file ; do
910                 ppath=$(dirname "$pfile")
911                 path=$(dirname "$file")
912                 if [ "$phash" = "$hash" -a "$ppath" = "$path" ]; then
913                         pname=$(basename "$pfile")
914                         name=$(basename "$file")
915                         cmp -s "$pfile" "$file" && (
916                                 rm "$file"
917                                 cd "$path" && ln -s "$pname" "$name" && echo link for "$file" created
918                         )
919                 fi
920                 phash="$hash"
921                 pfile="$file"
922         done
923 }
924
925 copy_dictionaries() {
926         if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_dictionaries}" ]; then
927                 ASpellResources="${LyxAppPrefix}/Contents/Resources"
928                 # try to reuse macports dictionaries for now
929                 if [ -d /opt/local/lib/aspell-0.60 ]; then ASpellInstallDir=/opt/local ; fi
930                 mkdir -p "${ASpellResources}"
931                 echo Copy Aspell dictionaries from "${ASpellInstallDir}"
932                 mkdir -p "${ASpellResources}"/data "${ASpellResources}"/dicts
933                 cp -p -r "${ASpellInstallDir}/lib/aspell-0.60"/* "${ASpellResources}"/data
934                 cp -p -r "${ASpellInstallDir}/share/aspell"/* "${ASpellResources}"/dicts
935         fi
936         if [ -d "${HunSpellInstallDir}" -a "yes" = "${hunspell_dictionaries}" ]; then
937                 HunSpellResources="${LyxAppPrefix}/Contents/Resources"
938                 if [ -d "${DictionarySourceDir}" ]; then
939                         ( cd "${DictionarySourceDir}" && find dicts -name .svn -prune -o -type f -print | cpio -pmdv "${HunSpellResources}" )
940                         deduplicate "${HunSpellResources}"/dicts
941                 fi
942         fi
943         if [ -d "${DictionarySourceDir}" -a "yes" = "${thesaurus_deployment}" ]; then
944                 MyThesResources="${LyxAppPrefix}/Contents/Resources"
945                 ( cd "${DictionarySourceDir}" && find thes -name .svn -prune -o -type f -print | cpio -pmdv "${MyThesResources}" )
946                 deduplicate "${MyThesResources}"/thes
947         fi
948 }
949
950 set_bundle_display_options() {
951         X_BOUNDS=$2
952         Y_BOUNDS=$3
953         Y_POSITION=$((Y_BOUNDS - 65))
954         Y_BOUNDS=$((Y_BOUNDS + 20))
955         LYX_X_POSITION=$((X_BOUNDS / 4))
956         LYX_Y_POSITION=$Y_POSITION
957         APP_X_POSITION=$((3 * X_BOUNDS / 4))
958         APP_Y_POSITION=$Y_POSITION
959         WITH_DOCUMENTS=$(test -d "${1}/Documents" && echo true || echo false)
960         osascript <<-EOF
961         tell application "Finder"
962         set f to POSIX file ("${1}" as string) as alias
963         tell folder f
964             open
965             tell container window
966                 set toolbar visible to false
967                 set statusbar visible to false
968                 set current view to icon view
969                 delay 1 -- sync
970                 set the bounds to {20, 50, $X_BOUNDS, $Y_BOUNDS}
971             end tell
972             delay 1 -- sync
973             set icon size of the icon view options of container window to 64
974             set arrangement of the icon view options of container window to not arranged
975             if ${WITH_DOCUMENTS} then
976                set position of item "Documents" to {$LYX_X_POSITION,0}
977             end if
978             set position of item "${LyxName}.app" to {$LYX_X_POSITION,$LYX_Y_POSITION}
979             set position of item "Applications" to {$APP_X_POSITION,$APP_Y_POSITION}
980             set background picture of the icon view options\
981                of container window to file "background.png" of folder "Pictures"
982             set the bounds of the container window to {0, 0, $X_BOUNDS, $Y_BOUNDS}
983             update without registering applications
984             delay 5 -- sync
985             close
986         end tell
987         delay 5 -- sync
988     end tell
989 EOF
990 }
991
992 make_dmg() {
993         cd "${1}"
994
995         BGSIZE=$(file "$DmgBackground" | awk -F , '/PNG/{print $2 }' | tr x ' ')
996         BG_W=$(echo ${BGSIZE} | awk '{print $1 }')
997         BG_H=$(echo ${BGSIZE} | awk '{print $2 }')
998
999         rm -f "${DMGNAME}.sparseimage" "${DMGNAME}.dmg"
1000
1001         hdiutil create -type SPARSE -size ${DMGSIZE:-"250m"} -fs HFS+ -volname "${LyxBase}" "${DMGNAME}"
1002         # Unmount currently mounted disk image
1003         mount | grep "${LyxBase}" && umount /Volumes/"${LyxBase}"
1004         test -d /Volumes/"${LyxBase}" && rmdir /Volumes/"${LyxBase}"
1005
1006         # Mount the disk image
1007         DEVICES=$(hdiutil attach "${DMGNAME}.sparseimage" | cut -f 1)
1008
1009         # Obtain device information
1010         DEVICE=$(echo $DEVICES | cut -f 1 -d ' ')
1011         VOLUME=$(mount |grep ${DEVICE} | cut -f 3 -d ' ')
1012
1013         # copy in the application bundle
1014         ditto --hfsCompression "${LyxAppDir}.app" "${VOLUME}/${LyxName}.app"
1015
1016         # copy in background image
1017         mkdir -p "${VOLUME}/Pictures"
1018         ditto --hfsCompression "${DmgBackground}" "${VOLUME}/Pictures/background.png"
1019         # symlink applications
1020         ln -s /Applications/ "${VOLUME}"/Applications
1021         test -d "${DocumentationDir}" && ditto --hfsCompression "${DocumentationDir}" "${VOLUME}"
1022         set_bundle_display_options "${VOLUME}" ${BG_W} ${BG_H}
1023         ${XCODE_DEVELOPER}/Tools/SetFile -a C "${VOLUME}"
1024         mv "${VOLUME}/Pictures" "${VOLUME}/.Pictures"
1025
1026         # Unmount the disk image
1027         hdiutil detach ${DEVICE}
1028
1029         # Convert the disk image to read-only
1030         hdiutil convert "${DMGNAME}.sparseimage" -format UDBZ -o "${DMGNAME}.dmg"
1031         rm -f "${DMGNAME}.sparseimage"
1032 }
1033
1034 # ------------------------------
1035 # Building distribution packages
1036 # ------------------------------
1037
1038 build_package() {
1039         test -n "${LyxAppZip}" && (
1040                 cd "${LyxAppPrefix}" && zip -r "${LyxAppZip}" .
1041         )
1042
1043         DMGARCH=""
1044         for arch in ${ARCH_LIST} ; do
1045                 DMGARCH="${DMGARCH}-${arch}"
1046         done
1047         QtDmgArchSuffix=${QtMajorVersion}${DMGARCH}${QtAPI}.dmg
1048
1049         test -n "${DMGLocation}" && (
1050                 make_dmg "${DMGLocation}"
1051                 if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt_deployment}" ]; then
1052                         rm -f "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1053                         echo move to "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1054                         mv "${DMGLocation}/${DMGNAME}.dmg" "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1055                 fi
1056         )
1057 }
1058
1059 # ------------------------------
1060 # main block
1061 # ------------------------------
1062
1063 if [ ${LyxOnlyPackage:-"no"} = "no" ]; then
1064         build_lyx
1065         convert_universal
1066         test -n "${CODESIGN_IDENTITY}" && code_sign "${LYX_BUNDLE_PATH}"
1067         copy_dictionaries
1068 fi
1069 build_package