]> git.lyx.org Git - features.git/blob - development/LyX-Mac-binary-release.sh
6e6546993c75ff2cfd04ad574b50899eddc1d081
[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}/${libnm}" ]; then
750                 cp -p "${source}" "${condir}/${fwdir}/Versions/${fwvrsn}/${libnm}"
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/"${libnm}" "${condir}/${fwdir}/${libnm}"
758                 ln -s Versions/Current/"${libnm}" "${condir}/${fwdir}/${fwname}"
759                 installname -id "@executable_path/../${fwdir}/${libnm}" "${condir}/${fwdir}/${libnm}"
760                 if [ -f "${LyxSourceDir}"/development/LyX-Mac-frameworks-template.plist ]; then
761                         cat "${LyxSourceDir}"/development/LyX-Mac-frameworks-template.plist | sed \
762                                 -e "s/@CFBundleExecutable@/${libnm}/" \
763                                 -e "s/@CFBundleIdentifier@/${libid}/" \
764                                 -e "s/@CFBundleShortVersionString@/${svrsn}/" \
765                                 -e "s/@CFBundleVersion@/${version}/" > "${condir}/${fwdir}"/Resources/Info.plist
766                 fi
767         fi
768         installname -change "${source}" "@executable_path/../${fwdir}/${libnm}" "${target}"
769 }
770
771 deploy_qtlibs() {
772         source="${QtInstallDir}"
773         target="$1"
774         version="Versions/${QtFrameworkVersion}/"
775         condir=$(content_directory "${target}")
776         mkdir -p "${condir}/Resources"
777         test -f "${condir}/Resources/qt.conf" || cat - > "${condir}/Resources/qt.conf" <<-EOF
778 [Paths]
779 Plugins = PlugIns
780 Translations = translations
781 EOF
782         if [ ! -d "${condir}/PlugIns" ]; then
783                 mkdir -p "${condir}/PlugIns"
784                 find "${source}/plugins" -name \*.dylib -print | grep -v _debug.dylib | while read libname ; do
785                         echo Copy plugin "${libname}"
786                         dylib=$(basename "${libname}")
787                         dirname=$(dirname "${libname}")
788                         dirname=$(basename "${dirname}")
789                         mkdir -p "${condir}/PlugIns/${dirname}"
790                         cp -p "${libname}" "${condir}/PlugIns/${dirname}"
791                 done
792         fi
793         for libnm in ${QtLibraries} ; do
794                 fwdir=$(framework_name "$libnm")
795                 dirname=$(dirname "${fwdir}")
796                 mkdir -p "${condir}/${dirname}"
797                 dirname=$(basename "${fwdir}")
798                 test -d "${condir}/${fwdir}" || (
799                         echo Copy framework "${source}/lib/"$(basename "${fwdir}")
800                         cp -pR "${source}/lib/"$(basename "${fwdir}") "${condir}/${fwdir}"
801                         rm -f "${condir}/${fwdir}/${version}${libnm}"_debug
802                         installname -id "@executable_path/../${fwdir}/${version}${libnm}" "${condir}/${fwdir}/${version}${libnm}"
803                         find "${condir}/PlugIns" "${condir}/"$(dirname "${fwdir}") -name Headers -prune -o -type f -print | while read filename ; do
804                                 if [ "${filename}" != "${target}" ]; then
805                                         otool -L "${filename}" 2>/dev/null | sort -u | while read library ; do
806                                                 # pattern match for: /path/to/qt/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.6.0, current version 4.6.2)
807                                                 case "${library}" in
808                                                 *@rpath/*"${libnm}"*"("*version*")"*)
809                                                         # echo rpath based name for ${libnm} is ok.
810                                                         ;;
811                                                 *"${libnm}"*"("*version*")"*)
812                                                         installname -change\
813                                                                 "${source}/lib/${dirname}/${version}${libnm}"\
814                                                                 "@executable_path/../${fwdir}/${version}${libnm}"\
815                                                                 "${filename}"
816                                                         ;;
817                                                 esac
818                                         done
819                                 fi
820                         done
821                 )
822                 installname -change\
823                         "${source}/lib/${dirname}/${version}${libnm}"\
824                         "@executable_path/../${fwdir}/${version}${libnm}"\
825                         "${target}"
826         done
827         if [ -d "${source}"/translations ]; then
828                 if [ ! -d "${condir}/translations" ]; then
829                         mkdir -p "${condir}/translations"
830                 fi
831                 echo Copy Qt translations to "${condir}/translations"
832                 cp -p "${source}"/translations/qt_*.qm "${condir}/translations"
833         fi
834 }
835
836 # -------------------------
837 # Create universal binaries
838 # -------------------------
839 convert_universal() {
840         cd "${LyxAppPrefix}"
841         for file in ${LYX_FILE_LIST} ; do
842                 OBJ_LIST=
843                 for arch in ${ARCH_LIST} ; do
844                         if [ -f "${BUNDLE_PATH}/${file}-${arch}" ]; then
845                                 OBJ_LIST="${OBJ_LIST} ${BUNDLE_PATH}/${file}-${arch}"
846                         fi
847                 done
848                 if [ -n "${OBJ_LIST}" ]; then
849                         lipo -create ${OBJ_LIST} -o "${BUNDLE_PATH}/${file}"
850                 fi
851                 if [ -f "${LibMagicInstallDir}/lib/${LibMagicLibrary}" -a "yes" = "${libmagic_deployment}" ]; then
852                         private_framework LibMagic "${LibMagicInstallDir}/lib/${LibMagicLibrary}" "${LYX_BUNDLE_PATH}/${file}" \
853                                 "${LibMagicVersion}" "${LibMagicInstallHdr}"
854                 fi
855                 if [ -f "${ASpellInstallDir}/lib/${ASpellLibrary}" -a "yes" = "${aspell_deployment}" ]; then
856                         private_framework Aspell "${ASpellInstallDir}/lib/${ASpellLibrary}" "${LYX_BUNDLE_PATH}/${file}" \
857                                 "${ASpellVersion}" "${ASpellInstallHdr}"
858                 fi
859                 if [ -f "${HunSpellInstallDir}/lib/${HunSpellLibrary}" -a "yes" = "${hunspell_deployment}" ]; then
860                         private_framework Hunspell "${HunSpellInstallDir}/lib/${HunSpellLibrary}" "${LYX_BUNDLE_PATH}/${file}" \
861                                 "${HunSpellVersion}" "${HunSpellInstallDir}/include/hunspell/"*.hxx "${HunSpellInstallHdr}"
862                 fi
863                 if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt_deployment}" ]; then
864                         deploy_qtlibs "${LYX_BUNDLE_PATH}/${file}"
865                 fi
866                 otool -L "${BUNDLE_PATH}/${file}" | while read reference ; do
867                         case "${reference}" in
868                         *"${LyxBuildDir}"*"("*")")
869                                 echo ERROR: Bad reference to "${reference}" found!!
870                                 ;;
871                         esac
872                 done
873         done
874         for arch in ${ARCH_LIST} ; do
875                 rm -f "${BUNDLE_PATH}"/*-${arch}
876         done
877 }
878
879 # -------------------------
880 # Create code sign signatures
881 # -------------------------
882 code_sign() {
883         target="$1"
884         condir=$(content_directory "${target}"/lyx)
885         appdir=$(dirname "${condir}")
886         # have to sign frameworks first
887         for csitem in \
888                 "${condir}"/Frameworks/Qt*.framework/Versions/${QtFrameworkVersion} \
889                 "${condir}"/Frameworks/*.framework/lib*.dylib \
890                 "${condir}"/PlugIns/*/lib*.dylib \
891                 "${condir}"/Library/Spotlight/* \
892                 "${target}"/inkscape \
893                 "${target}"/maxima \
894                 "${target}"/tex2lyx \
895                 "${target}"/lyxeditor \
896                 "${target}"/lyxconvert \
897                 "${target}"/lyxclient
898         do
899                 codesign --verbose --force --sign "${CODESIGN_IDENTITY}" "${csitem}"
900         done
901
902         /usr/bin/codesign --verbose --force --sign "${CODESIGN_IDENTITY}" "${appdir}" || {
903                 echo Warning: codesign failed with certificate named '"'${CODESIGN_IDENTITY}'"'
904         }
905 }
906
907 deduplicate() {
908         find "$@" -type f -print | while read file ; do
909                 echo $(md5 -q "$file") "$file"
910         done | sort | while read hash file ; do
911                 ppath=$(dirname "$pfile")
912                 path=$(dirname "$file")
913                 if [ "$phash" = "$hash" -a "$ppath" = "$path" ]; then
914                         pname=$(basename "$pfile")
915                         name=$(basename "$file")
916                         cmp -s "$pfile" "$file" && (
917                                 rm "$file"
918                                 cd "$path" && ln -s "$pname" "$name" && echo link for "$file" created
919                         )
920                 fi
921                 phash="$hash"
922                 pfile="$file"
923         done
924 }
925
926 copy_dictionaries() {
927         if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_dictionaries}" ]; then
928                 ASpellResources="${LyxAppPrefix}/Contents/Resources"
929                 # try to reuse macports dictionaries for now
930                 if [ -d /opt/local/lib/aspell-0.60 ]; then ASpellInstallDir=/opt/local ; fi
931                 mkdir -p "${ASpellResources}"
932                 echo Copy Aspell dictionaries from "${ASpellInstallDir}"
933                 mkdir -p "${ASpellResources}"/data "${ASpellResources}"/dicts
934                 cp -p -r "${ASpellInstallDir}/lib/aspell-0.60"/* "${ASpellResources}"/data
935                 cp -p -r "${ASpellInstallDir}/share/aspell"/* "${ASpellResources}"/dicts
936         fi
937         if [ -d "${HunSpellInstallDir}" -a "yes" = "${hunspell_dictionaries}" ]; then
938                 HunSpellResources="${LyxAppPrefix}/Contents/Resources"
939                 if [ -d "${DictionarySourceDir}" ]; then
940                         ( cd "${DictionarySourceDir}" && find dicts -name .svn -prune -o -type f -print | cpio -pmdv "${HunSpellResources}" )
941                         deduplicate "${HunSpellResources}"/dicts
942                 fi
943         fi
944         if [ -d "${DictionarySourceDir}" -a "yes" = "${thesaurus_deployment}" ]; then
945                 MyThesResources="${LyxAppPrefix}/Contents/Resources"
946                 ( cd "${DictionarySourceDir}" && find thes -name .svn -prune -o -type f -print | cpio -pmdv "${MyThesResources}" )
947                 deduplicate "${MyThesResources}"/thes
948         fi
949 }
950
951 set_bundle_display_options() {
952         X_BOUNDS=$2
953         Y_BOUNDS=$3
954         Y_POSITION=$((Y_BOUNDS - 65))
955         Y_BOUNDS=$((Y_BOUNDS + 20))
956         LYX_X_POSITION=$((X_BOUNDS / 4))
957         LYX_Y_POSITION=$Y_POSITION
958         APP_X_POSITION=$((3 * X_BOUNDS / 4))
959         APP_Y_POSITION=$Y_POSITION
960         WITH_DOCUMENTS=$(test -d "${1}/Documents" && echo true || echo false)
961         osascript <<-EOF
962         tell application "Finder"
963         set f to POSIX file ("${1}" as string) as alias
964         tell folder f
965             open
966             tell container window
967                 set toolbar visible to false
968                 set statusbar visible to false
969                 set current view to icon view
970                 delay 1 -- sync
971                 set the bounds to {20, 50, $X_BOUNDS, $Y_BOUNDS}
972             end tell
973             delay 1 -- sync
974             set icon size of the icon view options of container window to 64
975             set arrangement of the icon view options of container window to not arranged
976             if ${WITH_DOCUMENTS} then
977                set position of item "Documents" to {$LYX_X_POSITION,0}
978             end if
979             set position of item "${LyxName}.app" to {$LYX_X_POSITION,$LYX_Y_POSITION}
980             set position of item "Applications" to {$APP_X_POSITION,$APP_Y_POSITION}
981             set background picture of the icon view options\
982                of container window to file "background.png" of folder "Pictures"
983             set the bounds of the container window to {0, 0, $X_BOUNDS, $Y_BOUNDS}
984             update without registering applications
985             delay 5 -- sync
986             close
987         end tell
988         delay 5 -- sync
989     end tell
990 EOF
991 }
992
993 make_dmg() {
994         cd "${1}"
995
996         BGSIZE=$(file "$DmgBackground" | awk -F , '/PNG/{print $2 }' | tr x ' ')
997         BG_W=$(echo ${BGSIZE} | awk '{print $1 }')
998         BG_H=$(echo ${BGSIZE} | awk '{print $2 }')
999
1000         rm -f "${DMGNAME}.sparseimage" "${DMGNAME}.dmg"
1001
1002         hdiutil create -type SPARSE -size ${DMGSIZE:-"250m"} -fs HFS+ -volname "${LyxBase}" "${DMGNAME}"
1003         # Unmount currently mounted disk image
1004         mount | grep "${LyxBase}" && umount /Volumes/"${LyxBase}"
1005         test -d /Volumes/"${LyxBase}" && rmdir /Volumes/"${LyxBase}"
1006
1007         # Mount the disk image
1008         DEVICES=$(hdiutil attach "${DMGNAME}.sparseimage" | cut -f 1)
1009
1010         # Obtain device information
1011         DEVICE=$(echo $DEVICES | cut -f 1 -d ' ')
1012         VOLUME=$(mount |grep ${DEVICE} | cut -f 3 -d ' ')
1013
1014         # copy in the application bundle
1015         ditto --hfsCompression "${LyxAppDir}.app" "${VOLUME}/${LyxName}.app"
1016
1017         # copy in background image
1018         mkdir -p "${VOLUME}/Pictures"
1019         ditto --hfsCompression "${DmgBackground}" "${VOLUME}/Pictures/background.png"
1020         # symlink applications
1021         ln -s /Applications/ "${VOLUME}"/Applications
1022         test -d "${DocumentationDir}" && ditto --hfsCompression "${DocumentationDir}" "${VOLUME}"
1023         set_bundle_display_options "${VOLUME}" ${BG_W} ${BG_H}
1024         ${XCODE_DEVELOPER}/Tools/SetFile -a C "${VOLUME}"
1025         mv "${VOLUME}/Pictures" "${VOLUME}/.Pictures"
1026
1027         # Unmount the disk image
1028         hdiutil detach ${DEVICE}
1029
1030         # Convert the disk image to read-only
1031         hdiutil convert "${DMGNAME}.sparseimage" -format UDBZ -o "${DMGNAME}.dmg"
1032         rm -f "${DMGNAME}.sparseimage"
1033 }
1034
1035 # ------------------------------
1036 # Building distribution packages
1037 # ------------------------------
1038
1039 build_package() {
1040         test -n "${LyxAppZip}" && (
1041                 cd "${LyxAppPrefix}" && zip -r "${LyxAppZip}" .
1042         )
1043
1044         DMGARCH=""
1045         for arch in ${ARCH_LIST} ; do
1046                 DMGARCH="${DMGARCH}-${arch}"
1047         done
1048         QtDmgArchSuffix=${QtMajorVersion}${DMGARCH}${QtAPI}.dmg
1049
1050         test -n "${DMGLocation}" && (
1051                 make_dmg "${DMGLocation}"
1052                 if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt_deployment}" ]; then
1053                         rm -f "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1054                         echo move to "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1055                         mv "${DMGLocation}/${DMGNAME}.dmg" "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1056                 fi
1057         )
1058 }
1059
1060 # ------------------------------
1061 # main block
1062 # ------------------------------
1063
1064 if [ ${LyxOnlyPackage:-"no"} = "no" ]; then
1065         build_lyx
1066         convert_universal
1067         test -n "${CODESIGN_IDENTITY}" && code_sign "${LYX_BUNDLE_PATH}"
1068         copy_dictionaries
1069 fi
1070 build_package