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