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