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
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"
20 ASpellVersion=${ASpellVersion:-"0.60.6.1"}
21 ASpellSource="aspell-${ASpellVersion}"
22 ASpellLibrary="libaspell.15.dylib"
24 HunSpellVersion=${HunSpellVersion:-"1.3.3"}
25 HunSpellSource="hunspell-${HunSpellVersion}"
26 HunSpellLibrary="libhunspell-1.3.0.dylib"
28 unset DYLD_LIBRARY_PATH LD_LIBRARY_PATH
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)
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"
50 QtMajorVersion=$(echo "${QtVersion}"|cut -d. -f1)
51 QtConfigureOptions="${QtConfigureOptions} -opensource -silent -shared -confirm-license"
52 # stupid special case...
53 case "${QtVersion}:${QtAPI}" in
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}"
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"
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"
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}"
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}"
95 aspell_dictionaries="no"
96 hunspell_dictionaries="yes"
98 libmagic_deployment="yes"
99 aspell_deployment="yes"
100 hunspell_deployment="yes"
101 thesaurus_deployment="yes"
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
118 # detection of script home
119 LyxSourceDir=$(dirname "$0")
120 if [ ! -d "${LyxSourceDir}" ]; then
121 echo Missing LyX source directory.
124 case "${LyxSourceDir}" in
126 LyxSourceDir=$(dirname "${LyxSourceDir}")
130 */development|development)
131 LyxSourceDir=$(dirname "${LyxSourceDir}")
132 LyxSourceDir=$(cd "${LyxSourceDir}";pwd)
135 LyxSourceDir=$(cd "${LyxSourceDir}";pwd)
140 echo "*" Build script for LyX on Mac OS X
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
153 echo "All other arguments with -- are passed to configure"
154 echo "including the defaults: ${LyXConfigureOptions}"
159 if [ -x "${LyxSourceDir}/configure" ]; then
161 echo "*" Configure options of LyX
163 "${LyxSourceDir}/configure" --help
169 NCPU=$(sysctl -n hw.ncpu)
171 if [ $NCPU -gt 1 ]; then
175 while [ $# -gt 0 ]; do
177 --with-qt-frameworks=*)
178 configure_qt_frameworks=$(echo ${1}|cut -d= -f2)
179 if [ "$configure_qt_frameworks" = "yes" ]; then
186 QTDIR=$(echo ${1}|cut -d= -f2)
189 --with-macos-deployment-target=*)
190 MACOSX_DEPLOYMENT_TARGET=$(echo ${1}|cut -d= -f2)
191 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
195 SDKROOT=$(echo ${1}|cut -d= -f2)
198 SDKROOT="${DEVELOPER_SDKS}/MacOSX10.4u.sdk"
204 SDKROOT="${DEVELOPER_SDKS}/MacOSX${SDKROOT}.sdk"
205 if [ ! -d "${SDKROOT}" ]; then
206 echo Invalid SDKROOT given: "${SDKROOT}"
213 --codesign-identity=*)
214 CODESIGN_IDENTITY=$(echo "${1}"|cut -d= -f2)
217 --libmagic-deployment=*)
218 libmagic_deployment=$(echo ${1}|cut -d= -f2)
221 --aspell-deployment=*)
222 aspell_deployment=$(echo ${1}|cut -d= -f2)
223 aspell_dictionaries=$aspell_deployment
226 --hunspell-deployment=*)
227 hunspell_deployment=$(echo ${1}|cut -d= -f2)
228 hunspell_dictionaries=$hunspell_deployment
231 --thesaurus-deployment=*)
232 thesaurus_deployment=$(echo ${1}|cut -d= -f2)
236 qt_deployment=$(echo ${1}|cut -d= -f2)
240 ARCH=$(echo ${1}|cut -d= -f2|tr ',' ' ')
241 ARCH_LIST="${ARCH_LIST} ${ARCH}"
244 --with-dmg-location=*)
245 DMGLocation=$(echo ${1}|cut -d= -f2)
248 --with-binary-strip=yes)
253 LyxBuildDir=$(echo ${1}|cut -d= -f2)
257 LyXUtilitiesDir=$(echo ${1}|cut -d= -f2)
264 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
265 aspell_deployment="no"
268 --with-included-hunspell)
269 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
270 hunspell_deployment="no"
274 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
275 hunspell_deployment="no"
276 hunspell_dictionaries="no"
280 QtOnlyPackage=$(echo ${1}|cut -d= -f2)
284 LyxOnlyPackage=$(echo ${1}|cut -d= -f2)
287 --enable-cxx11|--enable-cxx-mode=*)
292 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
301 if [ "${configure_qt_frameworks}" != "yes" ]; then
302 QtInstallDir=${QTDIR}
305 ARCH_LIST=${ARCH_LIST:-"ppc i386"}
309 LyxBuildDir=${LyxBuildDir:-$(dirname "${LyxSourceDir}")/lyx-build}
310 DMGLocation=${DMGLocation:-"${LyxBuildDir}"}
312 LyXUtilitiesDir=${LyXUtilitiesDir:-"${LyxBuildDir}"/utilities}
314 LibMagicSourceDir=${LIBMAGICDIR:-$(dirname "${LyxSourceDir}")/${LibMagicSource}}
315 LibMagicBuildDir="${LyxBuildDir}"/"${LibMagicSource}"
316 LibMagicInstallDir=${LibMagicInstallDir:-"${LyXUtilitiesDir}"}
317 LibMagicInstallHdr="${LibMagicInstallDir}/include/magic.h"
319 ASpellSourceDir=${ASPELLDIR:-$(dirname "${LyxSourceDir}")/${ASpellSource}}
320 ASpellBuildDir="${ASpellSourceDir}"
321 ASpellInstallDir=${ASpellInstallDir:-"${LyXUtilitiesDir}"}
322 ASpellInstallHdr="${ASpellInstallDir}/include/aspell.h"
324 HunSpellSourceDir=${HUNSPELLDIR:-$(dirname "${LyxSourceDir}")/${HunSpellSource}}
325 HunSpellBuildDir="${HunSpellSourceDir}"
326 HunSpellInstallDir=${HunSpellInstallDir:-"${LyXUtilitiesDir}"}
327 HunSpellInstallHdr="${HunSpellInstallDir}/include/hunspell/hunspell.h"
329 QtSourceDir=${QTSOURCEDIR:-$(dirname "${LyxSourceDir}")/${QtSourceVersion}}
330 QtBuildDir=${QtBuildDir:-"${LyxBuildDir}"/${QtBuildSubDir:-"qt-build"}}
332 DictionarySourceDir=${DICTIONARYDIR:-$(dirname "${LyxSourceDir}")/dictionaries}
333 DocumentationDir=$(dirname "${LyxSourceDir}")/Documents
334 DmgBackground="${LyxSourceDir}"/development/MacOSX/dmg-background.tiff
336 if [ -z "${LyXVersion}" ]; then
337 LyXVersion=$(grep AC_INIT "${LyxSourceDir}"/configure.ac | cut -d, -f2 | tr -d " []()")
339 LyXVersionSuffix=${LyXVersionSuffix:-$(echo "${LyXVersion}" | cut -d. -f1-2)}
340 case "${LyXVersion}" in
342 LyXGitCommitHash=$(cd "${LyxSourceDir}" ; git log -1 --pretty=format:%h)
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"
355 # ---------------------------------
356 # DON'T MODIFY ANYTHING BELOW HERE!
357 # ---------------------------------
359 # don't change order here...
360 case "${QtVersion}" in
362 QtLibraries=${QtLibraries:-"QtSvg QtXml QtPrintSupport QtWidgets QtGui QtNetwork QtConcurrent QtCore"}
363 QtFrameworkVersion="5"
366 QtLibraries=${QtLibraries:-"QtDBus QtSvg QtXml QtPrintSupport QtMacExtras QtWidgets QtGui QtNetwork QtConcurrent QtCore"}
367 QtFrameworkVersion="5"
370 QtLibraries=${QtLibraries:-"QtSvg QtXml QtPrintSupport QtMacExtras QtWidgets QtGui QtNetwork QtConcurrent QtCore"}
371 QtFrameworkVersion="5"
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"
384 QtLibraries=${QtLibraries:-"QtSvg QtXml QtGui QtNetwork QtCore"}
385 QtFrameworkVersion="4"
389 DMGNAME="${LyxBase}${LyXGitCommitHash:+-}${LyXGitCommitHash}"
392 # Check for existing SDKs
393 SDKs=$(echo ${DEVELOPER_SDKS}/MacOSX1[01]*sdk)
398 MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"10.5"}; export MACOSX_DEPLOYMENT_TARGET
399 case "${MACOSX_DEPLOYMENT_TARGET}" in
401 SDKROOT="${DEVELOPER_SDKS}/MacOSX10.6.sdk"; export SDKROOT
404 SDKROOT=${SDKROOT:-"${DEVELOPER_SDKS}/MacOSX10.5.sdk"}; export SDKROOT
409 MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"10.4"}; export MACOSX_DEPLOYMENT_TARGET
410 SDKROOT=${SDKROOT:-"${DEVELOPER_SDKS}/MacOSX10.5.sdk"}; export SDKROOT
413 echo Unknown or missing SDK for Mac OS X.
417 MYCFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}"
418 MYLDFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}"
420 case "${EnableCXXMode}" in
421 --enable-cxx11|--enable-cxx-mode=11)
423 export CXX="c++ -stdlib=libc++"
424 export CXXFLAGS=-std=c++11
425 LyXConfigureOptions="${LyXConfigureOptions} --enable-cxx-mode=11"
427 --enable-cxx-mode=17)
429 export CXX="c++ -stdlib=libc++"
430 export CXXFLAGS=-std=c++17
431 LyXConfigureOptions="${LyXConfigureOptions} ${EnableCXXMode}"
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}".
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
451 case ${QtOnlyPackage:-"no"} in
457 if [ "${configure_qt_frameworks}" != "yes" -a -d "${QtSourceDir}" -a ! \( -d "${QtBuildDir}" -a -d "${QtInstallDir}" \) ]; then
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 " []()")
470 LibMagicName="LibMagic"
471 LibMagicBase="${LibMagicName}-${LibMagicVersion}"
473 echo Build libmagic library ${LibMagicBase}
474 echo configure options:
475 echo --prefix="${LibMagicInstallDir}" ${LibMagicConfigureOptions}
477 mkdir -p "${LibMagicBuildDir}" && cd "${LibMagicBuildDir}"
479 # ----------------------------------------
480 # Build LibMagic for different architectures
481 # ----------------------------------------
482 FILE_LIST="${LibMagicLibrary}"
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}
496 echo Cannot build and install LibMagic for ${arch}.
501 # -------------------------
502 # Create universal binaries
503 # -------------------------
504 for file in ${FILE_LIST} ; do
506 for arch in ${ARCH_LIST} ; do
507 OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
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)
519 for arch in ${ARCH_LIST} ; do
520 rm -f "${LibMagicInstallDir}"/lib/*-${arch}
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 " []()")
531 HunSpellName="Hunspell"
532 HunSpellBase="${HunSpellName}-${HunSpellVersion}"
534 echo Build hunspell library ${HunSpellBase}
535 echo configure options:
536 echo --prefix="${HunSpellInstallDir}" ${HunspellConfigureOptions}
538 mkdir -p "${HunSpellBuildDir}" && cd "${HunSpellBuildDir}"
540 # ----------------------------------------
541 # Build HunSpell for different architectures
542 # ----------------------------------------
543 FILE_LIST="${HunSpellLibrary}"
545 for arch in ${ARCH_LIST} ; do
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}
558 echo Cannot build and install HunSpell for ${arch}.
563 # -------------------------
564 # Create universal binaries
565 # -------------------------
566 for file in ${FILE_LIST} ; do
568 for arch in ${ARCH_LIST} ; do
569 OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
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)
581 for arch in ${ARCH_LIST} ; do
582 rm -f "${HunSpellInstallDir}"/lib/*-${arch}
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 " []()")
594 ASpellBase="${ASpellName}-${ASpellVersion}"
596 echo Build aspell library ${ASpellBase}
597 echo configure options:
598 echo --prefix="${ASpellInstallDir}" ${AspellConfigureOptions}
600 # ASpell builds inplace only :(
601 cd "${ASpellSourceDir}"
603 # ----------------------------------------
604 # Build ASpell for different architectures
605 # ----------------------------------------
606 FILE_LIST="${ASpellLibrary}"
608 for arch in ${ARCH_LIST} ; do
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}
621 echo Cannot build and install ASpell for ${arch}.
626 # -------------------------
627 # Create universal binaries
628 # -------------------------
629 for file in ${FILE_LIST} ; do
631 for arch in ${ARCH_LIST} ; do
632 OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
635 cd "${ASpellInstallDir}"
636 lipo -create ${OBJ_LIST} -o lib/${file}
642 for arch in ${ARCH_LIST} ; do
643 rm -f "${ASpellInstallDir}"/lib/*-${arch}
649 echo "Frameworks/${1}.framework"
652 LYX_FILE_LIST="lyx lyxclient tex2lyx lyxconvert"
653 BUNDLE_PATH="Contents/MacOS"
654 LYX_BUNDLE_PATH="${LyxAppPrefix}/${BUNDLE_PATH}"
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}"
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 )
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 )
678 # -------------------------------------
679 # Build LyX for different architectures
680 # -------------------------------------
682 if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_deployment}" ]; then
683 ConfigureExtraInc="--with-extra-inc=${ASpellInstallDir}/include"
684 ConfigureExtraLib="--with-extra-lib=${ASpellInstallDir}/lib"
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}"
694 LyXConfigureOptions="${LyXConfigureOptions} ${ConfigureExtraInc}"
695 LyXConfigureOptions="${LyXConfigureOptions} ${ConfigureExtraLib}"
697 for arch in ${ARCH_LIST} ; do
699 if [ -d "${LyxBuildDir}" ]; then rm -r "${LyxBuildDir}"; fi
700 mkdir -p "${LyxBuildDir}" && cd "${LyxBuildDir}"
702 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch}"
703 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch}"
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"
714 echo LDFLAGS="${LDFLAGS}"
716 echo CPPFLAGS="${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}"
730 echo ERROR: Cannot build and install ${file} for ${arch}.
737 content_directory() {
739 content=$(dirname "${target}")
740 content=$(dirname "${content}")
745 echo install_name_tool "$@"
746 install_name_tool "$@" || exit 1
749 private_framework() {
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)
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
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
780 installname -change "${source}" "@executable_path/../${fwdir}/${fwname}" "${target}"
784 source="${QtInstallDir}"
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
792 Translations = translations
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}"
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)
822 *@rpath/*"${libnm}"*"("*version*")"*)
823 # echo rpath based name for ${libnm} is ok.
825 *"${libnm}"*"("*version*")"*)
827 "${source}/lib/${dirname}/${version}${libnm}"\
828 "@executable_path/../${fwdir}/${version}${libnm}"\
837 "${source}/lib/${dirname}/${version}${libnm}"\
838 "@executable_path/../${fwdir}/${version}${libnm}"\
841 if [ -d "${source}"/translations ]; then
842 if [ ! -d "${condir}/translations" ]; then
843 mkdir -p "${condir}/translations"
845 echo Copy Qt translations to "${condir}/translations"
846 cp -p "${source}"/translations/qt_*.qm "${condir}/translations"
850 # -------------------------
851 # Create universal binaries
852 # -------------------------
853 convert_universal() {
855 for file in ${LYX_FILE_LIST} ; do
857 for arch in ${ARCH_LIST} ; do
858 if [ -f "${BUNDLE_PATH}/${file}-${arch}" ]; then
859 OBJ_LIST="${OBJ_LIST} ${BUNDLE_PATH}/${file}-${arch}"
862 if [ -n "${OBJ_LIST}" ]; then
863 lipo -create ${OBJ_LIST} -o "${BUNDLE_PATH}/${file}"
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}"
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}"
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}"
877 if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt_deployment}" ]; then
878 deploy_qtlibs "${LYX_BUNDLE_PATH}/${file}"
880 otool -L "${BUNDLE_PATH}/${file}" | while read reference ; do
881 case "${reference}" in
882 *"${LyxBuildDir}"*"("*")")
883 echo ERROR: Bad reference to "${reference}" found!!
888 for arch in ${ARCH_LIST} ; do
889 rm -f "${BUNDLE_PATH}"/*-${arch}
893 # -------------------------
894 # Create code sign signatures
895 # -------------------------
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}"
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 \
915 "${target}"/tex2lyx \
916 "${target}"/lyxeditor \
917 "${target}"/lyxconvert \
918 "${target}"/lyxclient
920 codesign --verbose --force --sign "${CODESIGN_IDENTITY}" "${csitem}"
923 /usr/bin/codesign --verbose --force --sign "${CODESIGN_IDENTITY}" "${appdir}" || {
924 echo Warning: codesign failed with certificate named '"'${CODESIGN_IDENTITY}'"'
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" && (
939 cd "$path" && ln -s "$pname" "$name" && echo link for "$file" created
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
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
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
970 set_bundle_display_options() {
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)
981 tell application "Finder"
982 set f to POSIX file ("${1}" as string) as alias
985 tell container window
986 set toolbar visible to false
987 set statusbar visible to false
988 set current view to icon view
990 set the bounds to {20, 50, $X_BOUNDS, $Y_BOUNDS}
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}
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
1012 # The image was made with with inkscape and tiffutil from dmg-background.svgz
1014 INKSCAPE=/Applications/Inkscape.app/Contents/MacOS/inkscape
1015 cd "${LyxSourceDir}"/development/MacOSX
1016 ${INKSCAPE} --export-type=png -w 560 -o dmg-background.png dmg-background.svgz
1017 ${INKSCAPE} --export-type=png -w 1120 -o dmg-background@2x.png dmg-background.svgz
1018 tiffutil -cathidpicheck dmg-background.png dmg-background@2x.png -out dmg-background.tiff
1024 BGSIZE=$(file "$DmgBackground" | awk -F , '/TIFF/{ print $10 $4 ;}/PNG/{ print $2; }'|sed -e 's/width=//' -e 's/height=//' -e 's/x//')
1025 BG_W=$(echo ${BGSIZE} | awk '{print $1 }')
1026 BG_H=$(echo ${BGSIZE} | awk '{print $2 }')
1028 rm -f "${DMGNAME}.sparseimage" "${DMGNAME}.dmg"
1030 hdiutil create -type SPARSE -size ${DMGSIZE:-"250m"} -fs HFS+ -volname "${LyxBase}" "${DMGNAME}"
1031 # Unmount currently mounted disk image
1032 mount | grep "${LyxBase}" && umount /Volumes/"${LyxBase}"
1033 test -d /Volumes/"${LyxBase}" && rmdir /Volumes/"${LyxBase}"
1035 # Mount the disk image
1036 DEVICES=$(hdiutil attach "${DMGNAME}.sparseimage" | cut -f 1)
1038 # Obtain device information
1039 DEVICE=$(echo $DEVICES | cut -f 1 -d ' ')
1040 VOLUME=$(mount |grep ${DEVICE} | cut -f 3 -d ' ')
1042 # copy in the application bundle
1043 ditto --hfsCompression "${LyxAppPrefix}" "${VOLUME}/${LyxName}.app"
1045 # copy in background image
1046 mkdir -p "${VOLUME}/Pictures"
1047 ditto --hfsCompression "${DmgBackground}" "${VOLUME}/Pictures/background.png"
1048 # symlink applications
1049 ln -s /Applications/ "${VOLUME}"/Applications
1050 test -d "${DocumentationDir}" && ditto --hfsCompression "${DocumentationDir}" "${VOLUME}"
1051 set_bundle_display_options "${VOLUME}" ${BG_W} ${BG_H}
1052 PATH="${XCODE_DEVELOPER}/Tools:$PATH" SetFile -a C "${VOLUME}"
1053 mv "${VOLUME}/Pictures" "${VOLUME}/.Pictures"
1055 # Unmount the disk image
1056 hdiutil detach ${DEVICE}
1058 # Convert the disk image to read-only
1059 hdiutil convert "${DMGNAME}.sparseimage" -format UDBZ -o "${DMGNAME}.dmg"
1060 rm -f "${DMGNAME}.sparseimage"
1063 # ------------------------------
1064 # Building distribution packages
1065 # ------------------------------
1068 test -n "${LyxAppZip}" && (
1069 cd "${LyxAppPrefix}" && zip -r "${LyxAppZip}" .
1073 for arch in ${ARCH_LIST} ; do
1074 DMGARCH="${DMGARCH}-${arch}"
1076 QtDmgArchSuffix="qt"${QtMajorVersion}${DMGARCH}${QtAPI}.dmg
1078 test -n "${DMGLocation}" && (
1079 make_dmg "${DMGLocation}"
1080 if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt_deployment}" ]; then
1081 rm -f "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1082 echo move to "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1083 mv "${DMGLocation}/${DMGNAME}.dmg" "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1088 # ------------------------------
1090 # ------------------------------
1092 if [ ${LyxOnlyPackage:-"no"} = "no" ]; then
1096 test -n "${CODESIGN_IDENTITY}" && code_sign "${LYX_BUNDLE_PATH}"
1097 find "${LyxAppPrefix}" -type d -exec chmod go-w '{}' \;