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