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