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