]> git.lyx.org Git - lyx.git/blob - development/LyX-Mac-binary-release.sh
Add missing parts for the creation of the resolution independent multi-image TIFF...
[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.12.*)
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                 "${LyxSourceDir}/configure"\
720                         --prefix="${LyxAppPrefix}" --with-version-suffix="-${LyXVersionSuffix}"\
721                         ${QtInstallDir:+"--with-qt-dir=${QtInstallDir}"} \
722                         ${LyXConfigureOptions}\
723                         --enable-build-type=rel && \
724                 make ${MAKEJOBS} && make install${strip}
725                 for file in ${LYX_FILE_LIST} ; do
726                         if [ -f "${LYX_BUNDLE_PATH}/${file}" ]; then
727                                 mv "${LYX_BUNDLE_PATH}/${file}"\
728                                         "${LYX_BUNDLE_PATH}/${file}-${arch}" 
729                         else
730                                 echo ERROR: Cannot build and install ${file} for ${arch}.
731                                 exit 1
732                         fi
733                 done
734         done
735 }
736
737 content_directory() {
738         target="$1"
739         content=$(dirname "${target}")
740         content=$(dirname "${content}")
741         echo "${content}"
742 }
743
744 installname() {
745                 echo install_name_tool "$@"
746                 install_name_tool "$@" || exit 1
747 }
748
749 private_framework() {
750         fwname="$1" ; shift
751         source="$1" ; shift
752         target="$1" ; shift
753         version=$(echo ${1:-"1.1.1"}.1.1.1 | cut -d. -f1-3) ; shift
754         fwdir=$(framework_name "${fwname}")
755         condir=$(content_directory "${target}")
756         libnm=$(basename "${source}")
757         libid="org.lyx."$(echo "${libnm}" | cut -d. -f1)
758         svrsn=$(echo "${version}" | cut -d. -f1-2)
759         fwvrsn="1"
760         mkdir -p "${condir}/${fwdir}"/Versions/${fwvrsn}/Headers
761         mkdir -p "${condir}/${fwdir}"/Versions/${fwvrsn}/Resources
762         if [ ! -f "${condir}/${fwdir}/Versions/${fwvrsn}/${fwname}" ]; then
763                 cp -p "${source}" "${condir}/${fwdir}/Versions/${fwvrsn}/${fwname}"
764                 for hfile in "$@" ; do
765                         test -f "${hfile}" && cp -p "${hfile}" "${condir}/${fwdir}"/Versions/${fwvrsn}/Headers
766                 done
767                 ln -s ${fwvrsn} "${condir}/${fwdir}/Versions/Current"
768                 ln -s Versions/Current/Headers "${condir}/${fwdir}/Headers"
769                 ln -s Versions/Current/Resources "${condir}/${fwdir}/Resources"
770                 ln -s Versions/Current/"${fwname}" "${condir}/${fwdir}/${fwname}"
771                 installname -id "@executable_path/../${fwdir}/${fwname}" "${condir}/${fwdir}/${fwname}"
772                 if [ -f "${LyxSourceDir}"/development/LyX-Mac-frameworks-template.plist ]; then
773                         cat "${LyxSourceDir}"/development/LyX-Mac-frameworks-template.plist | sed \
774                                 -e "s/@CFBundleExecutable@/${fwname}/" \
775                                 -e "s/@CFBundleIdentifier@/${libid}/" \
776                                 -e "s/@CFBundleShortVersionString@/${svrsn}/" \
777                                 -e "s/@CFBundleVersion@/${version}/" > "${condir}/${fwdir}"/Resources/Info.plist
778                 fi
779         fi
780         installname -change "${source}" "@executable_path/../${fwdir}/${fwname}" "${target}"
781 }
782
783 deploy_qtlibs() {
784         source="${QtInstallDir}"
785         target="$1"
786         version="Versions/${QtFrameworkVersion}/"
787         condir=$(content_directory "${target}")
788         mkdir -p "${condir}/Resources"
789         test -f "${condir}/Resources/qt.conf" || cat - > "${condir}/Resources/qt.conf" <<-EOF
790 [Paths]
791 Plugins = PlugIns
792 Translations = translations
793 EOF
794         if [ ! -d "${condir}/PlugIns" ]; then
795                 mkdir -p "${condir}/PlugIns"
796                 find "${source}/plugins" -name \*.dylib -print | grep -v _debug.dylib | while read libname ; do
797                         echo Copy plugin "${libname}"
798                         dylib=$(basename "${libname}")
799                         dirname=$(dirname "${libname}")
800                         dirname=$(basename "${dirname}")
801                         mkdir -p "${condir}/PlugIns/${dirname}"
802                         cp -p "${libname}" "${condir}/PlugIns/${dirname}"
803                 done
804         fi
805         for libnm in ${QtLibraries} ; do
806                 fwdir=$(framework_name "$libnm")
807                 dirname=$(dirname "${fwdir}")
808                 mkdir -p "${condir}/${dirname}"
809                 dirname=$(basename "${fwdir}")
810                 test -d "${condir}/${fwdir}" || (
811                         echo Copy framework "${source}/lib/"$(basename "${fwdir}")
812                         cp -pR "${source}/lib/"$(basename "${fwdir}") "${condir}/${fwdir}"
813                         rm -f "${condir}/${fwdir}/${libnm}"_debug "${condir}/${fwdir}/${version}${libnm}"_debug
814                         test -f "${condir}/${fwdir}/${libnm}".prl && mv "${condir}/${fwdir}/${libnm}".prl "${condir}/${fwdir}"/Resources
815                         test -f "${condir}/${fwdir}/${libnm}"_debug.prl && mv "${condir}/${fwdir}/${libnm}"_debug.prl "${condir}/${fwdir}"/Resources
816                         installname -id "@executable_path/../${fwdir}/${version}${libnm}" "${condir}/${fwdir}/${version}${libnm}"
817                         find "${condir}/PlugIns" "${condir}/"$(dirname "${fwdir}") -name Headers -prune -o -type f -print | while read filename ; do
818                                 if [ "${filename}" != "${target}" ]; then
819                                         otool -L "${filename}" 2>/dev/null | sort -u | while read library ; do
820                                                 # pattern match for: /path/to/qt/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.6.0, current version 4.6.2)
821                                                 case "${library}" in
822                                                 *@rpath/*"${libnm}"*"("*version*")"*)
823                                                         # echo rpath based name for ${libnm} is ok.
824                                                         ;;
825                                                 *"${libnm}"*"("*version*")"*)
826                                                         installname -change\
827                                                                 "${source}/lib/${dirname}/${version}${libnm}"\
828                                                                 "@executable_path/../${fwdir}/${version}${libnm}"\
829                                                                 "${filename}"
830                                                         ;;
831                                                 esac
832                                         done
833                                 fi
834                         done
835                 )
836                 installname -change\
837                         "${source}/lib/${dirname}/${version}${libnm}"\
838                         "@executable_path/../${fwdir}/${version}${libnm}"\
839                         "${target}"
840         done
841         if [ -d "${source}"/translations ]; then
842                 if [ ! -d "${condir}/translations" ]; then
843                         mkdir -p "${condir}/translations"
844                 fi
845                 echo Copy Qt translations to "${condir}/translations"
846                 cp -p "${source}"/translations/qt_*.qm "${condir}/translations"
847         fi
848 }
849
850 # -------------------------
851 # Create universal binaries
852 # -------------------------
853 convert_universal() {
854         cd "${LyxAppPrefix}"
855         for file in ${LYX_FILE_LIST} ; do
856                 OBJ_LIST=
857                 for arch in ${ARCH_LIST} ; do
858                         if [ -f "${BUNDLE_PATH}/${file}-${arch}" ]; then
859                                 OBJ_LIST="${OBJ_LIST} ${BUNDLE_PATH}/${file}-${arch}"
860                         fi
861                 done
862                 if [ -n "${OBJ_LIST}" ]; then
863                         lipo -create ${OBJ_LIST} -o "${BUNDLE_PATH}/${file}"
864                 fi
865                 if [ -f "${LibMagicInstallDir}/lib/${LibMagicLibrary}" -a "yes" = "${libmagic_deployment}" ]; then
866                         private_framework LibMagic "${LibMagicInstallDir}/lib/${LibMagicLibrary}" "${LYX_BUNDLE_PATH}/${file}" \
867                                 "${LibMagicVersion}" "${LibMagicInstallHdr}"
868                 fi
869                 if [ -f "${ASpellInstallDir}/lib/${ASpellLibrary}" -a "yes" = "${aspell_deployment}" ]; then
870                         private_framework Aspell "${ASpellInstallDir}/lib/${ASpellLibrary}" "${LYX_BUNDLE_PATH}/${file}" \
871                                 "${ASpellVersion}" "${ASpellInstallHdr}"
872                 fi
873                 if [ -f "${HunSpellInstallDir}/lib/${HunSpellLibrary}" -a "yes" = "${hunspell_deployment}" ]; then
874                         private_framework Hunspell "${HunSpellInstallDir}/lib/${HunSpellLibrary}" "${LYX_BUNDLE_PATH}/${file}" \
875                                 "${HunSpellVersion}" "${HunSpellInstallDir}/include/hunspell/"*.hxx "${HunSpellInstallHdr}"
876                 fi
877                 if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt_deployment}" ]; then
878                         deploy_qtlibs "${LYX_BUNDLE_PATH}/${file}"
879                 fi
880                 otool -L "${BUNDLE_PATH}/${file}" | while read reference ; do
881                         case "${reference}" in
882                         *"${LyxBuildDir}"*"("*")")
883                                 echo ERROR: Bad reference to "${reference}" found!!
884                                 ;;
885                         esac
886                 done
887         done
888         for arch in ${ARCH_LIST} ; do
889                 rm -f "${BUNDLE_PATH}"/*-${arch}
890         done
891 }
892
893 # -------------------------
894 # Create code sign signatures
895 # -------------------------
896 code_sign() {
897         target="$1"
898         condir=$(content_directory "${target}"/lyx)
899         appdir=$(dirname "${condir}")
900         # have to sign frameworks first
901         for fwname in Aspell Hunspell LibMagic ; do
902                 fwitem="${condir}"/$(framework_name "${fwname}")
903                 if [ -d "${fwitem}" ]; then
904                         codesign --verbose --force --sign "${CODESIGN_IDENTITY}" "${fwitem}"
905                 fi
906         done
907         for csitem in \
908                 "${condir}"/Frameworks/Qt*.framework/Versions/${QtFrameworkVersion} \
909                 "${condir}"/PlugIns/*/lib*.dylib \
910                 "${condir}"/Library/Spotlight/* \
911                 "${target}"/inkscape \
912                 "${target}"/lilypond \
913                 "${target}"/lilypond-book \
914                 "${target}"/maxima \
915                 "${target}"/tex2lyx \
916                 "${target}"/lyxeditor \
917                 "${target}"/lyxconvert \
918                 "${target}"/lyxclient
919         do
920                 codesign --verbose --force --sign "${CODESIGN_IDENTITY}" "${csitem}"
921         done
922
923         /usr/bin/codesign --verbose --force --sign "${CODESIGN_IDENTITY}" "${appdir}" || {
924                 echo Warning: codesign failed with certificate named '"'${CODESIGN_IDENTITY}'"'
925         }
926 }
927
928 deduplicate() {
929         find "$@" -type f -print | while read file ; do
930                 echo $(md5 -q "$file") "$file"
931         done | sort | while read hash file ; do
932                 ppath=$(dirname "$pfile")
933                 path=$(dirname "$file")
934                 if [ "$phash" = "$hash" -a "$ppath" = "$path" ]; then
935                         pname=$(basename "$pfile")
936                         name=$(basename "$file")
937                         cmp -s "$pfile" "$file" && (
938                                 rm "$file"
939                                 cd "$path" && ln -s "$pname" "$name" && echo link for "$file" created
940                         )
941                 fi
942                 phash="$hash"
943                 pfile="$file"
944         done
945 }
946
947 copy_dictionaries() {
948         if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_dictionaries}" ]; then
949                 ASpellResources="${LyxAppPrefix}/Contents/Resources"
950                 # try to reuse macports dictionaries for now
951                 if [ -d /opt/local/lib/aspell-0.60 ]; then ASpellInstallDir=/opt/local ; fi
952                 mkdir -p "${ASpellResources}"
953                 echo Copy Aspell dictionaries from "${ASpellInstallDir}"
954                 mkdir -p "${ASpellResources}"/data "${ASpellResources}"/dicts
955                 cp -p -r "${ASpellInstallDir}/lib/aspell-0.60"/* "${ASpellResources}"/data
956                 cp -p -r "${ASpellInstallDir}/share/aspell"/* "${ASpellResources}"/dicts
957         fi
958         if [ -d "${DictionarySourceDir}" -a "yes" = "${hunspell_dictionaries}" ]; then
959                 HunSpellResources="${LyxAppPrefix}/Contents/Resources"
960                 ( cd "${DictionarySourceDir}" && find dicts -name .svn -prune -o -type f -print | cpio -pmdv "${HunSpellResources}" )
961                 deduplicate "${HunSpellResources}"/dicts
962         fi
963         if [ -d "${DictionarySourceDir}" -a "yes" = "${thesaurus_deployment}" ]; then
964                 MyThesResources="${LyxAppPrefix}/Contents/Resources"
965                 ( cd "${DictionarySourceDir}" && find thes -name .svn -prune -o -type f -print | cpio -pmdv "${MyThesResources}" )
966                 deduplicate "${MyThesResources}"/thes
967         fi
968 }
969
970 set_bundle_display_options() {
971         X_BOUNDS=$2
972         Y_BOUNDS=$3
973         Y_POSITION=$((Y_BOUNDS - 65))
974         Y_BOUNDS=$((Y_BOUNDS + 50))
975         LYX_X_POSITION=$((X_BOUNDS / 4))
976         LYX_Y_POSITION=$Y_POSITION
977         APP_X_POSITION=$((3 * X_BOUNDS / 4))
978         APP_Y_POSITION=$Y_POSITION
979         WITH_DOCUMENTS=$(test -d "${1}/Documents" && echo true || echo false)
980         osascript <<-EOF
981         tell application "Finder"
982         set f to POSIX file ("${1}" as string) as alias
983         tell folder f
984             open
985             tell container window
986                 set toolbar visible to false
987                 set statusbar visible to false
988                 set current view to icon view
989                 delay 1 -- sync
990                 set the bounds to {20, 50, $X_BOUNDS, $Y_BOUNDS}
991             end tell
992             delay 1 -- sync
993             set icon size of the icon view options of container window to 64
994             set arrangement of the icon view options of container window to not arranged
995             if ${WITH_DOCUMENTS} then
996                set position of item "Documents" to {$LYX_X_POSITION,0}
997             end if
998             set position of item "${LyxName}.app" to {$LYX_X_POSITION,$LYX_Y_POSITION}
999             set position of item "Applications" to {$APP_X_POSITION,$APP_Y_POSITION}
1000             set background picture of the icon view options\
1001                of container window to file "background.png" of folder "Pictures"
1002             set the bounds of the container window to {0, 0, $X_BOUNDS, $Y_BOUNDS}
1003             update without registering applications
1004             delay 5 -- sync
1005             close
1006         end tell
1007         delay 5 -- sync
1008     end tell
1009 EOF
1010 }
1011
1012 # The image was made with with inkscape and tiffutil from dmg-background.svgz
1013 make_image() {
1014         INKSCAPE=/Applications/Inkscape.app/Contents/MacOS/inkscape
1015         (
1016                 cd "${LyxSourceDir}"/development/MacOSX
1017                 test -x ${INKSCAPE} && ${INKSCAPE} --export-type=png -w 560 -o dmg-background.png dmg-background.svgz
1018                 test -x ${INKSCAPE} && ${INKSCAPE} --export-type=png -w 1120 -o dmg-background@2x.png dmg-background.svgz
1019                 tiffutil -cathidpicheck dmg-background.png dmg-background@2x.png -out dmg-background.tiff
1020         )
1021 }
1022
1023 make_dmg() {
1024         cd "${1}"
1025
1026         test -f "${DmgBackground}" || make_image
1027         BGSIZE=$(file "$DmgBackground" | awk -F , '/TIFF/{ print $10 $4 ;}/PNG/{ print $2; }'|sed -e 's/width=//' -e 's/height=//' -e 's/x//')
1028         BG_W=$(echo ${BGSIZE} | awk '{print $1 }')
1029         BG_H=$(echo ${BGSIZE} | awk '{print $2 }')
1030
1031         rm -f "${DMGNAME}.sparseimage" "${DMGNAME}.dmg"
1032
1033         hdiutil create -type SPARSE -size ${DMGSIZE:-"250m"} -fs HFS+ -volname "${LyxBase}" "${DMGNAME}"
1034         # Unmount currently mounted disk image
1035         mount | grep "${LyxBase}" && umount /Volumes/"${LyxBase}"
1036         test -d /Volumes/"${LyxBase}" && rmdir /Volumes/"${LyxBase}"
1037
1038         # Mount the disk image
1039         DEVICES=$(hdiutil attach "${DMGNAME}.sparseimage" | cut -f 1)
1040
1041         # Obtain device information
1042         DEVICE=$(echo $DEVICES | cut -f 1 -d ' ')
1043         VOLUME=$(mount |grep ${DEVICE} | cut -f 3 -d ' ')
1044
1045         # copy in the application bundle
1046         ditto --hfsCompression "${LyxAppPrefix}" "${VOLUME}/${LyxName}.app"
1047
1048         # copy in background image
1049         mkdir -p "${VOLUME}/Pictures"
1050         ditto --hfsCompression "${DmgBackground}" "${VOLUME}/Pictures/background.png"
1051         # symlink applications
1052         ln -s /Applications/ "${VOLUME}"/Applications
1053         test -d "${DocumentationDir}" && ditto --hfsCompression "${DocumentationDir}" "${VOLUME}"
1054         set_bundle_display_options "${VOLUME}" ${BG_W} ${BG_H}
1055         PATH="${XCODE_DEVELOPER}/Tools:$PATH" SetFile -a C "${VOLUME}"
1056         mv "${VOLUME}/Pictures" "${VOLUME}/.Pictures"
1057
1058         # Unmount the disk image
1059         hdiutil detach ${DEVICE}
1060
1061         # Convert the disk image to read-only
1062         hdiutil convert "${DMGNAME}.sparseimage" -format UDBZ -o "${DMGNAME}.dmg"
1063         rm -f "${DMGNAME}.sparseimage"
1064 }
1065
1066 # ------------------------------
1067 # Building distribution packages
1068 # ------------------------------
1069
1070 build_package() {
1071         test -n "${LyxAppZip}" && (
1072                 cd "${LyxAppPrefix}" && zip -r "${LyxAppZip}" .
1073         )
1074
1075         DMGARCH=""
1076         for arch in ${ARCH_LIST} ; do
1077                 DMGARCH="${DMGARCH}-${arch}"
1078         done
1079         QtDmgArchSuffix="qt"${QtMajorVersion}${DMGARCH}${QtAPI}.dmg
1080
1081         test -n "${DMGLocation}" && (
1082                 make_dmg "${DMGLocation}"
1083                 if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt_deployment}" ]; then
1084                         rm -f "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1085                         echo move to "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1086                         mv "${DMGLocation}/${DMGNAME}.dmg" "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1087                 fi
1088         )
1089 }
1090
1091 # ------------------------------
1092 # main block
1093 # ------------------------------
1094
1095 if [ ${LyxOnlyPackage:-"no"} = "no" ]; then
1096         build_lyx
1097         convert_universal
1098         copy_dictionaries
1099         test -n "${CODESIGN_IDENTITY}" && code_sign "${LYX_BUNDLE_PATH}"
1100         find "${LyxAppPrefix}" -type d -exec chmod go-w '{}' \;
1101 fi
1102 build_package