5 # This script automates creating universal binaries of LyX on Mac.
6 # Author: Bennett Helm (and extended by Konrad Hofbauer)
7 # latest changes by Stephan Witt
8 # Last modified: February 2020
10 QtAPI=${QtAPI:-"-cocoa"}
11 QtVersion=${QtVersion:-"4.6.3"}
12 QtSourceVersion=${QtSourceVersion:-"qt-everywhere-opensource-src-${QtVersion}"}
13 QtBuildSubDir="qt-${QtVersion}-build${QtAPI}"
14 QtConfigureOptions=${QtConfigureOptions:-"-release"}
15 QtSkipComponents=${QtSkipComponents:-"qtconnectivity qtscript qtquickcontrols qtmultimedia qtvirtualkeyboard qtwayland qtwebengine"}
16 LibMagicVersion=${LibMagicVersion:-"5.19"}
17 LibMagicSource="file-${LibMagicVersion}"
18 LibMagicLibrary="libmagic.1.dylib"
20 ASpellVersion=${ASpellVersion:-"0.60.6.1"}
21 ASpellSource="aspell-${ASpellVersion}"
22 ASpellLibrary="libaspell.15.dylib"
24 HunSpellVersion=${HunSpellVersion:-"1.3.3"}
25 HunSpellSource="hunspell-${HunSpellVersion}"
26 HunSpellLibrary="libhunspell-1.3.0.dylib"
28 unset DYLD_LIBRARY_PATH LD_LIBRARY_PATH
31 # * a decent checkout of LyX sources (probably you have it already)
32 # * Qt - build with shared or static libraries for the used platforms (default: i386 and ppc)
33 # or - an unpacked source tree of Qt in $QTSOURCEDIR or in the sibling directory (variable QtSourceVersion)
34 # * for aspell support:
35 # the aspell sources placed in a sibling directory (variable ASpellSource)
36 # * for hunspell support:
37 # the hunspell sources placed in a sibling directory (variable HunSpellSource)
38 # * for dictionary deployment (only hunspell dicts and mythes thesauri are deployed per default):
39 # - aspell: the dictionary files of macports (in /opt/local/share/aspell and /opt/local/lib/aspell-0.60)
40 # - hunspell: the dictionary files in the sibling directory dictionaries/dicts
41 # - mythes: the data and idx files in the sibling directory dictionaries/thes
42 # * for magic file type detection support:
43 # the libmagic sources placed in a sibling directory (variable LibMagicSource)
45 LyXConfigureOptions="--enable-warnings --enable-optimization=-Os --with-x=no"
46 LyXConfigureOptions="${LyXConfigureOptions} --disable-stdlib-debug"
47 AspellConfigureOptions="--enable-warnings --enable-optimization=-O0 --enable-debug --disable-nls --enable-compile-in-filters --disable-pspell-compatibility"
48 HunspellConfigureOptions="--with-warnings --disable-nls --disable-static"
50 QtMajorVersion=$(echo "${QtVersion}"|cut -d. -f1)
51 QtConfigureOptions="${QtConfigureOptions} -opensource -silent -shared -confirm-license"
52 # stupid special case...
53 case "${QtVersion}:${QtAPI}" in
55 QtConfigureOptions="${QtConfigureOptions} -fast -no-exceptions"
56 QtConfigureOptions="${QtConfigureOptions} -no-webkit -no-qt3support -no-javascript-jit -no-dbus"
57 QtConfigureOptions="${QtConfigureOptions} -nomake examples -nomake demos -nomake docs -nomake tools"
58 for arch in ${ARCH_LIST} ; do
59 QTARCHS="${QTARCHS} -arch ${arch}"
63 QtConfigureOptions="${QtConfigureOptions} -fast -no-strip"
64 QtConfigureOptions="${QtConfigureOptions} -no-javascript-jit -no-pkg-config"
65 QtConfigureOptions="${QtConfigureOptions} -nomake examples -nomake demos -nomake docs -nomake tools"
68 QtConfigureOptions="${QtConfigureOptions} -no-strip"
69 QtConfigureOptions="${QtConfigureOptions} -no-kms -no-pkg-config"
70 QtConfigureOptions="${QtConfigureOptions} -nomake examples -nomake tools"
71 QtConfigureOptions="${QtConfigureOptions} -skip qtconnectivity -skip qtscript"
72 QtConfigureOptions="${QtConfigureOptions} -skip qtquickcontrols"
73 QtConfigureOptions="${QtConfigureOptions} -skip qttools"
74 QtConfigureOptions="${QtConfigureOptions} -skip qtdeclarative"
77 QtConfigureOptions="${QtConfigureOptions} -no-strip"
78 QtConfigureOptions="${QtConfigureOptions} -no-kms -no-pkg-config"
79 QtConfigureOptions="${QtConfigureOptions} -nomake examples -nomake tools"
80 for component in ${QtSkipComponents} ; do
81 QtConfigureOptions="${QtConfigureOptions} -skip ${component}"
85 QtConfigureOptions="${QtConfigureOptions} -fast -no-exceptions"
86 QtConfigureOptions="${QtConfigureOptions} -no-webkit -no-qt3support -no-javascript-jit -no-dbus"
87 QtConfigureOptions="${QtConfigureOptions} -nomake examples -nomake demos -nomake docs -nomake tools"
88 QtConfigureOptions="${QtConfigureOptions} ${QtAPI}"
89 for arch in ${ARCH_LIST} ; do
90 QTARCHS="${QTARCHS} -arch ${arch}"
95 aspell_dictionaries="no"
96 hunspell_dictionaries="yes"
98 libmagic_deployment="yes"
99 aspell_deployment="yes"
100 hunspell_deployment="yes"
101 thesaurus_deployment="yes"
105 # auto detect Xcode location
106 DEVELOPER_SDKS=$(dirname $(xcrun --show-sdk-path))
107 if [ -n "${DEVELOPER_SDKS}" ]; then
108 XCODE_DEVELOPER=$(dirname $(dirname $(xcrun --show-sdk-platform-path)))
109 MACOSX_DEPLOYMENT_TARGET="10.7" # Lion support is default
110 SDKROOT="${DEVELOPER_SDKS}/MacOSX$(xcrun --show-sdk-version).sdk" # use default SDK
111 elif [ -d "/Developer/SDKs" ]; then
112 DEVELOPER_SDKS="/Developer/SDKs"
113 XCODE_DEVELOPER="/Developer"
114 MACOSX_DEPLOYMENT_TARGET="10.4" # Tiger support is default
115 SDKROOT="${DEVELOPER_SDKS}/MacOSX10.5.sdk" # Leopard build is default
118 # detection of script home
119 LyxSourceDir=$(dirname "$0")
120 if [ ! -d "${LyxSourceDir}" ]; then
121 echo Missing LyX source directory.
124 case "${LyxSourceDir}" in
126 LyxSourceDir=$(dirname "${LyxSourceDir}")
130 */development|development)
131 LyxSourceDir=$(dirname "${LyxSourceDir}")
132 LyxSourceDir=$(cd "${LyxSourceDir}";pwd)
135 LyxSourceDir=$(cd "${LyxSourceDir}";pwd)
140 echo "*" Build script for LyX on Mac OS X
142 echo Optional arguments:
143 echo " --aspell-deployment=yes|no ." default yes
144 echo " --with-qt-frameworks=yes|no." default no
145 echo " --qt-deployment=yes|no ....." default yes
146 echo " --with-sdkroot=SDKROOT ....." default 10.5 "(Leopard)"
147 echo " --with-arch=ARCH ..........." default ppc,i386
148 echo " --with-build-path=PATH ....." default \${lyx-src-dir}/../lyx-build
149 echo " --with-dmg-location=PATH ..." default \${build-path}
150 echo " --with-binary-strip=yes ...." default no
151 echo " --codesign-identity=CSID ..." default is w/o CSID
153 echo "All other arguments with -- are passed to configure"
154 echo "including the defaults: ${LyXConfigureOptions}"
159 if [ -x "${LyxSourceDir}/configure" ]; then
161 echo "*" Configure options of LyX
163 "${LyxSourceDir}/configure" --help
169 NCPU=$(sysctl -n hw.ncpu)
171 if [ $NCPU -gt 1 ]; then
175 while [ $# -gt 0 ]; do
177 --with-qt-frameworks=*)
178 configure_qt_frameworks=$(echo ${1}|cut -d= -f2)
179 if [ "$configure_qt_frameworks" = "yes" ]; then
186 QTDIR=$(echo ${1}|cut -d= -f2)
189 --with-macos-deployment-target=*)
190 MACOSX_DEPLOYMENT_TARGET=$(echo ${1}|cut -d= -f2)
191 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
195 SDKROOT=$(echo ${1}|cut -d= -f2)
198 SDKROOT="${DEVELOPER_SDKS}/MacOSX10.4u.sdk"
204 SDKROOT="${DEVELOPER_SDKS}/MacOSX${SDKROOT}.sdk"
205 if [ ! -d "${SDKROOT}" ]; then
206 echo Invalid SDKROOT given: "${SDKROOT}"
213 --codesign-identity=*)
214 CODESIGN_IDENTITY=$(echo "${1}"|cut -d= -f2)
217 --libmagic-deployment=*)
218 libmagic_deployment=$(echo ${1}|cut -d= -f2)
221 --aspell-deployment=*)
222 aspell_deployment=$(echo ${1}|cut -d= -f2)
223 aspell_dictionaries=$aspell_deployment
226 --hunspell-deployment=*)
227 hunspell_deployment=$(echo ${1}|cut -d= -f2)
228 hunspell_dictionaries=$hunspell_deployment
231 --thesaurus-deployment=*)
232 thesaurus_deployment=$(echo ${1}|cut -d= -f2)
236 qt_deployment=$(echo ${1}|cut -d= -f2)
240 ARCH=$(echo ${1}|cut -d= -f2|tr ',' ' ')
241 ARCH_LIST="${ARCH_LIST} ${ARCH}"
244 --with-dmg-location=*)
245 DMGLocation=$(echo ${1}|cut -d= -f2)
248 --with-binary-strip=yes)
253 LyxBuildDir=$(echo ${1}|cut -d= -f2)
257 LyXUtilitiesDir=$(echo ${1}|cut -d= -f2)
264 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
265 aspell_deployment="no"
268 --with-included-hunspell)
269 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
270 hunspell_deployment="no"
274 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
275 hunspell_deployment="no"
276 hunspell_dictionaries="no"
280 QtOnlyPackage=$(echo ${1}|cut -d= -f2)
284 LyxOnlyPackage=$(echo ${1}|cut -d= -f2)
287 --enable-cxx11|--enable-cxx-mode=*)
288 LyXConfigureOptions="${LyXConfigureOptions} ${1}"
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.tiff
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"
377 case "${EnableCXXMode}" in
378 --enable-cxx11|--enable-cxx-mode=11)
379 echo Warning: Adjust cxx standard "${EnableCXXMode}" for Qt 6. C++17 or better is required.
380 EnableCXXMode="--enable-cxx-mode=17"
385 QtLibraries=${QtLibraries:-"QtSvg QtXml QtGui QtNetwork QtCore"}
386 QtFrameworkVersion="4"
390 DMGNAME="${LyxBase}${LyXGitCommitHash:+-}${LyXGitCommitHash}"
393 # Check for existing SDKs
394 SDKs=$(echo ${DEVELOPER_SDKS}/MacOSX1[01]*sdk)
399 MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"10.5"}; export MACOSX_DEPLOYMENT_TARGET
400 case "${MACOSX_DEPLOYMENT_TARGET}" in
402 SDKROOT="${DEVELOPER_SDKS}/MacOSX10.6.sdk"; export SDKROOT
405 SDKROOT=${SDKROOT:-"${DEVELOPER_SDKS}/MacOSX10.5.sdk"}; export SDKROOT
410 MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"10.4"}; export MACOSX_DEPLOYMENT_TARGET
411 SDKROOT=${SDKROOT:-"${DEVELOPER_SDKS}/MacOSX10.5.sdk"}; export SDKROOT
414 echo Unknown or missing SDK for Mac OS X.
418 MYCFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}"
419 MYLDFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}"
421 case "${EnableCXXMode}" in
422 --enable-cxx11|--enable-cxx-mode=11)
424 export CXX="c++ -stdlib=libc++"
425 export CXXFLAGS=-std=c++11
427 --enable-cxx-mode=17)
429 export CXX="c++ -stdlib=libc++"
430 export CXXFLAGS=-std=c++17
435 echo Build Qt library ${QtSourceDir}
436 if [ "${QtInstallDir}" = "${QtBuildDir}" ]; then
437 echo Bad install directory for Qt.
438 echo Must be different from build directory "${QtBuildDir}".
442 mkdir -p "${QtBuildDir}" && cd "${QtBuildDir}"
443 echo configure options:
444 echo ${QtConfigureOptions} ${QTARCHS} -prefix "${QtInstallDir}"
445 "${QtSourceDir}"/configure ${QtConfigureOptions} ${QTARCHS} -prefix "${QtInstallDir}"
446 make -j1 && make -j1 install
450 case ${QtOnlyPackage:-"no"} in
456 if [ "${configure_qt_frameworks}" != "yes" -a -d "${QtSourceDir}" -a ! \( -d "${QtBuildDir}" -a -d "${QtInstallDir}" \) ]; then
462 if [ -d "${LibMagicSourceDir}" -a ! -f "${LibMagicInstallHdr}" ]; then
463 # we have a private libmagic (file(1)) source tree at hand...
464 # so let's build and install it
465 if [ -z "${LibMagicVersion}" ]; then
466 LibMagicVersion=$(grep AC_INIT "${LibMagicSourceDir}"/configure.ac | cut -d, -f2|tr -d " []()")
469 LibMagicName="LibMagic"
470 LibMagicBase="${LibMagicName}-${LibMagicVersion}"
472 echo Build libmagic library ${LibMagicBase}
473 echo configure options:
474 echo --prefix="${LibMagicInstallDir}" ${LibMagicConfigureOptions}
476 mkdir -p "${LibMagicBuildDir}" && cd "${LibMagicBuildDir}"
478 # ----------------------------------------
479 # Build LibMagic for different architectures
480 # ----------------------------------------
481 FILE_LIST="${LibMagicLibrary}"
483 for arch in ${ARCH_LIST} ; do
484 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"; export CPPFLAGS
485 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYLDFLAGS}"; export LDFLAGS
486 "${LibMagicSourceDir}/configure"\
487 --prefix="${LibMagicInstallDir}"\
488 ${LibMagicConfigureOptions}
489 make && make install${strip}
490 for file in ${FILE_LIST} ; do
491 if [ -f "${LibMagicInstallDir}"/lib/${file} ]; then
492 mv "${LibMagicInstallDir}"/lib/${file}\
493 "${LibMagicInstallDir}"/lib/${file}-${arch}
495 echo Cannot build and install LibMagic for ${arch}.
500 # -------------------------
501 # Create universal binaries
502 # -------------------------
503 for file in ${FILE_LIST} ; do
505 for arch in ${ARCH_LIST} ; do
506 OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
509 cd "${LibMagicInstallDir}"
510 lipo -create ${OBJ_LIST} -o lib/${file}
511 # check for the "missing link"...
512 test -f lib/libmagic.dylib || (cd lib ; ln -s "${LibMagicLibrary}" libmagic.dylib)
518 for arch in ${ARCH_LIST} ; do
519 rm -f "${LibMagicInstallDir}"/lib/*-${arch}
523 if [ -d "${HunSpellSourceDir}" -a ! -f "${HunSpellInstallHdr}" ]; then
524 # we have a private HunSpell source tree at hand...
525 # so let's build and install it
526 if [ -z "${HunSpellVersion}" ]; then
527 HunSpellVersion=$(grep AC_INIT "${HunSpellSourceDir}"/configure.ac | cut -d, -f2|tr -d " []()")
530 HunSpellName="Hunspell"
531 HunSpellBase="${HunSpellName}-${HunSpellVersion}"
533 echo Build hunspell library ${HunSpellBase}
534 echo configure options:
535 echo --prefix="${HunSpellInstallDir}" ${HunspellConfigureOptions}
537 mkdir -p "${HunSpellBuildDir}" && cd "${HunSpellBuildDir}"
539 # ----------------------------------------
540 # Build HunSpell for different architectures
541 # ----------------------------------------
542 FILE_LIST="${HunSpellLibrary}"
544 for arch in ${ARCH_LIST} ; do
546 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"; export CPPFLAGS
547 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYLDFLAGS}"; export LDFLAGS
548 "${HunSpellSourceDir}/configure"\
549 --prefix="${HunSpellInstallDir}"\
550 ${HunspellConfigureOptions}
551 make && make install${strip}
552 for file in ${FILE_LIST} ; do
553 if [ -f "${HunSpellInstallDir}"/lib/${file} ]; then
554 mv "${HunSpellInstallDir}"/lib/${file}\
555 "${HunSpellInstallDir}"/lib/${file}-${arch}
557 echo Cannot build and install HunSpell for ${arch}.
562 # -------------------------
563 # Create universal binaries
564 # -------------------------
565 for file in ${FILE_LIST} ; do
567 for arch in ${ARCH_LIST} ; do
568 OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
571 cd "${HunSpellInstallDir}"
572 lipo -create ${OBJ_LIST} -o lib/${file}
573 # check for the "missing link"...
574 test -f lib/libhunspell.dylib || (cd lib ; ln -s "${HunSpellLibrary}" libhunspell.dylib)
580 for arch in ${ARCH_LIST} ; do
581 rm -f "${HunSpellInstallDir}"/lib/*-${arch}
585 if [ -d "${ASpellSourceDir}" -a ! -f "${ASpellInstallHdr}" -a "yes" = "${aspell_deployment}" ]; then
586 # we have a private ASpell source tree at hand...
587 # so let's build and install it
588 if [ -z "${ASpellVersion}" ]; then
589 ASpellVersion=$(grep AC_INIT "${ASpellSourceDir}"/configure.ac | cut -d, -f2|tr -d " []()")
593 ASpellBase="${ASpellName}-${ASpellVersion}"
595 echo Build aspell library ${ASpellBase}
596 echo configure options:
597 echo --prefix="${ASpellInstallDir}" ${AspellConfigureOptions}
599 # ASpell builds inplace only :(
600 cd "${ASpellSourceDir}"
602 # ----------------------------------------
603 # Build ASpell for different architectures
604 # ----------------------------------------
605 FILE_LIST="${ASpellLibrary}"
607 for arch in ${ARCH_LIST} ; do
609 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"; export CPPFLAGS
610 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYLDFLAGS}"; export LDFLAGS
611 CXXFLAGS=-g "${ASpellSourceDir}/configure"\
612 --prefix="${ASpellInstallDir}"\
613 ${AspellConfigureOptions}
614 make && make install${aspellstrip}
615 for file in ${FILE_LIST} ; do
616 if [ -f "${ASpellInstallDir}"/lib/${file} ]; then
617 mv "${ASpellInstallDir}"/lib/${file}\
618 "${ASpellInstallDir}"/lib/${file}-${arch}
620 echo Cannot build and install ASpell for ${arch}.
625 # -------------------------
626 # Create universal binaries
627 # -------------------------
628 for file in ${FILE_LIST} ; do
630 for arch in ${ARCH_LIST} ; do
631 OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
634 cd "${ASpellInstallDir}"
635 lipo -create ${OBJ_LIST} -o lib/${file}
641 for arch in ${ARCH_LIST} ; do
642 rm -f "${ASpellInstallDir}"/lib/*-${arch}
648 echo "Frameworks/${1}.framework"
651 LYX_FILE_LIST="lyx lyxclient tex2lyx lyxconvert"
652 BUNDLE_PATH="Contents/MacOS"
653 LYX_BUNDLE_PATH="${LyxAppPrefix}/${BUNDLE_PATH}"
657 if [ -n "${LyxAppZip}" -a -f "${LyxAppZip}" ]; then rm "${LyxAppZip}"; fi
658 if [ -d "${LyxAppPrefix}" ]; then
659 find "${LyxAppPrefix}" -type d -exec chmod u+w '{}' \;
660 rm -rf "${LyxAppPrefix}"
663 # -------------------------------------
664 # Automate configure check
665 # -------------------------------------
666 if [ ! -f "${LyxSourceDir}"/configure -o "${LyxSourceDir}"/configure -ot "${LyxSourceDir}"/configure.ac ]; then
667 ( cd "${LyxSourceDir}" && sh autogen.sh )
669 find "${LyxSourceDir}" -name Makefile.am -print | while read file ; do
670 dname=$(dirname "$file")
671 if [ -f "$dname/Makefile.in" -a "$dname/Makefile.in" -ot "$file" ]; then
672 ( cd "${LyxSourceDir}" && sh autogen.sh )
677 # -------------------------------------
678 # Build LyX for different architectures
679 # -------------------------------------
681 if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_deployment}" ]; then
682 ConfigureExtraInc="--with-extra-inc=${ASpellInstallDir}/include"
683 ConfigureExtraLib="--with-extra-lib=${ASpellInstallDir}/lib"
686 if [ -d "${HunSpellInstallDir}" -a "yes" = "${hunspell_deployment}" ]; then
687 HunSpellFramework=$(framework_name Hunspell)
688 HunSpellFramework=$(basename "${HunSpellFramework}")
689 ConfigureExtraInc="--with-extra-inc=${HunSpellInstallDir}/include"
690 ConfigureExtraLib="--with-extra-lib=${HunSpellInstallDir}/lib"
691 # LyXConfigureOptions="${LyXConfigureOptions} --with-hunspell-framework=${HunSpellFramework}"
693 LyXConfigureOptions="${LyXConfigureOptions} ${ConfigureExtraInc}"
694 LyXConfigureOptions="${LyXConfigureOptions} ${ConfigureExtraLib}"
696 for arch in ${ARCH_LIST} ; do
698 if [ -d "${LyxBuildDir}" ]; then rm -r "${LyxBuildDir}"; fi
699 mkdir -p "${LyxBuildDir}" && cd "${LyxBuildDir}"
701 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch}"
702 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch}"
704 if [ "$configure_qt_frameworks" = "yes" ]; then
705 export QT_CORE_CFLAGS="-FQtCore"
706 export QT_CORE_LIBS="-framework QtCore"
707 export QT_FRONTEND_CFLAGS="-FQtGui"
708 export QT_FRONTEND_LIBS="-framework QtGui"
709 CPPFLAGS="${CPPFLAGS} -I${SDKROOT}/Library/Frameworks/QtCore.framework/Headers"
710 CPPFLAGS="${CPPFLAGS} -I${SDKROOT}/Library/Frameworks/QtGui.framework/Headers"
713 echo LDFLAGS="${LDFLAGS}"
715 echo CPPFLAGS="${CPPFLAGS}"
717 echo CONFIGURE_OPTIONS="${LyXConfigureOptions}" ${QtInstallDir:+"--with-qt-dir=${QtInstallDir}"}
718 "${LyxSourceDir}/configure"\
719 --prefix="${LyxAppPrefix}" --with-version-suffix="-${LyXVersionSuffix}"\
720 ${QtInstallDir:+"--with-qt-dir=${QtInstallDir}"} \
721 ${LyXConfigureOptions}\
722 --enable-build-type=rel && \
723 make ${MAKEJOBS} && make install${strip}
724 for file in ${LYX_FILE_LIST} ; do
725 if [ -f "${LYX_BUNDLE_PATH}/${file}" ]; then
726 mv "${LYX_BUNDLE_PATH}/${file}"\
727 "${LYX_BUNDLE_PATH}/${file}-${arch}"
729 echo ERROR: Cannot build and install ${file} for ${arch}.
736 content_directory() {
738 content=$(dirname "${target}")
739 content=$(dirname "${content}")
744 echo install_name_tool "$@"
745 install_name_tool "$@" || exit 1
748 private_framework() {
752 version=$(echo ${1:-"1.1.1"}.1.1.1 | cut -d. -f1-3) ; shift
753 fwdir=$(framework_name "${fwname}")
754 condir=$(content_directory "${target}")
755 libnm=$(basename "${source}")
756 libid="org.lyx."$(echo "${libnm}" | cut -d. -f1)
757 svrsn=$(echo "${version}" | cut -d. -f1-2)
759 mkdir -p "${condir}/${fwdir}"/Versions/${fwvrsn}/Headers
760 mkdir -p "${condir}/${fwdir}"/Versions/${fwvrsn}/Resources
761 if [ ! -f "${condir}/${fwdir}/Versions/${fwvrsn}/${fwname}" ]; then
762 cp -p "${source}" "${condir}/${fwdir}/Versions/${fwvrsn}/${fwname}"
763 for hfile in "$@" ; do
764 test -f "${hfile}" && cp -p "${hfile}" "${condir}/${fwdir}"/Versions/${fwvrsn}/Headers
766 ln -s ${fwvrsn} "${condir}/${fwdir}/Versions/Current"
767 ln -s Versions/Current/Headers "${condir}/${fwdir}/Headers"
768 ln -s Versions/Current/Resources "${condir}/${fwdir}/Resources"
769 ln -s Versions/Current/"${fwname}" "${condir}/${fwdir}/${fwname}"
770 installname -id "@executable_path/../${fwdir}/${fwname}" "${condir}/${fwdir}/${fwname}"
771 if [ -f "${LyxSourceDir}"/development/LyX-Mac-frameworks-template.plist ]; then
772 cat "${LyxSourceDir}"/development/LyX-Mac-frameworks-template.plist | sed \
773 -e "s/@CFBundleExecutable@/${fwname}/" \
774 -e "s/@CFBundleIdentifier@/${libid}/" \
775 -e "s/@CFBundleShortVersionString@/${svrsn}/" \
776 -e "s/@CFBundleVersion@/${version}/" > "${condir}/${fwdir}"/Resources/Info.plist
779 installname -change "${source}" "@executable_path/../${fwdir}/${fwname}" "${target}"
783 source="${QtInstallDir}"
785 version="Versions/${QtFrameworkVersion}/"
786 condir=$(content_directory "${target}")
787 mkdir -p "${condir}/Resources"
788 test -f "${condir}/Resources/qt.conf" || cat - > "${condir}/Resources/qt.conf" <<-EOF
791 Translations = translations
793 if [ ! -d "${condir}/PlugIns" ]; then
794 mkdir -p "${condir}/PlugIns"
795 find "${source}/plugins" -name \*.dylib -print | grep -v _debug.dylib | while read libname ; do
796 echo Copy plugin "${libname}"
797 dylib=$(basename "${libname}")
798 dirname=$(dirname "${libname}")
799 dirname=$(basename "${dirname}")
800 mkdir -p "${condir}/PlugIns/${dirname}"
801 cp -p "${libname}" "${condir}/PlugIns/${dirname}"
804 for libnm in ${QtLibraries} ; do
805 fwdir=$(framework_name "$libnm")
806 dirname=$(dirname "${fwdir}")
807 mkdir -p "${condir}/${dirname}"
808 dirname=$(basename "${fwdir}")
809 test -d "${condir}/${fwdir}" || (
810 echo Copy framework "${source}/lib/"$(basename "${fwdir}")
811 cp -pR "${source}/lib/"$(basename "${fwdir}") "${condir}/${fwdir}"
812 rm -f "${condir}/${fwdir}/${libnm}"_debug "${condir}/${fwdir}/${version}${libnm}"_debug
813 test -f "${condir}/${fwdir}/${libnm}".prl && mv "${condir}/${fwdir}/${libnm}".prl "${condir}/${fwdir}"/Resources
814 test -f "${condir}/${fwdir}/${libnm}"_debug.prl && mv "${condir}/${fwdir}/${libnm}"_debug.prl "${condir}/${fwdir}"/Resources
815 installname -id "@executable_path/../${fwdir}/${version}${libnm}" "${condir}/${fwdir}/${version}${libnm}"
816 find "${condir}/PlugIns" "${condir}/"$(dirname "${fwdir}") -name Headers -prune -o -type f -print | while read filename ; do
817 if [ "${filename}" != "${target}" ]; then
818 otool -L "${filename}" 2>/dev/null | sort -u | while read library ; do
819 # pattern match for: /path/to/qt/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.6.0, current version 4.6.2)
821 *@rpath/*"${libnm}"*"("*version*")"*)
822 # echo rpath based name for ${libnm} is ok.
824 *"${libnm}"*"("*version*")"*)
826 "${source}/lib/${dirname}/${version}${libnm}"\
827 "@executable_path/../${fwdir}/${version}${libnm}"\
836 "${source}/lib/${dirname}/${version}${libnm}"\
837 "@executable_path/../${fwdir}/${version}${libnm}"\
840 if [ -d "${source}"/translations ]; then
841 if [ ! -d "${condir}/translations" ]; then
842 mkdir -p "${condir}/translations"
844 echo Copy Qt translations to "${condir}/translations"
845 cp -p "${source}"/translations/qt_*.qm "${condir}/translations"
849 # -------------------------
850 # Create universal binaries
851 # -------------------------
852 convert_universal() {
854 for file in ${LYX_FILE_LIST} ; do
856 for arch in ${ARCH_LIST} ; do
857 if [ -f "${BUNDLE_PATH}/${file}-${arch}" ]; then
858 OBJ_LIST="${OBJ_LIST} ${BUNDLE_PATH}/${file}-${arch}"
861 if [ -n "${OBJ_LIST}" ]; then
862 lipo -create ${OBJ_LIST} -o "${BUNDLE_PATH}/${file}"
864 if [ -f "${LibMagicInstallDir}/lib/${LibMagicLibrary}" -a "yes" = "${libmagic_deployment}" ]; then
865 private_framework LibMagic "${LibMagicInstallDir}/lib/${LibMagicLibrary}" "${LYX_BUNDLE_PATH}/${file}" \
866 "${LibMagicVersion}" "${LibMagicInstallHdr}"
868 if [ -f "${ASpellInstallDir}/lib/${ASpellLibrary}" -a "yes" = "${aspell_deployment}" ]; then
869 private_framework Aspell "${ASpellInstallDir}/lib/${ASpellLibrary}" "${LYX_BUNDLE_PATH}/${file}" \
870 "${ASpellVersion}" "${ASpellInstallHdr}"
872 if [ -f "${HunSpellInstallDir}/lib/${HunSpellLibrary}" -a "yes" = "${hunspell_deployment}" ]; then
873 private_framework Hunspell "${HunSpellInstallDir}/lib/${HunSpellLibrary}" "${LYX_BUNDLE_PATH}/${file}" \
874 "${HunSpellVersion}" "${HunSpellInstallDir}/include/hunspell/"*.hxx "${HunSpellInstallHdr}"
876 if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt_deployment}" ]; then
877 deploy_qtlibs "${LYX_BUNDLE_PATH}/${file}"
879 otool -L "${BUNDLE_PATH}/${file}" | while read reference ; do
880 case "${reference}" in
881 *"${LyxBuildDir}"*"("*")")
882 echo ERROR: Bad reference to "${reference}" found!!
887 for arch in ${ARCH_LIST} ; do
888 rm -f "${BUNDLE_PATH}"/*-${arch}
892 # -------------------------
893 # Create code sign signatures
894 # -------------------------
897 condir=$(content_directory "${target}"/lyx)
898 appdir=$(dirname "${condir}")
899 # have to sign frameworks first
900 for fwname in Aspell Hunspell LibMagic ; do
901 fwitem="${condir}"/$(framework_name "${fwname}")
902 if [ -d "${fwitem}" ]; then
903 codesign --verbose --force --sign "${CODESIGN_IDENTITY}" "${fwitem}"
907 "${condir}"/Frameworks/Qt*.framework/Versions/${QtFrameworkVersion} \
908 "${condir}"/PlugIns/*/lib*.dylib \
909 "${condir}"/Library/Spotlight/* \
910 "${target}"/inkscape \
911 "${target}"/lilypond \
912 "${target}"/lilypond-book \
914 "${target}"/tex2lyx \
915 "${target}"/lyxeditor \
916 "${target}"/lyxconvert \
917 "${target}"/lyxclient
919 codesign --verbose --force --sign "${CODESIGN_IDENTITY}" "${csitem}"
922 /usr/bin/codesign --verbose --force --sign "${CODESIGN_IDENTITY}" "${appdir}" || {
923 echo Warning: codesign failed with certificate named '"'${CODESIGN_IDENTITY}'"'
928 find "$@" -type f -print | while read file ; do
929 echo $(md5 -q "$file") "$file"
930 done | sort | while read hash file ; do
931 ppath=$(dirname "$pfile")
932 path=$(dirname "$file")
933 if [ "$phash" = "$hash" -a "$ppath" = "$path" ]; then
934 pname=$(basename "$pfile")
935 name=$(basename "$file")
936 cmp -s "$pfile" "$file" && (
938 cd "$path" && ln -s "$pname" "$name" && echo link for "$file" created
946 copy_dictionaries() {
947 if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_dictionaries}" ]; then
948 ASpellResources="${LyxAppPrefix}/Contents/Resources"
949 # try to reuse macports dictionaries for now
950 if [ -d /opt/local/lib/aspell-0.60 ]; then ASpellInstallDir=/opt/local ; fi
951 mkdir -p "${ASpellResources}"
952 echo Copy Aspell dictionaries from "${ASpellInstallDir}"
953 mkdir -p "${ASpellResources}"/data "${ASpellResources}"/dicts
954 cp -p -r "${ASpellInstallDir}/lib/aspell-0.60"/* "${ASpellResources}"/data
955 cp -p -r "${ASpellInstallDir}/share/aspell"/* "${ASpellResources}"/dicts
957 if [ -d "${DictionarySourceDir}" -a "yes" = "${hunspell_dictionaries}" ]; then
958 HunSpellResources="${LyxAppPrefix}/Contents/Resources"
959 ( cd "${DictionarySourceDir}" && find dicts -name .svn -prune -o -type f -print | cpio -pmdv "${HunSpellResources}" )
960 deduplicate "${HunSpellResources}"/dicts
962 if [ -d "${DictionarySourceDir}" -a "yes" = "${thesaurus_deployment}" ]; then
963 MyThesResources="${LyxAppPrefix}/Contents/Resources"
964 ( cd "${DictionarySourceDir}" && find thes -name .svn -prune -o -type f -print | cpio -pmdv "${MyThesResources}" )
965 deduplicate "${MyThesResources}"/thes
969 set_bundle_display_options() {
972 Y_POSITION=$((Y_BOUNDS - 65))
973 Y_BOUNDS=$((Y_BOUNDS + 50))
974 LYX_X_POSITION=$((X_BOUNDS / 4))
975 LYX_Y_POSITION=$Y_POSITION
976 APP_X_POSITION=$((3 * X_BOUNDS / 4))
977 APP_Y_POSITION=$Y_POSITION
978 WITH_DOCUMENTS=$(test -d "${1}/Documents" && echo true || echo false)
980 tell application "Finder"
981 set f to POSIX file ("${1}" as string) as alias
984 tell container window
985 set toolbar visible to false
986 set statusbar visible to false
987 set current view to icon view
989 set the bounds to {20, 50, $X_BOUNDS, $Y_BOUNDS}
992 set icon size of the icon view options of container window to 64
993 set arrangement of the icon view options of container window to not arranged
994 if ${WITH_DOCUMENTS} then
995 set position of item "Documents" to {$LYX_X_POSITION,0}
997 set position of item "${LyxName}.app" to {$LYX_X_POSITION,$LYX_Y_POSITION}
998 set position of item "Applications" to {$APP_X_POSITION,$APP_Y_POSITION}
999 set background picture of the icon view options\
1000 of container window to file "background.png" of folder "Pictures"
1001 set the bounds of the container window to {0, 0, $X_BOUNDS, $Y_BOUNDS}
1002 update without registering applications
1011 # The image was made with with inkscape and tiffutil from dmg-background.svgz
1013 INKSCAPE=/Applications/Inkscape.app/Contents/MacOS/inkscape
1014 cd "${LyxSourceDir}"/development/MacOSX
1015 ${INKSCAPE} --export-type=png -w 560 -o dmg-background.png dmg-background.svgz
1016 ${INKSCAPE} --export-type=png -w 1120 -o dmg-background@2x.png dmg-background.svgz
1017 tiffutil -cathidpicheck dmg-background.png dmg-background@2x.png -out dmg-background.tiff
1023 BGSIZE=$(file "$DmgBackground" | awk -F , '/TIFF/{ print $10 $4 ;}/PNG/{ print $2; }'|sed -e 's/width=//' -e 's/height=//' -e 's/x//')
1024 BG_W=$(echo ${BGSIZE} | awk '{print $1 }')
1025 BG_H=$(echo ${BGSIZE} | awk '{print $2 }')
1027 rm -f "${DMGNAME}.sparseimage" "${DMGNAME}.dmg"
1029 hdiutil create -type SPARSE -size ${DMGSIZE:-"250m"} -fs HFS+ -volname "${LyxBase}" "${DMGNAME}"
1030 # Unmount currently mounted disk image
1031 mount | grep "${LyxBase}" && umount /Volumes/"${LyxBase}"
1032 test -d /Volumes/"${LyxBase}" && rmdir /Volumes/"${LyxBase}"
1034 # Mount the disk image
1035 DEVICES=$(hdiutil attach "${DMGNAME}.sparseimage" | cut -f 1)
1037 # Obtain device information
1038 DEVICE=$(echo $DEVICES | cut -f 1 -d ' ')
1039 VOLUME=$(mount |grep ${DEVICE} | cut -f 3 -d ' ')
1041 # copy in the application bundle
1042 ditto --hfsCompression "${LyxAppPrefix}" "${VOLUME}/${LyxName}.app"
1044 # copy in background image
1045 mkdir -p "${VOLUME}/Pictures"
1046 ditto --hfsCompression "${DmgBackground}" "${VOLUME}/Pictures/background.png"
1047 # symlink applications
1048 ln -s /Applications/ "${VOLUME}"/Applications
1049 test -d "${DocumentationDir}" && ditto --hfsCompression "${DocumentationDir}" "${VOLUME}"
1050 set_bundle_display_options "${VOLUME}" ${BG_W} ${BG_H}
1051 PATH="${XCODE_DEVELOPER}/Tools:$PATH" SetFile -a C "${VOLUME}"
1052 mv "${VOLUME}/Pictures" "${VOLUME}/.Pictures"
1054 # Unmount the disk image
1055 hdiutil detach ${DEVICE}
1057 # Convert the disk image to read-only
1058 hdiutil convert "${DMGNAME}.sparseimage" -format UDBZ -o "${DMGNAME}.dmg"
1059 rm -f "${DMGNAME}.sparseimage"
1062 # ------------------------------
1063 # Building distribution packages
1064 # ------------------------------
1067 test -n "${LyxAppZip}" && (
1068 cd "${LyxAppPrefix}" && zip -r "${LyxAppZip}" .
1072 for arch in ${ARCH_LIST} ; do
1073 DMGARCH="${DMGARCH}-${arch}"
1075 QtDmgArchSuffix="qt"${QtMajorVersion}${DMGARCH}${QtAPI}.dmg
1077 test -n "${DMGLocation}" && (
1078 make_dmg "${DMGLocation}"
1079 if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt_deployment}" ]; then
1080 rm -f "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1081 echo move to "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1082 mv "${DMGLocation}/${DMGNAME}.dmg" "${DMGLocation}/${DMGNAME}+${QtDmgArchSuffix}"
1087 # ------------------------------
1089 # ------------------------------
1091 if [ ${LyxOnlyPackage:-"no"} = "no" ]; then
1095 test -n "${CODESIGN_IDENTITY}" && code_sign "${LYX_BUNDLE_PATH}"
1096 find "${LyxAppPrefix}" -type d -exec chmod go-w '{}' \;