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
155 echo " --codesign-identity=CSID ..." default is w/o CSID
157 echo "All other arguments with -- are passed to configure"
158 echo "including the defaults: ${LyXConfigureOptions}"
163 if [ -x "${LyxSourceDir}/configure" ]; then
165 echo "*" Configure options of LyX
167 "${LyxSourceDir}/configure" --help
173 NCPU=$(sysctl -n hw.ncpu)
175 if [ $NCPU -gt 1 ]; then
179 while [ $# -gt 0 ]; do
181 --with-qt-frameworks=*)
182 configure_qt_frameworks=$(echo ${1}|cut -d= -f2)
183 if [ "$configure_qt_frameworks" = "yes" ]; then
190 QTDIR=$(echo ${1}|cut -d= -f2)
193 --with-macosx-target=*)
194 MACOSX_DEPLOYMENT_TARGET=$(echo ${1}|cut -d= -f2)
198 SDKROOT=$(echo ${1}|cut -d= -f2)
201 SDKROOT="${DEVELOPER_SDKS}/MacOSX10.4u.sdk"
207 SDKROOT="${DEVELOPER_SDKS}/MacOSX${SDKROOT}.sdk"
208 if [ ! -d "${SDKROOT}" ]; then
209 echo Invalid SDKROOT given: "${SDKROOT}"
216 --codesign-identity=*)
217 CODESIGN_IDENTITY=$(echo "${1}"|cut -d= -f2)
220 --libmagic-deployment=*)
221 libmagic_deployment=$(echo ${1}|cut -d= -f2)
224 --aspell-deployment=*)
225 aspell_deployment=$(echo ${1}|cut -d= -f2)
226 aspell_dictionaries=$aspell_deployment
229 --hunspell-deployment=*)
230 hunspell_deployment=$(echo ${1}|cut -d= -f2)
231 hunspell_dictionaries=$hunspell_deployment
234 --thesaurus-deployment=*)
235 thesaurus_deployment=$(echo ${1}|cut -d= -f2)
239 qt_deployment=$(echo ${1}|cut -d= -f2)
243 ARCH=$(echo ${1}|cut -d= -f2|tr ',' ' ')
244 ARCH_LIST="${ARCH_LIST} ${ARCH}"
247 --with-dmg-location=*)
248 DMGLocation=$(echo ${1}|cut -d= -f2)
251 --with-binary-strip=yes)
256 LyxBuildDir=$(echo ${1}|cut -d= -f2)
260 LyXUtilitiesDir=$(echo ${1}|cut -d= -f2)
267 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
268 aspell_deployment="no"
272 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
273 hunspell_deployment="no"
277 QtOnlyPackage=$(echo ${1}|cut -d= -f2)
281 LyxOnlyPackage=$(echo ${1}|cut -d= -f2)
285 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
286 EnableCXX11="--enable-cxx11"
290 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
299 if [ "${configure_qt_frameworks}" != "yes" ]; then
300 QtInstallDir=${QTDIR:-"/opt/qt4"}
303 ARCH_LIST=${ARCH_LIST:-"ppc i386"}
307 LyxBuildDir=${LyxBuildDir:-$(dirname "${LyxSourceDir}")/lyx-build}
308 DMGLocation=${DMGLocation:-"${LyxBuildDir}"}
310 LyXUtilitiesDir=${LyXUtilitiesDir:-"${LyxBuildDir}"/utilities}
312 LibMagicSourceDir=${LIBMAGICDIR:-$(dirname "${LyxSourceDir}")/${LibMagicSource}}
313 LibMagicBuildDir="${LyxBuildDir}"/"${LibMagicSource}"
314 LibMagicInstallDir=${LibMagicInstallDir:-"${LyXUtilitiesDir}"}
315 LibMagicInstallHdr="${LibMagicInstallDir}/include/magic.h"
317 ASpellSourceDir=${ASPELLDIR:-$(dirname "${LyxSourceDir}")/${ASpellSource}}
318 ASpellBuildDir="${ASpellSourceDir}"
319 ASpellInstallDir=${ASpellInstallDir:-"${LyXUtilitiesDir}"}
320 ASpellInstallHdr="${ASpellInstallDir}/include/aspell.h"
322 HunSpellSourceDir=${HUNSPELLDIR:-$(dirname "${LyxSourceDir}")/${HunSpellSource}}
323 HunSpellBuildDir="${HunSpellSourceDir}"
324 HunSpellInstallDir=${HunSpellInstallDir:-"${LyXUtilitiesDir}"}
325 HunSpellInstallHdr="${HunSpellInstallDir}/include/hunspell/hunspell.h"
327 QtSourceDir=${QTSOURCEDIR:-$(dirname "${LyxSourceDir}")/${QtSourceVersion}}
328 QtBuildDir=${QtBuildDir:-"${LyxBuildDir}"/${QtBuildSubDir:-"qt-build"}}
330 DictionarySourceDir=${DICTIONARYDIR:-$(dirname "${LyxSourceDir}")/dictionaries}
331 DocumentationDir=$(dirname "${LyxSourceDir}")/Documents
332 DmgBackground="${LyxSourceDir}"/development/MacOSX/dmg-background.png
334 if [ -z "${LyXVersion}" ]; then
335 LyXVersion=$(grep AC_INIT "${LyxSourceDir}"/configure.ac | cut -d, -f2 | tr -d " ()")
337 LyXVersionSuffix=${LyXVersionSuffix:-$(echo "${LyXVersion}" | cut -d. -f1-2)}
338 case "${LyXVersion}" in
340 LyXGitCommitHash=$(cd "${LyxSourceDir}" ; git log -1 --pretty=format:%h)
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"
353 # ---------------------------------
354 # DON'T MODIFY ANYTHING BELOW HERE!
355 # ---------------------------------
357 # don't change order here...
358 case "${QtVersion}" in
360 QtLibraries=${QtLibraries:-"QtSvg QtXml QtPrintSupport QtWidgets QtGui QtNetwork QtConcurrent QtCore"}
361 QtFrameworkVersion="5"
364 QtLibraries=${QtLibraries:-"QtDbus QtSvg QtXml QtPrintSupport QtMacExtras QtWidgets QtGui QtNetwork QtConcurrent QtCore"}
365 QtFrameworkVersion="5"
368 QtLibraries=${QtLibraries:-"QtSvg QtXml QtPrintSupport QtMacExtras QtWidgets QtGui QtNetwork QtConcurrent QtCore"}
369 QtFrameworkVersion="5"
372 QtLibraries=${QtLibraries:-"QtSvg QtXml QtGui QtNetwork QtCore"}
373 QtFrameworkVersion="4"
377 DMGNAME="${LyxBase}${LyXGitCommitHash:+-}${LyXGitCommitHash}"
380 # Check for existing SDKs
381 SDKs=$(echo ${DEVELOPER_SDKS}/MacOSX10*sdk)
386 MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"10.5"}; export MACOSX_DEPLOYMENT_TARGET
387 case "${MACOSX_DEPLOYMENT_TARGET}" in
389 SDKROOT="${DEVELOPER_SDKS}/MacOSX10.6.sdk"; export SDKROOT
392 SDKROOT=${SDKROOT:-"${DEVELOPER_SDKS}/MacOSX10.5.sdk"}; export SDKROOT
397 MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"10.4"}; export MACOSX_DEPLOYMENT_TARGET
398 SDKROOT=${SDKROOT:-"${DEVELOPER_SDKS}/MacOSX10.5.sdk"}; export SDKROOT
401 echo Unknown or missing SDK for Mac OS X.
405 MYCFLAGS="-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} ${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}
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} ${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}
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} ${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}
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
642 find "${LyxAppPrefix}" -type d -exec chmod u+w '{}' \;
643 rm -rf "${LyxAppPrefix}"
646 case "${EnableCXX11}" in
649 export CXX="c++ -stdlib=libc++"
650 export CXXFLAGS=-std=c++11
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 )
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 )
668 # -------------------------------------
669 # Build LyX for different architectures
670 # -------------------------------------
672 if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_deployment}" ]; then
673 ConfigureExtraInc="--with-extra-inc=${ASpellInstallDir}/include"
674 ConfigureExtraLib="--with-extra-lib=${ASpellInstallDir}/lib"
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}"
684 LyXConfigureOptions="${LyXConfigureOptions} ${ConfigureExtraInc}"
685 LyXConfigureOptions="${LyXConfigureOptions} ${ConfigureExtraLib}"
687 for arch in ${ARCH_LIST} ; do
689 if [ -d "${LyxBuildDir}" ]; then rm -r "${LyxBuildDir}"; fi
690 mkdir -p "${LyxBuildDir}" && cd "${LyxBuildDir}"
692 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"
693 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"
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"
704 echo LDFLAGS="${LDFLAGS}"
706 echo CPPFLAGS="${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}"
720 echo ERROR: Cannot build and install ${file} for ${arch}.
727 content_directory() {
729 content=$(dirname "${target}")
730 content=$(dirname "${content}")
735 echo install_name_tool "$@"
736 install_name_tool "$@" || exit 1
739 private_framework() {
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)
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
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
770 installname -change "${source}" "@executable_path/../${fwdir}/${fwname}" "${target}"
774 source="${QtInstallDir}"
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
782 Translations = translations
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}"
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)
812 *@rpath/*"${libnm}"*"("*version*")"*)
813 echo rpath based name for ${libnm} is ok.
815 *"${libnm}"*"("*version*")"*)
817 "${source}/lib/${dirname}/${version}${libnm}"\
818 "@executable_path/../${fwdir}/${version}${libnm}"\
827 "${source}/lib/${dirname}/${version}${libnm}"\
828 "@executable_path/../${fwdir}/${version}${libnm}"\
831 if [ -d "${source}"/translations ]; then
832 if [ ! -d "${condir}/translations" ]; then
833 mkdir -p "${condir}/translations"
835 echo Copy Qt translations to "${condir}/translations"
836 cp -p "${source}"/translations/qt_*.qm "${condir}/translations"
840 # -------------------------
841 # Create universal binaries
842 # -------------------------
843 convert_universal() {
845 for file in ${LYX_FILE_LIST} ; do
847 for arch in ${ARCH_LIST} ; do
848 if [ -f "${BUNDLE_PATH}/${file}-${arch}" ]; then
849 OBJ_LIST="${OBJ_LIST} ${BUNDLE_PATH}/${file}-${arch}"
852 if [ -n "${OBJ_LIST}" ]; then
853 lipo -create ${OBJ_LIST} -o "${BUNDLE_PATH}/${file}"
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}"
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}"
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}"
867 if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt_deployment}" ]; then
868 deploy_qtlibs "${LYX_BUNDLE_PATH}/${file}"
870 otool -L "${BUNDLE_PATH}/${file}" | while read reference ; do
871 case "${reference}" in
872 *"${LyxBuildDir}"*"("*")")
873 echo ERROR: Bad reference to "${reference}" found!!
878 for arch in ${ARCH_LIST} ; do
879 rm -f "${BUNDLE_PATH}"/*-${arch}
883 # -------------------------
884 # Create code sign signatures
885 # -------------------------
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}"
898 "${condir}"/Frameworks/Qt*.framework/Versions/${QtFrameworkVersion} \
899 "${condir}"/PlugIns/*/lib*.dylib \
900 "${condir}"/Library/Spotlight/* \
901 "${target}"/inkscape \
903 "${target}"/tex2lyx \
904 "${target}"/lyxeditor \
905 "${target}"/lyxconvert \
906 "${target}"/lyxclient
908 codesign --verbose --force --sign "${CODESIGN_IDENTITY}" "${csitem}"
911 /usr/bin/codesign --verbose --force --sign "${CODESIGN_IDENTITY}" "${appdir}" || {
912 echo Warning: codesign failed with certificate named '"'${CODESIGN_IDENTITY}'"'
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" && (
927 cd "$path" && ln -s "$pname" "$name" && echo link for "$file" created
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
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
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
960 set_bundle_display_options() {
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)
971 tell application "Finder"
972 set f to POSIX file ("${1}" as string) as alias
975 tell container window
976 set toolbar visible to false
977 set statusbar visible to false
978 set current view to icon view
980 set the bounds to {20, 50, $X_BOUNDS, $Y_BOUNDS}
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}
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
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 }')
1009 rm -f "${DMGNAME}.sparseimage" "${DMGNAME}.dmg"
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}"
1016 # Mount the disk image
1017 DEVICES=$(hdiutil attach "${DMGNAME}.sparseimage" | cut -f 1)
1019 # Obtain device information
1020 DEVICE=$(echo $DEVICES | cut -f 1 -d ' ')
1021 VOLUME=$(mount |grep ${DEVICE} | cut -f 3 -d ' ')
1023 # copy in the application bundle
1024 ditto --hfsCompression "${LyxAppPrefix}" "${VOLUME}/${LyxName}.app"
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"
1036 # Unmount the disk image
1037 hdiutil detach ${DEVICE}
1039 # Convert the disk image to read-only
1040 hdiutil convert "${DMGNAME}.sparseimage" -format UDBZ -o "${DMGNAME}.dmg"
1041 rm -f "${DMGNAME}.sparseimage"
1044 # ------------------------------
1045 # Building distribution packages
1046 # ------------------------------
1049 test -n "${LyxAppZip}" && (
1050 cd "${LyxAppPrefix}" && zip -r "${LyxAppZip}" .
1054 for arch in ${ARCH_LIST} ; do
1055 DMGARCH="${DMGARCH}-${arch}"
1057 QtDmgArchSuffix=${QtMajorVersion}${DMGARCH}${QtAPI}.dmg
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}"
1069 # ------------------------------
1071 # ------------------------------
1073 if [ ${LyxOnlyPackage:-"no"} = "no" ]; then
1077 test -n "${CODESIGN_IDENTITY}" && code_sign "${LYX_BUNDLE_PATH}"
1078 find "${LyxAppPrefix}" -type d -exec chmod a-w '{}' \;