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