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"
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"
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"
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}"
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}"
98 aspell_dictionaries="no"
99 hunspell_dictionaries="yes"
101 libmagic_deployment="yes"
102 aspell_deployment="yes"
103 hunspell_deployment="yes"
104 thesaurus_deployment="yes"
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
121 # detection of script home
122 LyxSourceDir=$(dirname "$0")
123 if [ ! -d "${LyxSourceDir}" ]; then
124 echo Missing LyX source directory.
127 case "${LyxSourceDir}" in
129 LyxSourceDir=$(dirname "${LyxSourceDir}")
133 */development|development)
134 LyxSourceDir=$(dirname "${LyxSourceDir}")
135 LyxSourceDir=$(cd "${LyxSourceDir}";pwd)
138 LyxSourceDir=$(cd "${LyxSourceDir}";pwd)
143 echo "*" Build script for LyX on Mac OS X
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
156 echo "All other arguments with -- are passed to configure"
157 echo "including the defaults: ${LyXConfigureOptions}"
162 if [ -x "${LyxSourceDir}/configure" ]; then
164 echo "*" Configure options of LyX
166 "${LyxSourceDir}/configure" --help
172 NCPU=$(sysctl -n hw.ncpu)
174 if [ $NCPU -gt 1 ]; then
178 while [ $# -gt 0 ]; do
180 --with-qt-frameworks=*)
181 configure_qt_frameworks=$(echo ${1}|cut -d= -f2)
182 if [ "$configure_qt_frameworks" = "yes" ]; then
189 QTDIR=$(echo ${1}|cut -d= -f2)
192 --with-macosx-target=*)
193 MACOSX_DEPLOYMENT_TARGET=$(echo ${1}|cut -d= -f2)
197 SDKROOT=$(echo ${1}|cut -d= -f2)
200 SDKROOT="${DEVELOPER_SDKS}/MacOSX10.4u.sdk"
206 SDKROOT="${DEVELOPER_SDKS}/MacOSX${SDKROOT}.sdk"
207 if [ ! -d "${SDKROOT}" ]; then
208 echo Invalid SDKROOT given: "${SDKROOT}"
215 --codesign-identity=*)
216 CODESIGN_IDENTITY=$(echo "${1}"|cut -d= -f2)
219 --libmagic-deployment=*)
220 libmagic_deployment=$(echo ${1}|cut -d= -f2)
223 --aspell-deployment=*)
224 aspell_deployment=$(echo ${1}|cut -d= -f2)
225 aspell_dictionaries=$aspell_deployment
228 --hunspell-deployment=*)
229 hunspell_deployment=$(echo ${1}|cut -d= -f2)
230 hunspell_dictionaries=$hunspell_deployment
233 --thesaurus-deployment=*)
234 thesaurus_deployment=$(echo ${1}|cut -d= -f2)
238 qt_deployment=$(echo ${1}|cut -d= -f2)
242 ARCH=$(echo ${1}|cut -d= -f2|tr ',' ' ')
243 ARCH_LIST="${ARCH_LIST} ${ARCH}"
246 --with-dmg-location=*)
247 DMGLocation=$(echo ${1}|cut -d= -f2)
250 --with-binary-strip=yes)
255 LyxBuildDir=$(echo ${1}|cut -d= -f2)
259 LyXUtilitiesDir=$(echo ${1}|cut -d= -f2)
266 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
267 aspell_deployment="no"
271 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
272 hunspell_deployment="no"
276 QtOnlyPackage=$(echo ${1}|cut -d= -f2)
280 LyxOnlyPackage=$(echo ${1}|cut -d= -f2)
284 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
285 EnableCXX11="--enable-cxx11"
289 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
298 if [ "${configure_qt_frameworks}" != "yes" ]; then
299 QtInstallDir=${QTDIR:-"/opt/qt4"}
302 ARCH_LIST=${ARCH_LIST:-"ppc i386"}
306 LyxBuildDir=${LyxBuildDir:-$(dirname "${LyxSourceDir}")/lyx-build}
307 DMGLocation=${DMGLocation:-"${LyxBuildDir}"}
309 LyXUtilitiesDir=${LyXUtilitiesDir:-"${LyxBuildDir}"/utilities}
311 LibMagicSourceDir=${LIBMAGICDIR:-$(dirname "${LyxSourceDir}")/${LibMagicSource}}
312 LibMagicBuildDir="${LyxBuildDir}"/"${LibMagicSource}"
313 LibMagicInstallDir=${LibMagicInstallDir:-"${LyXUtilitiesDir}"}
314 LibMagicInstallHdr="${LibMagicInstallDir}/include/magic.h"
316 ASpellSourceDir=${ASPELLDIR:-$(dirname "${LyxSourceDir}")/${ASpellSource}}
317 ASpellBuildDir="${ASpellSourceDir}"
318 ASpellInstallDir=${ASpellInstallDir:-"${LyXUtilitiesDir}"}
319 ASpellInstallHdr="${ASpellInstallDir}/include/aspell.h"
321 HunSpellSourceDir=${HUNSPELLDIR:-$(dirname "${LyxSourceDir}")/${HunSpellSource}}
322 HunSpellBuildDir="${HunSpellSourceDir}"
323 HunSpellInstallDir=${HunSpellInstallDir:-"${LyXUtilitiesDir}"}
324 HunSpellInstallHdr="${HunSpellInstallDir}/include/hunspell/hunspell.h"
326 QtSourceDir=${QTSOURCEDIR:-$(dirname "${LyxSourceDir}")/${QtSourceVersion}}
327 QtBuildDir=${QtBuildDir:-"${LyxBuildDir}"/${QtBuildSubDir:-"qt-build"}}
329 DictionarySourceDir=${DICTIONARYDIR:-$(dirname "${LyxSourceDir}")/dictionaries}
330 DocumentationDir=$(dirname "${LyxSourceDir}")/Documents
331 DmgBackground="${LyxSourceDir}"/development/MacOSX/dmg-background.png
333 if [ -z "${LyXVersion}" ]; then
334 LyXVersion=$(grep AC_INIT "${LyxSourceDir}"/configure.ac | cut -d, -f2 | tr -d " []()")
336 LyXVersionSuffix=${LyXVersionSuffix:-$(echo "${LyXVersion}" | cut -d. -f1-2)}
337 case "${LyXVersion}" in
339 LyXGitCommitHash=$(cd "${LyxSourceDir}" ; git log -1 --pretty=format:%h)
344 LyxBase="${LyxName}-${LyXVersion}"
345 LyxApp="${LyxBase}.app"
346 LyxAppDir="${LyxBuildDir}"/"${LyxBase}"
347 LyxBuildDir="${LyxAppDir}.build"
348 LyxAppPrefix="${LyxAppDir}.app"
349 # if zip file is needed... remove the comment sign
350 #LyxAppZip="${LyxAppPrefix}.zip"
352 # ---------------------------------
353 # DON'T MODIFY ANYTHING BELOW HERE!
354 # ---------------------------------
356 # don't change order here...
357 case "${QtVersion}" in
359 QtLibraries=${QtLibraries:-"QtSvg QtXml QtPrintSupport QtWidgets QtGui QtNetwork QtConcurrent QtCore"}
360 QtFrameworkVersion="5"
363 QtLibraries=${QtLibraries:-"QtDbus QtSvg QtXml QtPrintSupport QtMacExtras QtWidgets QtGui QtNetwork QtConcurrent QtCore"}
364 QtFrameworkVersion="5"
367 QtLibraries=${QtLibraries:-"QtSvg QtXml QtPrintSupport QtMacExtras QtWidgets QtGui QtNetwork QtConcurrent QtCore"}
368 QtFrameworkVersion="5"
371 QtLibraries=${QtLibraries:-"QtSvg QtXml QtGui QtNetwork QtCore"}
372 QtFrameworkVersion="4"
376 DMGNAME="${LyxBase}${LyXGitCommitHash:+-}${LyXGitCommitHash}"
379 # Check for existing SDKs
380 SDKs=$(echo ${DEVELOPER_SDKS}/MacOSX10*sdk)
385 MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"10.5"}; export MACOSX_DEPLOYMENT_TARGET
386 case "${MACOSX_DEPLOYMENT_TARGET}" in
388 SDKROOT="${DEVELOPER_SDKS}/MacOSX10.6.sdk"; export SDKROOT
391 SDKROOT=${SDKROOT:-"${DEVELOPER_SDKS}/MacOSX10.5.sdk"}; export SDKROOT
396 MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"10.4"}; export MACOSX_DEPLOYMENT_TARGET
397 SDKROOT=${SDKROOT:-"${DEVELOPER_SDKS}/MacOSX10.5.sdk"}; export SDKROOT
400 echo Unknown or missing SDK for Mac OS X.
404 MYCFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}"
405 MYLDFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}"
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}".
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
421 if [ -d "${QtInstallDir}" -a ! -f "${QtInstallDir}"/include/QtCore ]; then
422 cd "${QtInstallDir}" && (
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} )
433 case ${QtOnlyPackage:-"no"} in
439 if [ "${configure_qt_frameworks}" != "yes" -a -d "${QtSourceDir}" -a ! \( -d "${QtBuildDir}" -a -d "${QtInstallDir}" \) ]; then
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 " []()")
452 LibMagicName="LibMagic"
453 LibMagicBase="${LibMagicName}-${LibMagicVersion}"
455 echo Build libmagic library ${LibMagicBase}
456 echo configure options:
457 echo --prefix="${LibMagicInstallDir}" ${LibMagicConfigureOptions}
459 mkdir -p "${LibMagicBuildDir}" && cd "${LibMagicBuildDir}"
461 # ----------------------------------------
462 # Build LibMagic for different architectures
463 # ----------------------------------------
464 FILE_LIST="${LibMagicLibrary}"
466 for arch in ${ARCH_LIST} ; do
467 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"; export CPPFLAGS
468 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYLDFLAGS}"; 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}
478 echo Cannot build and install LibMagic for ${arch}.
483 # -------------------------
484 # Create universal binaries
485 # -------------------------
486 for file in ${FILE_LIST} ; do
488 for arch in ${ARCH_LIST} ; do
489 OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
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)
501 for arch in ${ARCH_LIST} ; do
502 rm -f "${LibMagicInstallDir}"/lib/*-${arch}
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 " []()")
513 HunSpellName="Hunspell"
514 HunSpellBase="${HunSpellName}-${HunSpellVersion}"
516 echo Build hunspell library ${HunSpellBase}
517 echo configure options:
518 echo --prefix="${HunSpellInstallDir}" ${HunspellConfigureOptions}
520 mkdir -p "${HunSpellBuildDir}" && cd "${HunSpellBuildDir}"
522 # ----------------------------------------
523 # Build HunSpell for different architectures
524 # ----------------------------------------
525 FILE_LIST="${HunSpellLibrary}"
527 for arch in ${ARCH_LIST} ; do
529 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"; export CPPFLAGS
530 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYLDFLAGS}"; 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}
540 echo Cannot build and install HunSpell for ${arch}.
545 # -------------------------
546 # Create universal binaries
547 # -------------------------
548 for file in ${FILE_LIST} ; do
550 for arch in ${ARCH_LIST} ; do
551 OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
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)
563 for arch in ${ARCH_LIST} ; do
564 rm -f "${HunSpellInstallDir}"/lib/*-${arch}
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 " []()")
576 ASpellBase="${ASpellName}-${ASpellVersion}"
578 echo Build aspell library ${ASpellBase}
579 echo configure options:
580 echo --prefix="${ASpellInstallDir}" ${AspellConfigureOptions}
582 # ASpell builds inplace only :(
583 cd "${ASpellSourceDir}"
585 # ----------------------------------------
586 # Build ASpell for different architectures
587 # ----------------------------------------
588 FILE_LIST="${ASpellLibrary}"
590 for arch in ${ARCH_LIST} ; do
592 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"; export CPPFLAGS
593 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYLDFLAGS}"; 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}
603 echo Cannot build and install ASpell for ${arch}.
608 # -------------------------
609 # Create universal binaries
610 # -------------------------
611 for file in ${FILE_LIST} ; do
613 for arch in ${ARCH_LIST} ; do
614 OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
617 cd "${ASpellInstallDir}"
618 lipo -create ${OBJ_LIST} -o lib/${file}
624 for arch in ${ARCH_LIST} ; do
625 rm -f "${ASpellInstallDir}"/lib/*-${arch}
631 echo "Frameworks/${1}.framework"
634 LYX_FILE_LIST="lyx lyxclient tex2lyx lyxconvert"
635 BUNDLE_PATH="Contents/MacOS"
636 LYX_BUNDLE_PATH="${LyxAppPrefix}/${BUNDLE_PATH}"
640 if [ -n "${LyxAppZip}" -a -f "${LyxAppZip}" ]; then rm "${LyxAppZip}"; fi
641 if [ -d "${LyxAppPrefix}" ]; then rm -rf "${LyxAppPrefix}"; fi
643 case "${EnableCXX11}" in
646 export CXX="c++ -stdlib=libc++"
647 export CXXFLAGS=-std=c++11
651 # -------------------------------------
652 # Automate configure check
653 # -------------------------------------
654 if [ ! -f "${LyxSourceDir}"/configure -o "${LyxSourceDir}"/configure -ot "${LyxSourceDir}"/configure.ac ]; then
655 ( cd "${LyxSourceDir}" && sh autogen.sh )
657 find "${LyxSourceDir}" -name Makefile.am -print | while read file ; do
658 dname=$(dirname "$file")
659 if [ -f "$dname/Makefile.in" -a "$dname/Makefile.in" -ot "$file" ]; then
660 ( cd "${LyxSourceDir}" && sh autogen.sh )
665 # -------------------------------------
666 # Build LyX for different architectures
667 # -------------------------------------
669 if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_deployment}" ]; then
670 ConfigureExtraInc="--with-extra-inc=${ASpellInstallDir}/include"
671 ConfigureExtraLib="--with-extra-lib=${ASpellInstallDir}/lib"
674 if [ -d "${HunSpellInstallDir}" -a "yes" = "${hunspell_deployment}" ]; then
675 HunSpellFramework=$(framework_name Hunspell)
676 HunSpellFramework=$(basename "${HunSpellFramework}")
677 ConfigureExtraInc="--with-extra-inc=${HunSpellInstallDir}/include"
678 ConfigureExtraLib="--with-extra-lib=${HunSpellInstallDir}/lib"
679 # LyXConfigureOptions="${LyXConfigureOptions} --with-hunspell-framework=${HunSpellFramework}"
681 LyXConfigureOptions="${LyXConfigureOptions} ${ConfigureExtraInc}"
682 LyXConfigureOptions="${LyXConfigureOptions} ${ConfigureExtraLib}"
684 for arch in ${ARCH_LIST} ; do
686 if [ -d "${LyxBuildDir}" ]; then rm -r "${LyxBuildDir}"; fi
687 mkdir -p "${LyxBuildDir}" && cd "${LyxBuildDir}"
689 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"
690 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYLDFLAGS}"
692 if [ "$configure_qt_frameworks" = "yes" ]; then
693 export QT_CORE_CFLAGS="-FQtCore"
694 export QT_CORE_LIBS="-framework QtCore"
695 export QT_FRONTEND_CFLAGS="-FQtGui"
696 export QT_FRONTEND_LIBS="-framework QtGui"
697 CPPFLAGS="${CPPFLAGS} -I${SDKROOT}/Library/Frameworks/QtCore.framework/Headers"
698 CPPFLAGS="${CPPFLAGS} -I${SDKROOT}/Library/Frameworks/QtGui.framework/Headers"
701 echo LDFLAGS="${LDFLAGS}"
703 echo CPPFLAGS="${CPPFLAGS}"
705 echo CONFIGURE_OPTIONS="${LyXConfigureOptions}" ${QtInstallDir:+"--with-qt-dir=${QtInstallDir}"}
706 "${LyxSourceDir}/configure"\
707 --prefix="${LyxAppPrefix}" --with-version-suffix="-${LyXVersionSuffix}"\
708 ${QtInstallDir:+"--with-qt-dir=${QtInstallDir}"} \
709 ${LyXConfigureOptions}\
710 --enable-build-type=rel && \
711 make ${MAKEJOBS} && make install${strip}
712 for file in ${LYX_FILE_LIST} ; do
713 if [ -f "${LYX_BUNDLE_PATH}/${file}" ]; then
714 mv "${LYX_BUNDLE_PATH}/${file}"\
715 "${LYX_BUNDLE_PATH}/${file}-${arch}"
717 echo ERROR: Cannot build and install ${file} for ${arch}.
724 content_directory() {
726 content=$(dirname "${target}")
727 content=$(dirname "${content}")
732 echo install_name_tool "$@"
733 install_name_tool "$@" || exit 1
736 private_framework() {
740 version=$(echo ${1:-"1.1.1"}.1.1.1 | cut -d. -f1-3) ; shift
741 fwdir=$(framework_name "${fwname}")
742 condir=$(content_directory "${target}")
743 libnm=$(basename "${source}")
744 libid="org.lyx."$(echo "${libnm}" | cut -d. -f1)
745 svrsn=$(echo "${version}" | cut -d. -f1-2)
747 mkdir -p "${condir}/${fwdir}"/Versions/${fwvrsn}/Headers
748 mkdir -p "${condir}/${fwdir}"/Versions/${fwvrsn}/Resources
749 if [ ! -f "${condir}/${fwdir}/Versions/${fwvrsn}/${fwname}" ]; then
750 cp -p "${source}" "${condir}/${fwdir}/Versions/${fwvrsn}/${fwname}"
751 for hfile in "$@" ; do
752 test -f "${hfile}" && cp -p "${hfile}" "${condir}/${fwdir}"/Versions/${fwvrsn}/Headers
754 ln -s ${fwvrsn} "${condir}/${fwdir}/Versions/Current"
755 ln -s Versions/Current/Headers "${condir}/${fwdir}/Headers"
756 ln -s Versions/Current/Resources "${condir}/${fwdir}/Resources"
757 ln -s Versions/Current/"${fwname}" "${condir}/${fwdir}/${fwname}"
758 installname -id "@executable_path/../${fwdir}/${fwname}" "${condir}/${fwdir}/${fwname}"
759 if [ -f "${LyxSourceDir}"/development/LyX-Mac-frameworks-template.plist ]; then
760 cat "${LyxSourceDir}"/development/LyX-Mac-frameworks-template.plist | sed \
761 -e "s/@CFBundleExecutable@/${fwname}/" \
762 -e "s/@CFBundleIdentifier@/${libid}/" \
763 -e "s/@CFBundleShortVersionString@/${svrsn}/" \
764 -e "s/@CFBundleVersion@/${version}/" > "${condir}/${fwdir}"/Resources/Info.plist
767 installname -change "${source}" "@executable_path/../${fwdir}/${fwname}" "${target}"
771 source="${QtInstallDir}"
773 version="Versions/${QtFrameworkVersion}/"
774 condir=$(content_directory "${target}")
775 mkdir -p "${condir}/Resources"
776 test -f "${condir}/Resources/qt.conf" || cat - > "${condir}/Resources/qt.conf" <<-EOF
779 Translations = translations
781 if [ ! -d "${condir}/PlugIns" ]; then
782 mkdir -p "${condir}/PlugIns"
783 find "${source}/plugins" -name \*.dylib -print | grep -v _debug.dylib | while read libname ; do
784 echo Copy plugin "${libname}"
785 dylib=$(basename "${libname}")
786 dirname=$(dirname "${libname}")
787 dirname=$(basename "${dirname}")
788 mkdir -p "${condir}/PlugIns/${dirname}"
789 cp -p "${libname}" "${condir}/PlugIns/${dirname}"
792 for libnm in ${QtLibraries} ; do
793 fwdir=$(framework_name "$libnm")
794 dirname=$(dirname "${fwdir}")
795 mkdir -p "${condir}/${dirname}"
796 dirname=$(basename "${fwdir}")
797 test -d "${condir}/${fwdir}" || (
798 echo Copy framework "${source}/lib/"$(basename "${fwdir}")
799 cp -pR "${source}/lib/"$(basename "${fwdir}") "${condir}/${fwdir}"
800 rm -f "${condir}/${fwdir}/${libnm}"_debug "${condir}/${fwdir}/${version}${libnm}"_debug
801 test -f "${condir}/${fwdir}/${libnm}".prl && mv "${condir}/${fwdir}/${libnm}".prl "${condir}/${fwdir}"/Resources
802 test -f "${condir}/${fwdir}/${libnm}"_debug.prl && mv "${condir}/${fwdir}/${libnm}"_debug.prl "${condir}/${fwdir}"/Resources
803 installname -id "@executable_path/../${fwdir}/${version}${libnm}" "${condir}/${fwdir}/${version}${libnm}"
804 find "${condir}/PlugIns" "${condir}/"$(dirname "${fwdir}") -name Headers -prune -o -type f -print | while read filename ; do
805 if [ "${filename}" != "${target}" ]; then
806 otool -L "${filename}" 2>/dev/null | sort -u | while read library ; do
807 # pattern match for: /path/to/qt/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.6.0, current version 4.6.2)
809 *@rpath/*"${libnm}"*"("*version*")"*)
810 # echo rpath based name for ${libnm} is ok.
812 *"${libnm}"*"("*version*")"*)
814 "${source}/lib/${dirname}/${version}${libnm}"\
815 "@executable_path/../${fwdir}/${version}${libnm}"\
824 "${source}/lib/${dirname}/${version}${libnm}"\
825 "@executable_path/../${fwdir}/${version}${libnm}"\
828 if [ -d "${source}"/translations ]; then
829 if [ ! -d "${condir}/translations" ]; then
830 mkdir -p "${condir}/translations"
832 echo Copy Qt translations to "${condir}/translations"
833 cp -p "${source}"/translations/qt_*.qm "${condir}/translations"
837 # -------------------------
838 # Create universal binaries
839 # -------------------------
840 convert_universal() {
842 for file in ${LYX_FILE_LIST} ; do
844 for arch in ${ARCH_LIST} ; do
845 if [ -f "${BUNDLE_PATH}/${file}-${arch}" ]; then
846 OBJ_LIST="${OBJ_LIST} ${BUNDLE_PATH}/${file}-${arch}"
849 if [ -n "${OBJ_LIST}" ]; then
850 lipo -create ${OBJ_LIST} -o "${BUNDLE_PATH}/${file}"
852 if [ -f "${LibMagicInstallDir}/lib/${LibMagicLibrary}" -a "yes" = "${libmagic_deployment}" ]; then
853 private_framework LibMagic "${LibMagicInstallDir}/lib/${LibMagicLibrary}" "${LYX_BUNDLE_PATH}/${file}" \
854 "${LibMagicVersion}" "${LibMagicInstallHdr}"
856 if [ -f "${ASpellInstallDir}/lib/${ASpellLibrary}" -a "yes" = "${aspell_deployment}" ]; then
857 private_framework Aspell "${ASpellInstallDir}/lib/${ASpellLibrary}" "${LYX_BUNDLE_PATH}/${file}" \
858 "${ASpellVersion}" "${ASpellInstallHdr}"
860 if [ -f "${HunSpellInstallDir}/lib/${HunSpellLibrary}" -a "yes" = "${hunspell_deployment}" ]; then
861 private_framework Hunspell "${HunSpellInstallDir}/lib/${HunSpellLibrary}" "${LYX_BUNDLE_PATH}/${file}" \
862 "${HunSpellVersion}" "${HunSpellInstallDir}/include/hunspell/"*.hxx "${HunSpellInstallHdr}"
864 if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt_deployment}" ]; then
865 deploy_qtlibs "${LYX_BUNDLE_PATH}/${file}"
867 otool -L "${BUNDLE_PATH}/${file}" | while read reference ; do
868 case "${reference}" in
869 *"${LyxBuildDir}"*"("*")")
870 echo ERROR: Bad reference to "${reference}" found!!
875 for arch in ${ARCH_LIST} ; do
876 rm -f "${BUNDLE_PATH}"/*-${arch}
880 # -------------------------
881 # Create code sign signatures
882 # -------------------------
885 condir=$(content_directory "${target}"/lyx)
886 appdir=$(dirname "${condir}")
887 # have to sign frameworks first
888 for fwname in Aspell Hunspell LibMagic ; do
889 fwitem="${condir}"/$(framework_name "${fwname}")
890 if [ -d "${fwitem}" ]; then
891 codesign --verbose --force --sign "${CODESIGN_IDENTITY}" "${fwitem}"
895 "${condir}"/Frameworks/Qt*.framework/Versions/${QtFrameworkVersion} \
896 "${condir}"/PlugIns/*/lib*.dylib \
897 "${condir}"/Library/Spotlight/* \
898 "${target}"/inkscape \
900 "${target}"/tex2lyx \
901 "${target}"/lyxeditor \
902 "${target}"/lyxconvert \
903 "${target}"/lyxclient
905 codesign --verbose --force --sign "${CODESIGN_IDENTITY}" "${csitem}"
908 /usr/bin/codesign --verbose --force --sign "${CODESIGN_IDENTITY}" "${appdir}" || {
909 echo Warning: codesign failed with certificate named '"'${CODESIGN_IDENTITY}'"'
914 find "$@" -type f -print | while read file ; do
915 echo $(md5 -q "$file") "$file"
916 done | sort | while read hash file ; do
917 ppath=$(dirname "$pfile")
918 path=$(dirname "$file")
919 if [ "$phash" = "$hash" -a "$ppath" = "$path" ]; then
920 pname=$(basename "$pfile")
921 name=$(basename "$file")
922 cmp -s "$pfile" "$file" && (
924 cd "$path" && ln -s "$pname" "$name" && echo link for "$file" created
932 copy_dictionaries() {
933 if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_dictionaries}" ]; then
934 ASpellResources="${LyxAppPrefix}/Contents/Resources"
935 # try to reuse macports dictionaries for now
936 if [ -d /opt/local/lib/aspell-0.60 ]; then ASpellInstallDir=/opt/local ; fi
937 mkdir -p "${ASpellResources}"
938 echo Copy Aspell dictionaries from "${ASpellInstallDir}"
939 mkdir -p "${ASpellResources}"/data "${ASpellResources}"/dicts
940 cp -p -r "${ASpellInstallDir}/lib/aspell-0.60"/* "${ASpellResources}"/data
941 cp -p -r "${ASpellInstallDir}/share/aspell"/* "${ASpellResources}"/dicts
943 if [ -d "${HunSpellInstallDir}" -a "yes" = "${hunspell_dictionaries}" ]; then
944 HunSpellResources="${LyxAppPrefix}/Contents/Resources"
945 if [ -d "${DictionarySourceDir}" ]; then
946 ( cd "${DictionarySourceDir}" && find dicts -name .svn -prune -o -type f -print | cpio -pmdv "${HunSpellResources}" )
947 deduplicate "${HunSpellResources}"/dicts
950 if [ -d "${DictionarySourceDir}" -a "yes" = "${thesaurus_deployment}" ]; then
951 MyThesResources="${LyxAppPrefix}/Contents/Resources"
952 ( cd "${DictionarySourceDir}" && find thes -name .svn -prune -o -type f -print | cpio -pmdv "${MyThesResources}" )
953 deduplicate "${MyThesResources}"/thes
957 set_bundle_display_options() {
960 Y_POSITION=$((Y_BOUNDS - 65))
961 Y_BOUNDS=$((Y_BOUNDS + 20))
962 LYX_X_POSITION=$((X_BOUNDS / 4))
963 LYX_Y_POSITION=$Y_POSITION
964 APP_X_POSITION=$((3 * X_BOUNDS / 4))
965 APP_Y_POSITION=$Y_POSITION
966 WITH_DOCUMENTS=$(test -d "${1}/Documents" && echo true || echo false)
968 tell application "Finder"
969 set f to POSIX file ("${1}" as string) as alias
972 tell container window
973 set toolbar visible to false
974 set statusbar visible to false
975 set current view to icon view
977 set the bounds to {20, 50, $X_BOUNDS, $Y_BOUNDS}
980 set icon size of the icon view options of container window to 64
981 set arrangement of the icon view options of container window to not arranged
982 if ${WITH_DOCUMENTS} then
983 set position of item "Documents" to {$LYX_X_POSITION,0}
985 set position of item "${LyxName}.app" to {$LYX_X_POSITION,$LYX_Y_POSITION}
986 set position of item "Applications" to {$APP_X_POSITION,$APP_Y_POSITION}
987 set background picture of the icon view options\
988 of container window to file "background.png" of folder "Pictures"
989 set the bounds of the container window to {0, 0, $X_BOUNDS, $Y_BOUNDS}
990 update without registering applications
1002 BGSIZE=$(file "$DmgBackground" | awk -F , '/PNG/{print $2 }' | tr x ' ')
1003 BG_W=$(echo ${BGSIZE} | awk '{print $1 }')
1004 BG_H=$(echo ${BGSIZE} | awk '{print $2 }')
1006 rm -f "${DMGNAME}.sparseimage" "${DMGNAME}.dmg"
1008 hdiutil create -type SPARSE -size ${DMGSIZE:-"250m"} -fs HFS+ -volname "${LyxBase}" "${DMGNAME}"
1009 # Unmount currently mounted disk image
1010 mount | grep "${LyxBase}" && umount /Volumes/"${LyxBase}"
1011 test -d /Volumes/"${LyxBase}" && rmdir /Volumes/"${LyxBase}"
1013 # Mount the disk image
1014 DEVICES=$(hdiutil attach "${DMGNAME}.sparseimage" | cut -f 1)
1016 # Obtain device information
1017 DEVICE=$(echo $DEVICES | cut -f 1 -d ' ')
1018 VOLUME=$(mount |grep ${DEVICE} | cut -f 3 -d ' ')
1020 # copy in the application bundle
1021 ditto --hfsCompression "${LyxAppDir}.app" "${VOLUME}/${LyxName}.app"
1023 # copy in background image
1024 mkdir -p "${VOLUME}/Pictures"
1025 ditto --hfsCompression "${DmgBackground}" "${VOLUME}/Pictures/background.png"
1026 # symlink applications
1027 ln -s /Applications/ "${VOLUME}"/Applications
1028 test -d "${DocumentationDir}" && ditto --hfsCompression "${DocumentationDir}" "${VOLUME}"
1029 set_bundle_display_options "${VOLUME}" ${BG_W} ${BG_H}
1030 ${XCODE_DEVELOPER}/Tools/SetFile -a C "${VOLUME}"
1031 mv "${VOLUME}/Pictures" "${VOLUME}/.Pictures"
1033 # Unmount the disk image
1034 hdiutil detach ${DEVICE}
1036 # Convert the disk image to read-only
1037 hdiutil convert "${DMGNAME}.sparseimage" -format UDBZ -o "${DMGNAME}.dmg"
1038 rm -f "${DMGNAME}.sparseimage"
1041 # ------------------------------
1042 # Building distribution packages
1043 # ------------------------------
1046 test -n "${LyxAppZip}" && (
1047 cd "${LyxAppPrefix}" && zip -r "${LyxAppZip}" .
1051 for arch in ${ARCH_LIST} ; do
1052 DMGARCH="${DMGARCH}-${arch}"
1054 QtDmgArchSuffix=${QtMajorVersion}${DMGARCH}${QtAPI}.dmg
1056 test -n "${DMGLocation}" && (
1057 make_dmg "${DMGLocation}"
1058 if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt_deployment}" ]; then
1059 rm -f "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1060 echo move to "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1061 mv "${DMGLocation}/${DMGNAME}.dmg" "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1066 # ------------------------------
1068 # ------------------------------
1070 if [ ${LyxOnlyPackage:-"no"} = "no" ]; then
1074 test -n "${CODESIGN_IDENTITY}" && code_sign "${LYX_BUNDLE_PATH}"