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