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