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)
288 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
289 EnableCXX11="--enable-cxx11"
293 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
302 if [ "${configure_qt_frameworks}" != "yes" ]; then
303 QtInstallDir=${QTDIR:-"/opt/qt4"}
306 ARCH_LIST=${ARCH_LIST:-"ppc i386"}
310 LyxBuildDir=${LyxBuildDir:-$(dirname "${LyxSourceDir}")/lyx-build}
311 DMGLocation=${DMGLocation:-"${LyxBuildDir}"}
313 LyXUtilitiesDir=${LyXUtilitiesDir:-"${LyxBuildDir}"/utilities}
315 LibMagicSourceDir=${LIBMAGICDIR:-$(dirname "${LyxSourceDir}")/${LibMagicSource}}
316 LibMagicBuildDir="${LyxBuildDir}"/"${LibMagicSource}"
317 LibMagicInstallDir=${LibMagicInstallDir:-"${LyXUtilitiesDir}"}
318 LibMagicInstallHdr="${LibMagicInstallDir}/include/magic.h"
320 ASpellSourceDir=${ASPELLDIR:-$(dirname "${LyxSourceDir}")/${ASpellSource}}
321 ASpellBuildDir="${ASpellSourceDir}"
322 ASpellInstallDir=${ASpellInstallDir:-"${LyXUtilitiesDir}"}
323 ASpellInstallHdr="${ASpellInstallDir}/include/aspell.h"
325 HunSpellSourceDir=${HUNSPELLDIR:-$(dirname "${LyxSourceDir}")/${HunSpellSource}}
326 HunSpellBuildDir="${HunSpellSourceDir}"
327 HunSpellInstallDir=${HunSpellInstallDir:-"${LyXUtilitiesDir}"}
328 HunSpellInstallHdr="${HunSpellInstallDir}/include/hunspell/hunspell.h"
330 QtSourceDir=${QTSOURCEDIR:-$(dirname "${LyxSourceDir}")/${QtSourceVersion}}
331 QtBuildDir=${QtBuildDir:-"${LyxBuildDir}"/${QtBuildSubDir:-"qt-build"}}
333 DictionarySourceDir=${DICTIONARYDIR:-$(dirname "${LyxSourceDir}")/dictionaries}
334 DocumentationDir=$(dirname "${LyxSourceDir}")/Documents
335 DmgBackground="${LyxSourceDir}"/development/MacOSX/dmg-background.png
337 if [ -z "${LyXVersion}" ]; then
338 LyXVersion=$(grep AC_INIT "${LyxSourceDir}"/configure.ac | cut -d, -f2 | tr -d " []()")
340 LyXVersionSuffix=${LyXVersionSuffix:-$(echo "${LyXVersion}" | cut -d. -f1-2)}
341 case "${LyXVersion}" in
343 LyXGitCommitHash=$(cd "${LyxSourceDir}" ; git log -1 --pretty=format:%h)
348 LyxBase="${LyxName}-${LyXVersion}"
349 LyxApp="${LyxBase}.app"
350 LyxAppDir="${LyxBuildDir}"/"${LyxBase}"
351 LyxBuildDir="${LyxAppDir}.build"
352 LyxAppPrefix="${LyxAppDir}.app"
353 # if zip file is needed... remove the comment sign
354 #LyxAppZip="${LyxAppPrefix}.zip"
356 # ---------------------------------
357 # DON'T MODIFY ANYTHING BELOW HERE!
358 # ---------------------------------
360 # don't change order here...
361 case "${QtVersion}" in
363 QtLibraries=${QtLibraries:-"QtSvg QtXml QtPrintSupport QtWidgets QtGui QtNetwork QtConcurrent QtCore"}
364 QtFrameworkVersion="5"
367 QtLibraries=${QtLibraries:-"QtDBus QtSvg QtXml QtPrintSupport QtMacExtras QtWidgets QtGui QtNetwork QtConcurrent QtCore"}
368 QtFrameworkVersion="5"
371 QtLibraries=${QtLibraries:-"QtSvg QtXml QtPrintSupport QtMacExtras QtWidgets QtGui QtNetwork QtConcurrent QtCore"}
372 QtFrameworkVersion="5"
375 QtLibraries=${QtLibraries:-"QtCore5Compat QtDBus QtSvg QtXml QtPrintSupport QtSvgWidgets QtWidgets QtGui QtNetwork QtConcurrent QtCore"}
376 QtFrameworkVersion="A"
379 QtLibraries=${QtLibraries:-"QtSvg QtXml QtGui QtNetwork QtCore"}
380 QtFrameworkVersion="4"
384 DMGNAME="${LyxBase}${LyXGitCommitHash:+-}${LyXGitCommitHash}"
387 # Check for existing SDKs
388 SDKs=$(echo ${DEVELOPER_SDKS}/MacOSX1[01]*sdk)
393 MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"10.5"}; export MACOSX_DEPLOYMENT_TARGET
394 case "${MACOSX_DEPLOYMENT_TARGET}" in
396 SDKROOT="${DEVELOPER_SDKS}/MacOSX10.6.sdk"; export SDKROOT
399 SDKROOT=${SDKROOT:-"${DEVELOPER_SDKS}/MacOSX10.5.sdk"}; export SDKROOT
404 MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"10.4"}; export MACOSX_DEPLOYMENT_TARGET
405 SDKROOT=${SDKROOT:-"${DEVELOPER_SDKS}/MacOSX10.5.sdk"}; export SDKROOT
408 echo Unknown or missing SDK for Mac OS X.
412 MYCFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}"
413 MYLDFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}"
416 echo Build Qt library ${QtSourceDir}
417 if [ "${QtInstallDir}" = "${QtBuildDir}" ]; then
418 echo Bad install directory for Qt.
419 echo Must be different from build directory "${QtBuildDir}".
423 mkdir -p "${QtBuildDir}" && cd "${QtBuildDir}"
424 echo configure options:
425 echo ${QtConfigureOptions} ${QTARCHS} -prefix "${QtInstallDir}"
426 "${QtSourceDir}"/configure ${QtConfigureOptions} ${QTARCHS} -prefix "${QtInstallDir}"
427 make -j1 && make -j1 install
431 case ${QtOnlyPackage:-"no"} in
437 if [ "${configure_qt_frameworks}" != "yes" -a -d "${QtSourceDir}" -a ! \( -d "${QtBuildDir}" -a -d "${QtInstallDir}" \) ]; then
443 if [ -d "${LibMagicSourceDir}" -a ! -f "${LibMagicInstallHdr}" ]; then
444 # we have a private libmagic (file(1)) source tree at hand...
445 # so let's build and install it
446 if [ -z "${LibMagicVersion}" ]; then
447 LibMagicVersion=$(grep AC_INIT "${LibMagicSourceDir}"/configure.ac | cut -d, -f2|tr -d " []()")
450 LibMagicName="LibMagic"
451 LibMagicBase="${LibMagicName}-${LibMagicVersion}"
453 echo Build libmagic library ${LibMagicBase}
454 echo configure options:
455 echo --prefix="${LibMagicInstallDir}" ${LibMagicConfigureOptions}
457 mkdir -p "${LibMagicBuildDir}" && cd "${LibMagicBuildDir}"
459 # ----------------------------------------
460 # Build LibMagic for different architectures
461 # ----------------------------------------
462 FILE_LIST="${LibMagicLibrary}"
464 for arch in ${ARCH_LIST} ; do
465 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"; export CPPFLAGS
466 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYLDFLAGS}"; export LDFLAGS
467 "${LibMagicSourceDir}/configure"\
468 --prefix="${LibMagicInstallDir}"\
469 ${LibMagicConfigureOptions}
470 make && make install${strip}
471 for file in ${FILE_LIST} ; do
472 if [ -f "${LibMagicInstallDir}"/lib/${file} ]; then
473 mv "${LibMagicInstallDir}"/lib/${file}\
474 "${LibMagicInstallDir}"/lib/${file}-${arch}
476 echo Cannot build and install LibMagic for ${arch}.
481 # -------------------------
482 # Create universal binaries
483 # -------------------------
484 for file in ${FILE_LIST} ; do
486 for arch in ${ARCH_LIST} ; do
487 OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
490 cd "${LibMagicInstallDir}"
491 lipo -create ${OBJ_LIST} -o lib/${file}
492 # check for the "missing link"...
493 test -f lib/libmagic.dylib || (cd lib ; ln -s "${LibMagicLibrary}" libmagic.dylib)
499 for arch in ${ARCH_LIST} ; do
500 rm -f "${LibMagicInstallDir}"/lib/*-${arch}
504 if [ -d "${HunSpellSourceDir}" -a ! -f "${HunSpellInstallHdr}" ]; then
505 # we have a private HunSpell source tree at hand...
506 # so let's build and install it
507 if [ -z "${HunSpellVersion}" ]; then
508 HunSpellVersion=$(grep AC_INIT "${HunSpellSourceDir}"/configure.ac | cut -d, -f2|tr -d " []()")
511 HunSpellName="Hunspell"
512 HunSpellBase="${HunSpellName}-${HunSpellVersion}"
514 echo Build hunspell library ${HunSpellBase}
515 echo configure options:
516 echo --prefix="${HunSpellInstallDir}" ${HunspellConfigureOptions}
518 mkdir -p "${HunSpellBuildDir}" && cd "${HunSpellBuildDir}"
520 # ----------------------------------------
521 # Build HunSpell for different architectures
522 # ----------------------------------------
523 FILE_LIST="${HunSpellLibrary}"
525 for arch in ${ARCH_LIST} ; do
527 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"; export CPPFLAGS
528 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYLDFLAGS}"; export LDFLAGS
529 "${HunSpellSourceDir}/configure"\
530 --prefix="${HunSpellInstallDir}"\
531 ${HunspellConfigureOptions}
532 make && make install${strip}
533 for file in ${FILE_LIST} ; do
534 if [ -f "${HunSpellInstallDir}"/lib/${file} ]; then
535 mv "${HunSpellInstallDir}"/lib/${file}\
536 "${HunSpellInstallDir}"/lib/${file}-${arch}
538 echo Cannot build and install HunSpell for ${arch}.
543 # -------------------------
544 # Create universal binaries
545 # -------------------------
546 for file in ${FILE_LIST} ; do
548 for arch in ${ARCH_LIST} ; do
549 OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
552 cd "${HunSpellInstallDir}"
553 lipo -create ${OBJ_LIST} -o lib/${file}
554 # check for the "missing link"...
555 test -f lib/libhunspell.dylib || (cd lib ; ln -s "${HunSpellLibrary}" libhunspell.dylib)
561 for arch in ${ARCH_LIST} ; do
562 rm -f "${HunSpellInstallDir}"/lib/*-${arch}
566 if [ -d "${ASpellSourceDir}" -a ! -f "${ASpellInstallHdr}" -a "yes" = "${aspell_deployment}" ]; then
567 # we have a private ASpell source tree at hand...
568 # so let's build and install it
569 if [ -z "${ASpellVersion}" ]; then
570 ASpellVersion=$(grep AC_INIT "${ASpellSourceDir}"/configure.ac | cut -d, -f2|tr -d " []()")
574 ASpellBase="${ASpellName}-${ASpellVersion}"
576 echo Build aspell library ${ASpellBase}
577 echo configure options:
578 echo --prefix="${ASpellInstallDir}" ${AspellConfigureOptions}
580 # ASpell builds inplace only :(
581 cd "${ASpellSourceDir}"
583 # ----------------------------------------
584 # Build ASpell for different architectures
585 # ----------------------------------------
586 FILE_LIST="${ASpellLibrary}"
588 for arch in ${ARCH_LIST} ; do
590 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"; export CPPFLAGS
591 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYLDFLAGS}"; export LDFLAGS
592 CXXFLAGS=-g "${ASpellSourceDir}/configure"\
593 --prefix="${ASpellInstallDir}"\
594 ${AspellConfigureOptions}
595 make && make install${aspellstrip}
596 for file in ${FILE_LIST} ; do
597 if [ -f "${ASpellInstallDir}"/lib/${file} ]; then
598 mv "${ASpellInstallDir}"/lib/${file}\
599 "${ASpellInstallDir}"/lib/${file}-${arch}
601 echo Cannot build and install ASpell for ${arch}.
606 # -------------------------
607 # Create universal binaries
608 # -------------------------
609 for file in ${FILE_LIST} ; do
611 for arch in ${ARCH_LIST} ; do
612 OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
615 cd "${ASpellInstallDir}"
616 lipo -create ${OBJ_LIST} -o lib/${file}
622 for arch in ${ARCH_LIST} ; do
623 rm -f "${ASpellInstallDir}"/lib/*-${arch}
629 echo "Frameworks/${1}.framework"
632 LYX_FILE_LIST="lyx lyxclient tex2lyx lyxconvert"
633 BUNDLE_PATH="Contents/MacOS"
634 LYX_BUNDLE_PATH="${LyxAppPrefix}/${BUNDLE_PATH}"
638 if [ -n "${LyxAppZip}" -a -f "${LyxAppZip}" ]; then rm "${LyxAppZip}"; fi
639 if [ -d "${LyxAppPrefix}" ]; then
640 find "${LyxAppPrefix}" -type d -exec chmod u+w '{}' \;
641 rm -rf "${LyxAppPrefix}"
644 case "${EnableCXX11}" in
647 export CXX="c++ -stdlib=libc++"
648 export CXXFLAGS=-std=c++11
652 # -------------------------------------
653 # Automate configure check
654 # -------------------------------------
655 if [ ! -f "${LyxSourceDir}"/configure -o "${LyxSourceDir}"/configure -ot "${LyxSourceDir}"/configure.ac ]; then
656 ( cd "${LyxSourceDir}" && sh autogen.sh )
658 find "${LyxSourceDir}" -name Makefile.am -print | while read file ; do
659 dname=$(dirname "$file")
660 if [ -f "$dname/Makefile.in" -a "$dname/Makefile.in" -ot "$file" ]; then
661 ( cd "${LyxSourceDir}" && sh autogen.sh )
666 # -------------------------------------
667 # Build LyX for different architectures
668 # -------------------------------------
670 if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_deployment}" ]; then
671 ConfigureExtraInc="--with-extra-inc=${ASpellInstallDir}/include"
672 ConfigureExtraLib="--with-extra-lib=${ASpellInstallDir}/lib"
675 if [ -d "${HunSpellInstallDir}" -a "yes" = "${hunspell_deployment}" ]; then
676 HunSpellFramework=$(framework_name Hunspell)
677 HunSpellFramework=$(basename "${HunSpellFramework}")
678 ConfigureExtraInc="--with-extra-inc=${HunSpellInstallDir}/include"
679 ConfigureExtraLib="--with-extra-lib=${HunSpellInstallDir}/lib"
680 # LyXConfigureOptions="${LyXConfigureOptions} --with-hunspell-framework=${HunSpellFramework}"
682 LyXConfigureOptions="${LyXConfigureOptions} ${ConfigureExtraInc}"
683 LyXConfigureOptions="${LyXConfigureOptions} ${ConfigureExtraLib}"
685 for arch in ${ARCH_LIST} ; do
687 if [ -d "${LyxBuildDir}" ]; then rm -r "${LyxBuildDir}"; fi
688 mkdir -p "${LyxBuildDir}" && cd "${LyxBuildDir}"
690 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch}"
691 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch}"
693 if [ "$configure_qt_frameworks" = "yes" ]; then
694 export QT_CORE_CFLAGS="-FQtCore"
695 export QT_CORE_LIBS="-framework QtCore"
696 export QT_FRONTEND_CFLAGS="-FQtGui"
697 export QT_FRONTEND_LIBS="-framework QtGui"
698 CPPFLAGS="${CPPFLAGS} -I${SDKROOT}/Library/Frameworks/QtCore.framework/Headers"
699 CPPFLAGS="${CPPFLAGS} -I${SDKROOT}/Library/Frameworks/QtGui.framework/Headers"
702 echo LDFLAGS="${LDFLAGS}"
704 echo CPPFLAGS="${CPPFLAGS}"
706 echo CONFIGURE_OPTIONS="${LyXConfigureOptions}" ${QtInstallDir:+"--with-qt-dir=${QtInstallDir}"}
707 "${LyxSourceDir}/configure"\
708 --prefix="${LyxAppPrefix}" --with-version-suffix="-${LyXVersionSuffix}"\
709 ${QtInstallDir:+"--with-qt-dir=${QtInstallDir}"} \
710 ${LyXConfigureOptions}\
711 --enable-build-type=rel && \
712 make ${MAKEJOBS} && make install${strip}
713 for file in ${LYX_FILE_LIST} ; do
714 if [ -f "${LYX_BUNDLE_PATH}/${file}" ]; then
715 mv "${LYX_BUNDLE_PATH}/${file}"\
716 "${LYX_BUNDLE_PATH}/${file}-${arch}"
718 echo ERROR: Cannot build and install ${file} for ${arch}.
725 content_directory() {
727 content=$(dirname "${target}")
728 content=$(dirname "${content}")
733 echo install_name_tool "$@"
734 install_name_tool "$@" || exit 1
737 private_framework() {
741 version=$(echo ${1:-"1.1.1"}.1.1.1 | cut -d. -f1-3) ; shift
742 fwdir=$(framework_name "${fwname}")
743 condir=$(content_directory "${target}")
744 libnm=$(basename "${source}")
745 libid="org.lyx."$(echo "${libnm}" | cut -d. -f1)
746 svrsn=$(echo "${version}" | cut -d. -f1-2)
748 mkdir -p "${condir}/${fwdir}"/Versions/${fwvrsn}/Headers
749 mkdir -p "${condir}/${fwdir}"/Versions/${fwvrsn}/Resources
750 if [ ! -f "${condir}/${fwdir}/Versions/${fwvrsn}/${fwname}" ]; then
751 cp -p "${source}" "${condir}/${fwdir}/Versions/${fwvrsn}/${fwname}"
752 for hfile in "$@" ; do
753 test -f "${hfile}" && cp -p "${hfile}" "${condir}/${fwdir}"/Versions/${fwvrsn}/Headers
755 ln -s ${fwvrsn} "${condir}/${fwdir}/Versions/Current"
756 ln -s Versions/Current/Headers "${condir}/${fwdir}/Headers"
757 ln -s Versions/Current/Resources "${condir}/${fwdir}/Resources"
758 ln -s Versions/Current/"${fwname}" "${condir}/${fwdir}/${fwname}"
759 installname -id "@executable_path/../${fwdir}/${fwname}" "${condir}/${fwdir}/${fwname}"
760 if [ -f "${LyxSourceDir}"/development/LyX-Mac-frameworks-template.plist ]; then
761 cat "${LyxSourceDir}"/development/LyX-Mac-frameworks-template.plist | sed \
762 -e "s/@CFBundleExecutable@/${fwname}/" \
763 -e "s/@CFBundleIdentifier@/${libid}/" \
764 -e "s/@CFBundleShortVersionString@/${svrsn}/" \
765 -e "s/@CFBundleVersion@/${version}/" > "${condir}/${fwdir}"/Resources/Info.plist
768 installname -change "${source}" "@executable_path/../${fwdir}/${fwname}" "${target}"
772 source="${QtInstallDir}"
774 version="Versions/${QtFrameworkVersion}/"
775 condir=$(content_directory "${target}")
776 mkdir -p "${condir}/Resources"
777 test -f "${condir}/Resources/qt.conf" || cat - > "${condir}/Resources/qt.conf" <<-EOF
780 Translations = translations
782 if [ ! -d "${condir}/PlugIns" ]; then
783 mkdir -p "${condir}/PlugIns"
784 find "${source}/plugins" -name \*.dylib -print | grep -v _debug.dylib | while read libname ; do
785 echo Copy plugin "${libname}"
786 dylib=$(basename "${libname}")
787 dirname=$(dirname "${libname}")
788 dirname=$(basename "${dirname}")
789 mkdir -p "${condir}/PlugIns/${dirname}"
790 cp -p "${libname}" "${condir}/PlugIns/${dirname}"
793 for libnm in ${QtLibraries} ; do
794 fwdir=$(framework_name "$libnm")
795 dirname=$(dirname "${fwdir}")
796 mkdir -p "${condir}/${dirname}"
797 dirname=$(basename "${fwdir}")
798 test -d "${condir}/${fwdir}" || (
799 echo Copy framework "${source}/lib/"$(basename "${fwdir}")
800 cp -pR "${source}/lib/"$(basename "${fwdir}") "${condir}/${fwdir}"
801 rm -f "${condir}/${fwdir}/${libnm}"_debug "${condir}/${fwdir}/${version}${libnm}"_debug
802 test -f "${condir}/${fwdir}/${libnm}".prl && mv "${condir}/${fwdir}/${libnm}".prl "${condir}/${fwdir}"/Resources
803 test -f "${condir}/${fwdir}/${libnm}"_debug.prl && mv "${condir}/${fwdir}/${libnm}"_debug.prl "${condir}/${fwdir}"/Resources
804 installname -id "@executable_path/../${fwdir}/${version}${libnm}" "${condir}/${fwdir}/${version}${libnm}"
805 find "${condir}/PlugIns" "${condir}/"$(dirname "${fwdir}") -name Headers -prune -o -type f -print | while read filename ; do
806 if [ "${filename}" != "${target}" ]; then
807 otool -L "${filename}" 2>/dev/null | sort -u | while read library ; do
808 # pattern match for: /path/to/qt/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.6.0, current version 4.6.2)
810 *@rpath/*"${libnm}"*"("*version*")"*)
811 # echo rpath based name for ${libnm} is ok.
813 *"${libnm}"*"("*version*")"*)
815 "${source}/lib/${dirname}/${version}${libnm}"\
816 "@executable_path/../${fwdir}/${version}${libnm}"\
825 "${source}/lib/${dirname}/${version}${libnm}"\
826 "@executable_path/../${fwdir}/${version}${libnm}"\
829 if [ -d "${source}"/translations ]; then
830 if [ ! -d "${condir}/translations" ]; then
831 mkdir -p "${condir}/translations"
833 echo Copy Qt translations to "${condir}/translations"
834 cp -p "${source}"/translations/qt_*.qm "${condir}/translations"
838 # -------------------------
839 # Create universal binaries
840 # -------------------------
841 convert_universal() {
843 for file in ${LYX_FILE_LIST} ; do
845 for arch in ${ARCH_LIST} ; do
846 if [ -f "${BUNDLE_PATH}/${file}-${arch}" ]; then
847 OBJ_LIST="${OBJ_LIST} ${BUNDLE_PATH}/${file}-${arch}"
850 if [ -n "${OBJ_LIST}" ]; then
851 lipo -create ${OBJ_LIST} -o "${BUNDLE_PATH}/${file}"
853 if [ -f "${LibMagicInstallDir}/lib/${LibMagicLibrary}" -a "yes" = "${libmagic_deployment}" ]; then
854 private_framework LibMagic "${LibMagicInstallDir}/lib/${LibMagicLibrary}" "${LYX_BUNDLE_PATH}/${file}" \
855 "${LibMagicVersion}" "${LibMagicInstallHdr}"
857 if [ -f "${ASpellInstallDir}/lib/${ASpellLibrary}" -a "yes" = "${aspell_deployment}" ]; then
858 private_framework Aspell "${ASpellInstallDir}/lib/${ASpellLibrary}" "${LYX_BUNDLE_PATH}/${file}" \
859 "${ASpellVersion}" "${ASpellInstallHdr}"
861 if [ -f "${HunSpellInstallDir}/lib/${HunSpellLibrary}" -a "yes" = "${hunspell_deployment}" ]; then
862 private_framework Hunspell "${HunSpellInstallDir}/lib/${HunSpellLibrary}" "${LYX_BUNDLE_PATH}/${file}" \
863 "${HunSpellVersion}" "${HunSpellInstallDir}/include/hunspell/"*.hxx "${HunSpellInstallHdr}"
865 if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt_deployment}" ]; then
866 deploy_qtlibs "${LYX_BUNDLE_PATH}/${file}"
868 otool -L "${BUNDLE_PATH}/${file}" | while read reference ; do
869 case "${reference}" in
870 *"${LyxBuildDir}"*"("*")")
871 echo ERROR: Bad reference to "${reference}" found!!
876 for arch in ${ARCH_LIST} ; do
877 rm -f "${BUNDLE_PATH}"/*-${arch}
881 # -------------------------
882 # Create code sign signatures
883 # -------------------------
886 condir=$(content_directory "${target}"/lyx)
887 appdir=$(dirname "${condir}")
888 # have to sign frameworks first
889 for fwname in Aspell Hunspell LibMagic ; do
890 fwitem="${condir}"/$(framework_name "${fwname}")
891 if [ -d "${fwitem}" ]; then
892 codesign --verbose --force --sign "${CODESIGN_IDENTITY}" "${fwitem}"
896 "${condir}"/Frameworks/Qt*.framework/Versions/${QtFrameworkVersion} \
897 "${condir}"/PlugIns/*/lib*.dylib \
898 "${condir}"/Library/Spotlight/* \
899 "${target}"/inkscape \
900 "${target}"/lilypond \
901 "${target}"/lilypond-book \
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 "${DictionarySourceDir}" -a "yes" = "${hunspell_dictionaries}" ]; then
947 HunSpellResources="${LyxAppPrefix}/Contents/Resources"
948 ( cd "${DictionarySourceDir}" && find dicts -name .svn -prune -o -type f -print | cpio -pmdv "${HunSpellResources}" )
949 deduplicate "${HunSpellResources}"/dicts
951 if [ -d "${DictionarySourceDir}" -a "yes" = "${thesaurus_deployment}" ]; then
952 MyThesResources="${LyxAppPrefix}/Contents/Resources"
953 ( cd "${DictionarySourceDir}" && find thes -name .svn -prune -o -type f -print | cpio -pmdv "${MyThesResources}" )
954 deduplicate "${MyThesResources}"/thes
958 set_bundle_display_options() {
961 Y_POSITION=$((Y_BOUNDS - 65))
962 Y_BOUNDS=$((Y_BOUNDS + 20))
963 LYX_X_POSITION=$((X_BOUNDS / 4))
964 LYX_Y_POSITION=$Y_POSITION
965 APP_X_POSITION=$((3 * X_BOUNDS / 4))
966 APP_Y_POSITION=$Y_POSITION
967 WITH_DOCUMENTS=$(test -d "${1}/Documents" && echo true || echo false)
969 tell application "Finder"
970 set f to POSIX file ("${1}" as string) as alias
973 tell container window
974 set toolbar visible to false
975 set statusbar visible to false
976 set current view to icon view
978 set the bounds to {20, 50, $X_BOUNDS, $Y_BOUNDS}
981 set icon size of the icon view options of container window to 64
982 set arrangement of the icon view options of container window to not arranged
983 if ${WITH_DOCUMENTS} then
984 set position of item "Documents" to {$LYX_X_POSITION,0}
986 set position of item "${LyxName}.app" to {$LYX_X_POSITION,$LYX_Y_POSITION}
987 set position of item "Applications" to {$APP_X_POSITION,$APP_Y_POSITION}
988 set background picture of the icon view options\
989 of container window to file "background.png" of folder "Pictures"
990 set the bounds of the container window to {0, 0, $X_BOUNDS, $Y_BOUNDS}
991 update without registering applications
1003 BGSIZE=$(file "$DmgBackground" | awk -F , '/PNG/{print $2 }' | tr x ' ')
1004 BG_W=$(echo ${BGSIZE} | awk '{print $1 }')
1005 BG_H=$(echo ${BGSIZE} | awk '{print $2 }')
1007 rm -f "${DMGNAME}.sparseimage" "${DMGNAME}.dmg"
1009 hdiutil create -type SPARSE -size ${DMGSIZE:-"250m"} -fs HFS+ -volname "${LyxBase}" "${DMGNAME}"
1010 # Unmount currently mounted disk image
1011 mount | grep "${LyxBase}" && umount /Volumes/"${LyxBase}"
1012 test -d /Volumes/"${LyxBase}" && rmdir /Volumes/"${LyxBase}"
1014 # Mount the disk image
1015 DEVICES=$(hdiutil attach "${DMGNAME}.sparseimage" | cut -f 1)
1017 # Obtain device information
1018 DEVICE=$(echo $DEVICES | cut -f 1 -d ' ')
1019 VOLUME=$(mount |grep ${DEVICE} | cut -f 3 -d ' ')
1021 # copy in the application bundle
1022 ditto --hfsCompression "${LyxAppPrefix}" "${VOLUME}/${LyxName}.app"
1024 # copy in background image
1025 mkdir -p "${VOLUME}/Pictures"
1026 ditto --hfsCompression "${DmgBackground}" "${VOLUME}/Pictures/background.png"
1027 # symlink applications
1028 ln -s /Applications/ "${VOLUME}"/Applications
1029 test -d "${DocumentationDir}" && ditto --hfsCompression "${DocumentationDir}" "${VOLUME}"
1030 set_bundle_display_options "${VOLUME}" ${BG_W} ${BG_H}
1031 PATH="${XCODE_DEVELOPER}/Tools:$PATH" SetFile -a C "${VOLUME}"
1032 mv "${VOLUME}/Pictures" "${VOLUME}/.Pictures"
1034 # Unmount the disk image
1035 hdiutil detach ${DEVICE}
1037 # Convert the disk image to read-only
1038 hdiutil convert "${DMGNAME}.sparseimage" -format UDBZ -o "${DMGNAME}.dmg"
1039 rm -f "${DMGNAME}.sparseimage"
1042 # ------------------------------
1043 # Building distribution packages
1044 # ------------------------------
1047 test -n "${LyxAppZip}" && (
1048 cd "${LyxAppPrefix}" && zip -r "${LyxAppZip}" .
1052 for arch in ${ARCH_LIST} ; do
1053 DMGARCH="${DMGARCH}-${arch}"
1055 QtDmgArchSuffix="qt"${QtMajorVersion}${DMGARCH}${QtAPI}.dmg
1057 test -n "${DMGLocation}" && (
1058 make_dmg "${DMGLocation}"
1059 if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt_deployment}" ]; then
1060 rm -f "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1061 echo move to "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1062 mv "${DMGLocation}/${DMGNAME}.dmg" "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1067 # ------------------------------
1069 # ------------------------------
1071 if [ ${LyxOnlyPackage:-"no"} = "no" ]; then
1075 test -n "${CODESIGN_IDENTITY}" && code_sign "${LYX_BUNDLE_PATH}"
1076 find "${LyxAppPrefix}" -type d -exec chmod go-w '{}' \;