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