PageRenderTime 55ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/lyx-2.0.4/development/LyX-Mac-binary-release.sh

#
Shell | 755 lines | 602 code | 71 blank | 82 comment | 89 complexity | 2df16bfe90e6e99e0a29b3fc85aeeb50 MD5 | raw file
Possible License(s): LGPL-2.0, GPL-2.0
  1. #!/bin/sh
  2. # set -x
  3. # This script automates creating universal binaries of LyX on Mac.
  4. # Author: Bennett Helm (and extended by Konrad Hofbauer)
  5. # latest changes by Stephan Witt
  6. # Last modified: January 2011
  7. CARBON=-carbon
  8. Qt4Version="4.6.3"
  9. Qt4SourceVersion="qt-everywhere-opensource-src-${Qt4Version}"
  10. Qt4BuildSubDir="qt-${Qt4Version}-build${CARBON}"
  11. # Prerequisite:
  12. # * a decent checkout of LyX sources (probably you have it already)
  13. # * Qt4 - build with shared or static libraries for the used platforms (default: i386 and ppc)
  14. # or - an unpacked source tree of Qt4 in $QT4SOURCEDIR or in the sibling directory (variable Qt4SourceVersion)
  15. # * for aspell support:
  16. # the aspell sources placed in a sibling directory (variable ASpellSourceVersion)
  17. # * for hunspell support:
  18. # the hunspell sources placed in a sibling directory (variable HunSpellSourceVersion)
  19. # * for dictionary deployment (per default thesauri only):
  20. # - aspell: the dictionary files of macports (in /opt/local/share/aspell and /opt/local/lib/aspell-0.60)
  21. # - hunspell: the dictionary files in the sibling directory dictionaries/dicts
  22. # - mythes: the data and idx files in the sibling directory dictionaries/thes
  23. LyXConfigureOptions="--enable-warnings --enable-optimization=-Os --with-included-gettext --with-x=no"
  24. AspellConfigureOptions="--enable-warnings --enable-optimization=-O0 --enable-debug --disable-nls --enable-compile-in-filters --disable-pspell-compatibility"
  25. HunspellConfigureOptions="--with-warnings --disable-nls --with-included-gettext --disable-static"
  26. Qt4ConfigureOptions="-opensource -silent -shared -release -fast -no-exceptions"
  27. Qt4ConfigureOptions="${Qt4ConfigureOptions} -no-webkit -no-qt3support -no-javascript-jit -no-dbus"
  28. Qt4ConfigureOptions="${Qt4ConfigureOptions} -nomake examples -nomake demos -nomake docs -nomake tools"
  29. #Qt4ConfigureOptions="${Qt4ConfigureOptions} ${CARBON}"
  30. aspell_dictionaries="no"
  31. hunspell_dictionaries="yes"
  32. aspell_deployment="yes"
  33. hunspell_deployment="yes"
  34. thesaurus_deployment="yes"
  35. qt4_deployment="yes"
  36. MACOSX_DEPLOYMENT_TARGET="10.4" # Tiger support is default
  37. SDKROOT="/Developer/SDKs/MacOSX10.5.sdk" # Leopard build is default
  38. usage() {
  39. echo Build script for LyX on Mac OS X
  40. echo
  41. echo Optional arguments:
  42. echo " --aspell-deployment=yes|no ." default yes
  43. echo " --with-qt4-frameworks=yes|no" default no
  44. echo " --qt4-deployment=yes|no ...." default yes
  45. echo " --with-macosx-target=TARGET " default 10.4 "(Tiger)"
  46. echo " --with-sdkroot=SDKROOT ....." default 10.5 "(Leopard)"
  47. echo " --with-arch=ARCH ..........." default ppc,i386
  48. echo " --with-build-path=PATH ....." default \${lyx-src-dir}/../lyx-build
  49. echo " --with-dmg-location=PATH ..." default \${build-path}
  50. echo
  51. echo "All other arguments with -- are passed to configure"
  52. echo "including the defaults: ${LyXConfigureOptions}"
  53. echo
  54. exit 0
  55. }
  56. while [ $# -gt 0 ]; do
  57. case "${1}" in
  58. --with-qt4-frameworks=*)
  59. configure_qt4_frameworks=`echo ${1}|cut -d= -f2`
  60. if [ "$configure_qt4_frameworks" = "yes" ]; then
  61. unset QTDIR
  62. qt4_deployment="no"
  63. fi
  64. shift
  65. ;;
  66. --with-qt4-dir=*)
  67. QTDIR=`echo ${1}|cut -d= -f2`
  68. shift
  69. ;;
  70. --with-macosx-target=*)
  71. MACOSX_DEPLOYMENT_TARGET=`echo ${1}|cut -d= -f2`
  72. shift
  73. ;;
  74. --with-sdkroot=*)
  75. SDKROOT=`echo ${1}|cut -d= -f2`
  76. case "${SDKROOT}" in
  77. 10.4)
  78. SDKROOT="/Developer/SDKs/MacOSX10.4u.sdk"
  79. export CC=gcc-4.0
  80. export OBJC=gcc-4.0
  81. export CXX=g++-4.0
  82. ;;
  83. 10.5|10.6)
  84. SDKROOT="/Developer/SDKs/MacOSX${SDKROOT}.sdk"
  85. ;;
  86. *)
  87. usage
  88. ;;
  89. esac
  90. shift
  91. ;;
  92. --aspell-deployment=*)
  93. aspell_deployment=`echo ${1}|cut -d= -f2`
  94. aspell_dictionaries=$aspell_deployment
  95. shift
  96. ;;
  97. --hunspell-deployment=*)
  98. hunspell_deployment=`echo ${1}|cut -d= -f2`
  99. hunspell_dictionaries=$hunspell_deployment
  100. shift
  101. ;;
  102. --thesaurus-deployment=*)
  103. thesaurus_deployment=`echo ${1}|cut -d= -f2`
  104. shift
  105. ;;
  106. --qt4-deployment=*)
  107. qt4_deployment=`echo ${1}|cut -d= -f2`
  108. shift
  109. ;;
  110. --with-arch=*)
  111. ARCH=`echo ${1}|cut -d= -f2|tr ',' ' '`
  112. ARCH_LIST="${ARCH_LIST} ${ARCH}"
  113. shift
  114. ;;
  115. --with-dmg-location=*)
  116. DMGLocation=`echo ${1}|cut -d= -f2`
  117. shift
  118. ;;
  119. --with-build-path=*)
  120. LyxBuildDir=`echo ${1}|cut -d= -f2`
  121. shift
  122. ;;
  123. --help)
  124. usage
  125. ;;
  126. --without-aspell)
  127. LyXConfigureOptions="${LyXConfigureOptions} ${1}"
  128. aspell_deployment="no"
  129. shift
  130. ;;
  131. --without-hunspell)
  132. LyXConfigureOptions="${LyXConfigureOptions} ${1}"
  133. hunspell_deployment="no"
  134. shift
  135. ;;
  136. --*)
  137. LyXConfigureOptions="${LyXConfigureOptions} ${1}"
  138. shift
  139. ;;
  140. *)
  141. break
  142. ;;
  143. esac
  144. done
  145. if [ "${configure_qt4_frameworks}" != "yes" ]; then
  146. QtInstallDir=${QTDIR:-"/opt/qt4"}
  147. fi
  148. QtFrameworkVersion="4"
  149. ASpellSourceVersion="aspell-0.60.6"
  150. HunSpellSourceVersion="hunspell-1.2.12"
  151. ARCH_LIST=${ARCH_LIST:-"ppc i386"}
  152. strip="-strip"
  153. aspellstrip=
  154. # detection of script home
  155. LyxSourceDir=${1:-`dirname "$0"`}
  156. if [ ! -d "${LyxSourceDir}" ]; then
  157. echo Missing LyX source directory.
  158. exit 2
  159. fi
  160. case "${LyxSourceDir}" in
  161. /*/development)
  162. LyxSourceDir=`dirname "${LyxSourceDir}"`
  163. ;;
  164. /*)
  165. ;;
  166. */development|development)
  167. LyxSourceDir=`dirname "${LyxSourceDir}"`
  168. LyxSourceDir=`cd "${LyxSourceDir}";pwd`
  169. ;;
  170. *)
  171. LyxSourceDir=`cd "${LyxSourceDir}";pwd`
  172. ;;
  173. esac
  174. LyxBuildDir=${LyxBuildDir:-`dirname "${LyxSourceDir}"`/lyx-build}
  175. DMGLocation=${DMGLocation:-"${LyxBuildDir}"}
  176. ASpellSourceDir=${ASPELLDIR:-`dirname "${LyxSourceDir}"`/${ASpellSourceVersion}}
  177. ASpellInstallDir=${ASpellInstallDir:-"${LyxBuildDir}"/SpellChecker.lib}
  178. HunSpellSourceDir=${HUNSPELLDIR:-`dirname "${LyxSourceDir}"`/${HunSpellSourceVersion}}
  179. HunSpellInstallDir=${HunSpellInstallDir:-"${LyxBuildDir}"/SpellChecker.lib}
  180. Qt4SourceDir=${QT4SOURCEDIR:-`dirname "${LyxSourceDir}"`/${Qt4SourceVersion}}
  181. Qt4BuildDir=${Qt4BuildDir:-"${LyxBuildDir}"/${Qt4BuildSubDir:-"qt4-build"}}
  182. DictionarySourceDir=${DICTIONARYDIR:-`dirname "${LyxSourceDir}"`/dictionaries}
  183. DmgBackground="${LyxSourceDir}"/development/MacOSX/dmg-background.png
  184. ASpellInstallHdr="${ASpellInstallDir}/include/aspell.h"
  185. HunSpellInstallHdr="${HunSpellInstallDir}/include/hunspell/hunspell.h"
  186. if [ -z "${LyXVersion}" ]; then
  187. LyXVersion=`grep AC_INIT "${LyxSourceDir}"/configure.ac | cut -d, -f2 | tr -d " ()"`
  188. fi
  189. LyXVersionSuffix=${LyXVersionSuffix:-`echo "${LyXVersion}" | cut -d. -f1-2`}
  190. LyxName="LyX"
  191. LyxBase="${LyxName}-${LyXVersion}"
  192. LyxApp="${LyxBase}.app"
  193. LyxAppDir="${LyxBuildDir}"/"${LyxBase}"
  194. LyxBuildDir="${LyxAppDir}.build"
  195. LyxAppPrefix="${LyxAppDir}.app"
  196. # if zip file is needed... remove the comment sign
  197. #LyxAppZip="${LyxAppPrefix}.zip"
  198. # ---------------------------------
  199. # DON'T MODIFY ANYTHING BELOW HERE!
  200. # ---------------------------------
  201. # don't change order here...
  202. QtLibraries="QtSvg QtXml QtGui QtNetwork QtCore"
  203. DMGNAME="${LyxBase}"
  204. DMGSIZE="550m"
  205. # Check for existing SDKs
  206. SDKs=`echo /Developer/SDKs/MacOSX10*sdk`
  207. case "$SDKs" in
  208. ${SDKROOT})
  209. ;;
  210. *10.6*)
  211. MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"10.5"}; export MACOSX_DEPLOYMENT_TARGET
  212. case "${MACOSX_DEPLOYMENT_TARGET}" in
  213. 10.6)
  214. SDKROOT="/Developer/SDKs/MacOSX10.6.sdk"; export SDKROOT
  215. ;;
  216. 10.5|10.4)
  217. SDKROOT=${SDKROOT:-"/Developer/SDKs/MacOSX10.5.sdk"}; export SDKROOT
  218. ;;
  219. esac
  220. ;;
  221. *10.5*)
  222. MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-"10.4"}; export MACOSX_DEPLOYMENT_TARGET
  223. SDKROOT=${SDKROOT:-"/Developer/SDKs/MacOSX10.5.sdk"}; export SDKROOT
  224. ;;
  225. *)
  226. echo Unknown or missing SDK for Mac OS X.
  227. exit 1
  228. ;;
  229. esac
  230. MYCFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}"
  231. # These variables define the identifiers of the
  232. # system (both Intel and PowerPC) to compile for.
  233. # (Note: darwin8 is 10.4; darwin9 is 10.5.)
  234. # Only change these if necessary
  235. HostSystem_i386="i686-apple-darwin8"
  236. HostSystem_ppc="powerpc-apple-darwin8"
  237. if [ "${configure_qt4_frameworks}" != "yes" -a -d "${Qt4SourceDir}" -a ! \( -d "${Qt4BuildDir}" -a -d "${QtInstallDir}" \) ]; then
  238. echo Build Qt4 library ${Qt4SourceDir}
  239. if [ "${QtInstallDir}" = "${Qt4BuildDir}" ]; then
  240. echo Bad install directory for Qt.
  241. echo Must be different from build directory "${Qt4BuildDir}".
  242. exit 1
  243. fi
  244. (
  245. mkdir -p "${Qt4BuildDir}" && cd "${Qt4BuildDir}"
  246. for arch in ${ARCH_LIST} ; do
  247. ARCHS="${ARCHS} -arch ${arch}"
  248. done
  249. echo configure options:
  250. echo ${Qt4ConfigureOptions} ${ARCHS} -prefix "${QtInstallDir}"
  251. echo yes | "${Qt4SourceDir}"/configure ${Qt4ConfigureOptions} ${ARCHS} -prefix "${QtInstallDir}"
  252. make && make install
  253. )
  254. cd "${QtInstallDir}" && (
  255. mkdir -p include
  256. cd include
  257. for libnm in ${QtLibraries} ; do
  258. test -d ${libnm} -o -L ${libnm} || ln -s ../lib/${libnm}.framework/Headers ${libnm}
  259. done
  260. )
  261. fi
  262. if [ -d "${HunSpellSourceDir}" -a ! -f "${HunSpellInstallHdr}" ]; then
  263. # we have a private HunSpell source tree at hand...
  264. # so let's build and install it
  265. if [ -z "${HunSpellVersion}" ]; then
  266. HunSpellVersion=`grep AC_INIT "${HunSpellSourceDir}"/configure.ac | cut -d, -f2|tr -d " ()"`
  267. fi
  268. HunSpellName="Hunspell"
  269. HunSpellBase="${HunSpellName}-${HunSpellVersion}"
  270. echo Build hunspell library ${HunSpellBase}
  271. echo configure options:
  272. echo --prefix="${HunSpellInstallDir}" ${HunspellConfigureOptions}
  273. cd "${HunSpellSourceDir}"
  274. # ----------------------------------------
  275. # Build HunSpell for different architectures
  276. # ----------------------------------------
  277. FILE_LIST="libhunspell-1.2.0.dylib"
  278. for arch in ${ARCH_LIST} ; do
  279. make distclean
  280. CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"; export CPPFLAGS
  281. LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"; export LDFLAGS
  282. HOSTSYSTEM=`eval "echo \\$HostSystem_$arch"`
  283. "${HunSpellSourceDir}/configure"\
  284. --prefix="${HunSpellInstallDir}"\
  285. ${HunspellConfigureOptions}
  286. make && make install${strip}
  287. for file in ${FILE_LIST} ; do
  288. if [ -f "${HunSpellInstallDir}"/lib/${file} ]; then
  289. mv "${HunSpellInstallDir}"/lib/${file}\
  290. "${HunSpellInstallDir}"/lib/${file}-${arch}
  291. else
  292. echo Cannot build and install HunSpell for ${arch}.
  293. exit 1
  294. fi
  295. done
  296. done
  297. # -------------------------
  298. # Create universal binaries
  299. # -------------------------
  300. for file in ${FILE_LIST} ; do
  301. OBJ_LIST=
  302. for arch in ${ARCH_LIST} ; do
  303. OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
  304. done
  305. (
  306. cd "${HunSpellInstallDir}"
  307. lipo -create ${OBJ_LIST} -o lib/${file}
  308. # check for the "missing link"...
  309. test -f lib/libhunspell.dylib || (cd lib ; ln -s libhunspell-1.2.dylib libhunspell.dylib)
  310. )
  311. done
  312. # --------
  313. # Clean up
  314. # --------
  315. for arch in ${ARCH_LIST} ; do
  316. rm -f "${HunSpellInstallDir}"/lib/*-${arch}
  317. done
  318. fi
  319. if [ -d "${ASpellSourceDir}" -a ! -f "${ASpellInstallHdr}" -a "yes" = "${aspell_deployment}" ]; then
  320. # we have a private ASpell source tree at hand...
  321. # so let's build and install it
  322. if [ -z "${ASpellVersion}" ]; then
  323. ASpellVersion=`grep AC_INIT "${ASpellSourceDir}"/configure.ac | cut -d, -f2|tr -d " ()"`
  324. fi
  325. ASpellName="Aspell"
  326. ASpellBase="${ASpellName}-${ASpellVersion}"
  327. echo Build aspell library ${ASpellBase}
  328. echo configure options:
  329. echo --prefix="${ASpellInstallDir}" ${AspellConfigureOptions}
  330. # ASpell builds inplace only :(
  331. cd "${ASpellSourceDir}"
  332. # ----------------------------------------
  333. # Build ASpell for different architectures
  334. # ----------------------------------------
  335. FILE_LIST="libaspell.15.dylib"
  336. for arch in ${ARCH_LIST} ; do
  337. make distclean
  338. CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"; export CPPFLAGS
  339. LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"; export LDFLAGS
  340. HOSTSYSTEM=`eval "echo \\$HostSystem_$arch"`
  341. CXXFLAGS=-g "${ASpellSourceDir}/configure"\
  342. --prefix="${ASpellInstallDir}"\
  343. ${AspellConfigureOptions}
  344. make && make install${aspellstrip}
  345. for file in ${FILE_LIST} ; do
  346. if [ -f "${ASpellInstallDir}"/lib/${file} ]; then
  347. mv "${ASpellInstallDir}"/lib/${file}\
  348. "${ASpellInstallDir}"/lib/${file}-${arch}
  349. else
  350. echo Cannot build and install ASpell for ${arch}.
  351. exit 1
  352. fi
  353. done
  354. done
  355. # -------------------------
  356. # Create universal binaries
  357. # -------------------------
  358. for file in ${FILE_LIST} ; do
  359. OBJ_LIST=
  360. for arch in ${ARCH_LIST} ; do
  361. OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
  362. done
  363. (
  364. cd "${ASpellInstallDir}"
  365. lipo -create ${OBJ_LIST} -o lib/${file}
  366. )
  367. done
  368. # --------
  369. # Clean up
  370. # --------
  371. for arch in ${ARCH_LIST} ; do
  372. rm -f "${ASpellInstallDir}"/lib/*-${arch}
  373. done
  374. fi
  375. framework_name() {
  376. echo "Frameworks/${1}.framework"
  377. }
  378. LYX_FILE_LIST="lyx lyxclient tex2lyx"
  379. BUNDLE_PATH="Contents/MacOS"
  380. LYX_BUNDLE_PATH="${LyxAppPrefix}/${BUNDLE_PATH}"
  381. build_lyx() {
  382. # Clear Output
  383. if [ -n "${LyxAppZip}" -a -f "${LyxAppZip}" ]; then rm "${LyxAppZip}"; fi
  384. if [ -d "${LyxAppPrefix}" ]; then rm -rf "${LyxAppPrefix}"; fi
  385. # -------------------------------------
  386. # Automate configure check
  387. # -------------------------------------
  388. if [ ! -f "${LyxSourceDir}"/configure -o "${LyxSourceDir}"/configure -ot "${LyxSourceDir}"/configure.ac ]; then
  389. ( cd "${LyxSourceDir}" && sh autogen.sh )
  390. else
  391. find "${LyxSourceDir}" -name Makefile.am -print | while read file ; do
  392. dname=`dirname "$file"`
  393. if [ -f "$dname/Makefile.in" -a "$dname/Makefile.in" -ot "$file" ]; then
  394. ( cd "${LyxSourceDir}" && sh autogen.sh )
  395. break
  396. fi
  397. done
  398. fi
  399. # -------------------------------------
  400. # Build LyX for different architectures
  401. # -------------------------------------
  402. if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_deployment}" ]; then
  403. ConfigureExtraInc="--with-extra-inc=${ASpellInstallDir}/include"
  404. ConfigureExtraLib="--with-extra-lib=${ASpellInstallDir}/lib"
  405. fi
  406. if [ -d "${HunSpellInstallDir}" -a "yes" = "${hunspell_deployment}" ]; then
  407. HunSpellFramework=`framework_name Hunspell`
  408. HunSpellFramework=`basename "${HunSpellFramework}"`
  409. ConfigureExtraInc="--with-extra-inc=${HunSpellInstallDir}/include"
  410. ConfigureExtraLib="--with-extra-lib=${HunSpellInstallDir}/lib"
  411. # LyXConfigureOptions="${LyXConfigureOptions} --with-hunspell-framework=${HunSpellFramework}"
  412. fi
  413. LyXConfigureOptions="${LyXConfigureOptions} ${ConfigureExtraInc}"
  414. LyXConfigureOptions="${LyXConfigureOptions} ${ConfigureExtraLib}"
  415. for arch in ${ARCH_LIST} ; do
  416. if [ -d "${LyxBuildDir}" ]; then rm -r "${LyxBuildDir}"; fi
  417. mkdir -p "${LyxBuildDir}" && cd "${LyxBuildDir}"
  418. CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"
  419. LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch} ${MYCFLAGS}"
  420. HOSTSYSTEM=`eval "echo \\$HostSystem_$arch"`
  421. if [ "$configure_qt4_frameworks" = "yes" ]; then
  422. export QT4_CORE_CFLAGS="-FQtCore"
  423. export QT4_CORE_LIBS="-framework QtCore"
  424. export QT4_FRONTEND_CFLAGS="-FQtGui"
  425. export QT4_FRONTEND_LIBS="-framework QtGui"
  426. export PKG_CONFIG=""
  427. CPPFLAGS="${CPPFLAGS} -I${SDKROOT}/Library/Frameworks/QtCore.framework/Headers"
  428. CPPFLAGS="${CPPFLAGS} -I${SDKROOT}/Library/Frameworks/QtGui.framework/Headers"
  429. fi
  430. LDFLAGS="${LDFLAGS}"${CARBON:+" -framework Carbon"}
  431. LDFLAGS="${LDFLAGS} -framework AppKit"
  432. echo LDFLAGS="${LDFLAGS}"
  433. export LDFLAGS
  434. echo CPPFLAGS="${CPPFLAGS}"
  435. export CPPFLAGS
  436. echo CONFIGURE_OPTIONS="${LyXConfigureOptions}" ${QtInstallDir:+"--with-qt4-dir=${QtInstallDir}"}
  437. "${LyxSourceDir}/configure"\
  438. --prefix="${LyxAppPrefix}" --with-version-suffix="-${LyXVersionSuffix}"\
  439. ${QtInstallDir:+"--with-qt4-dir=${QtInstallDir}"} \
  440. ${LyXConfigureOptions}\
  441. --enable-build-type=rel && \
  442. make -j2 && make install${strip}
  443. for file in ${LYX_FILE_LIST} ; do
  444. if [ -f "${LYX_BUNDLE_PATH}/${file}" ]; then
  445. mv "${LYX_BUNDLE_PATH}/${file}"\
  446. "${LYX_BUNDLE_PATH}/${file}-${arch}"
  447. else
  448. echo ERROR: Cannot build and install LyX for ${arch}.
  449. exit 1
  450. fi
  451. done
  452. done
  453. }
  454. content_directory() {
  455. target="$1"
  456. content=`dirname "${target}"`
  457. content=`dirname "${content}"`
  458. echo "${content}"
  459. }
  460. private_framework() {
  461. fwdir=`framework_name "$1"`
  462. source="$2"
  463. target="$3"
  464. condir=`content_directory "${target}"`
  465. libnm=`basename "${source}"`
  466. mkdir -p "${condir}/${fwdir}"
  467. if [ ! -f "${condir}/${fwdir}/${libnm}" ]; then
  468. cp -p "${source}" "${condir}/${fwdir}"
  469. echo Set library id in "${condir}/${fwdir}/${libnm}"
  470. install_name_tool -id "@executable_path/../${fwdir}/${libnm}" "${condir}/${fwdir}/${libnm}"
  471. fi
  472. echo Correct library id reference to "${libnm}" in "${target}"
  473. install_name_tool -change "${source}" "@executable_path/../${fwdir}/${libnm}" "${target}"
  474. }
  475. deploy_qtlibs() {
  476. source="${QtInstallDir}"
  477. target="$1"
  478. version="Versions/${QtFrameworkVersion}/"
  479. condir=`content_directory "${target}"`
  480. mkdir -p "${condir}/Resources"
  481. test -f "${condir}/Resources/qt.conf" || cat - > "${condir}/Resources/qt.conf" <<-EOF
  482. [Paths]
  483. Plugins = PlugIns
  484. Translations = translations
  485. EOF
  486. if [ ! -d "${condir}/PlugIns" ]; then
  487. mkdir -p "${condir}/PlugIns"
  488. find "${source}/plugins" -name \*.dylib -print | while read libname ; do
  489. echo Copy plugin "${libname}"
  490. dylib=`basename "${libname}"`
  491. dirname=`dirname "${libname}"`
  492. dirname=`basename "${dirname}"`
  493. mkdir -p "${condir}/PlugIns/${dirname}"
  494. cp -p "${libname}" "${condir}/PlugIns/${dirname}"
  495. done
  496. fi
  497. for libnm in ${QtLibraries} ; do
  498. fwdir=`framework_name "$libnm"`
  499. dirname=`dirname "${fwdir}"`
  500. mkdir -p "${condir}/${dirname}"
  501. dirname=`basename "${fwdir}"`
  502. test -d "${condir}/${fwdir}" || (
  503. echo Copy framework "${source}/lib/"`basename "${fwdir}"`
  504. cp -pR "${source}/lib/"`basename "${fwdir}"` "${condir}/${fwdir}"
  505. echo Set library id in "${condir}/${fwdir}/${version}${libnm}"
  506. install_name_tool -id "@executable_path/../${fwdir}/${version}${libnm}" "${condir}/${fwdir}/${version}${libnm}"
  507. find "${condir}/PlugIns" "${condir}/"`dirname "${fwdir}"` -name Headers -prune -o -type f -print | while read filename ; do
  508. if [ "${filename}" != "${target}" ]; then
  509. otool -L "${filename}" 2>/dev/null | sort -u | while read library ; do
  510. # pattern match for: /path/to/qt4/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.6.0, current version 4.6.2)
  511. case "${library}" in
  512. *"${libnm}"*"("*version*")"*)
  513. echo Correct library id reference to "${libnm}" in "${filename}"
  514. install_name_tool -change\
  515. "${source}/lib/${dirname}/${version}${libnm}"\
  516. "@executable_path/../${fwdir}/${version}${libnm}"\
  517. "${filename}"
  518. ;;
  519. esac
  520. done
  521. fi
  522. done
  523. )
  524. echo Correct library id reference to "${libnm}" in "${target}"
  525. install_name_tool -change\
  526. "${source}/lib/${dirname}/${version}${libnm}"\
  527. "@executable_path/../${fwdir}/${version}${libnm}"\
  528. "${target}"
  529. done
  530. if [ ! -d "${condir}/translations" ]; then
  531. mkdir -p "${condir}/translations"
  532. fi
  533. echo Copy Qt translations to "${condir}/translations"
  534. cp -p "${source}"/translations/qt_*.qm "${condir}/translations"
  535. }
  536. # -------------------------
  537. # Create universal binaries
  538. # -------------------------
  539. convert_universal() {
  540. cd "${LyxAppPrefix}"
  541. for file in ${LYX_FILE_LIST} ; do
  542. OBJ_LIST=
  543. for arch in ${ARCH_LIST} ; do
  544. if [ -f "${BUNDLE_PATH}/${file}-${arch}" ]; then
  545. OBJ_LIST="${OBJ_LIST} ${BUNDLE_PATH}/${file}-${arch}"
  546. fi
  547. done
  548. if [ -n "${OBJ_LIST}" ]; then
  549. lipo -create ${OBJ_LIST} -o "${BUNDLE_PATH}/${file}"
  550. fi
  551. if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_deployment}" ]; then
  552. private_framework Aspell "${ASpellInstallDir}/lib/libaspell.15.dylib" "${LYX_BUNDLE_PATH}/${file}"
  553. fi
  554. if [ -d "${HunSpellInstallDir}" -a "yes" = "${hunspell_deployment}" ]; then
  555. private_framework Hunspell "${HunSpellInstallDir}/lib/libhunspell-1.2.0.dylib" "${LYX_BUNDLE_PATH}/${file}"
  556. fi
  557. if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt4_deployment}" ]; then
  558. deploy_qtlibs "${LYX_BUNDLE_PATH}/${file}"
  559. fi
  560. otool -L "${BUNDLE_PATH}/${file}" | while read reference ; do
  561. case "${reference}" in
  562. *"${LyxBuildDir}"*"("*")")
  563. echo ERROR: Bad reference to "${reference}" found!!
  564. ;;
  565. esac
  566. done
  567. done
  568. for arch in ${ARCH_LIST} ; do
  569. rm -f ${BUNDLE_PATH}/*-${arch}
  570. done
  571. }
  572. copy_dictionaries() {
  573. if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_dictionaries}" ]; then
  574. ASpellResources="${LyxAppPrefix}/Contents/Resources"
  575. # try to reuse macports dictionaries for now
  576. if [ -d /opt/local/lib/aspell-0.60 ]; then ASpellInstallDir=/opt/local ; fi
  577. mkdir -p "${ASpellResources}"
  578. echo Copy Aspell dictionaries from "${ASpellInstallDir}"
  579. mkdir -p "${ASpellResources}"/data "${ASpellResources}"/dicts
  580. cp -p -r "${ASpellInstallDir}/lib/aspell-0.60"/* "${ASpellResources}"/data
  581. cp -p -r "${ASpellInstallDir}/share/aspell"/* "${ASpellResources}"/dicts
  582. fi
  583. if [ -d "${HunSpellInstallDir}" -a "yes" = "${hunspell_dictionaries}" ]; then
  584. HunSpellResources="${LyxAppPrefix}/Contents/Resources"
  585. if [ -d "${DictionarySourceDir}" ]; then
  586. ( cd "${DictionarySourceDir}" && find dicts -name .svn -prune -o -type f -print | cpio -pmdv "${HunSpellResources}" )
  587. fi
  588. fi
  589. if [ -d "${DictionarySourceDir}" -a "yes" = "${thesaurus_deployment}" ]; then
  590. MyThesResources="${LyxAppPrefix}/Contents/Resources"
  591. ( cd "${DictionarySourceDir}" && find thes -name .svn -prune -o -type f -print | cpio -pmdv "${MyThesResources}" )
  592. fi
  593. }
  594. set_bundle_display_options() {
  595. X_BOUNDS=$2
  596. Y_BOUNDS=$3
  597. Y_POSITION=$((Y_BOUNDS - 65))
  598. Y_BOUNDS=$((Y_BOUNDS + 20))
  599. LYX_X_POSITION=$((X_BOUNDS / 4))
  600. LYX_Y_POSITION=$Y_POSITION
  601. APP_X_POSITION=$((3 * X_BOUNDS / 4))
  602. APP_Y_POSITION=$Y_POSITION
  603. osascript <<-EOF
  604. tell application "Finder"
  605. set f to POSIX file ("${1}" as string) as alias
  606. tell folder f
  607. open
  608. tell container window
  609. set toolbar visible to false
  610. set statusbar visible to false
  611. set current view to icon view
  612. delay 1 -- sync
  613. set the bounds to {20, 50, $X_BOUNDS, $Y_BOUNDS}
  614. end tell
  615. delay 1 -- sync
  616. set icon size of the icon view options of container window to 64
  617. set arrangement of the icon view options of container window to not arranged
  618. set position of item "${LyxName}.app" to {$LYX_X_POSITION,$LYX_Y_POSITION}
  619. set position of item "Applications" to {$APP_X_POSITION,$APP_Y_POSITION}
  620. set background picture of the icon view options\
  621. of container window to file "background.png" of folder "Pictures"
  622. set the bounds of the container window to {0, 0, $X_BOUNDS, $Y_BOUNDS}
  623. update without registering applications
  624. delay 5 -- sync
  625. close
  626. end tell
  627. delay 5 -- sync
  628. end tell
  629. EOF
  630. }
  631. make_dmg() {
  632. cd "${1}"
  633. BGSIZE=`file "$DmgBackground" | awk -F , '/PNG/{print $2 }' | tr x ' '`
  634. BG_W=`echo ${BGSIZE} | awk '{print $1 }'`
  635. BG_H=`echo ${BGSIZE} | awk '{print $2 }'`
  636. rm -f "${DMGNAME}.sparseimage" "${DMGNAME}.dmg"
  637. hdiutil create -type SPARSE -size ${DMGSIZE:-"250m"} -fs HFS+ -volname "${LyxBase}" "${DMGNAME}"
  638. # Unmount currently mounted disk image
  639. test -d /Volumes/"${LyxBase}" && umount /Volumes/"${LyxBase}"
  640. # Mount the disk image
  641. hdiutil attach "${DMGNAME}.sparseimage"
  642. # Obtain device information
  643. DEVS=$(hdiutil attach "${DMGNAME}.sparseimage" | cut -f 1)
  644. DEV=$(echo $DEVS | cut -f 1 -d ' ')
  645. VOLUME=$(mount |grep ${DEV} | cut -f 3 -d ' ')
  646. # copy in the application bundle
  647. cp -Rp "${LyxAppDir}.app" "${VOLUME}/${LyxName}.app"
  648. # copy in background image
  649. mkdir -p "${VOLUME}/Pictures"
  650. cp "${DmgBackground}" "${VOLUME}/Pictures/background.png"
  651. # symlink applications
  652. ln -s /Applications/ "${VOLUME}"/Applications
  653. set_bundle_display_options "${VOLUME}" ${BG_W} ${BG_H}
  654. /Developer/Tools/SetFile -a C "${VOLUME}"
  655. mv "${VOLUME}/Pictures" "${VOLUME}/.Pictures"
  656. # Unmount the disk image
  657. hdiutil detach ${DEV}
  658. # Convert the disk image to read-only
  659. hdiutil convert "${DMGNAME}.sparseimage" -format UDBZ -o "${DMGNAME}.dmg"
  660. rm -f "${DMGNAME}.sparseimage"
  661. }
  662. # ------------------------------
  663. # Building distribution packages
  664. # ------------------------------
  665. build_distribution() {
  666. test -n "${LyxAppZip}" && (
  667. cd "${LyxAppPrefix}" && zip -r "${LyxAppZip}" .
  668. )
  669. test -n "${DMGLocation}" && (
  670. make_dmg "${DMGLocation}"
  671. if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt4_deployment}" ]; then
  672. rm -f "${DMGLocation}/${DMGNAME}+qt4.dmg"
  673. echo move to "${DMGLocation}/${DMGNAME}+qt4.dmg"
  674. mv "${DMGLocation}/${DMGNAME}.dmg" "${DMGLocation}/${DMGNAME}+qt4.dmg"
  675. fi
  676. )
  677. }
  678. # ------------------------------
  679. # main block
  680. # ------------------------------
  681. build_lyx
  682. convert_universal
  683. copy_dictionaries
  684. build_distribution