]> git.lyx.org Git - lyx.git/blob - development/LyX-Mac-binary-release.sh
Update it.po
[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 # exit 0
420
421
422 framework_name() {
423         echo "Frameworks/${1}.framework"
424 }
425
426 if [ ! -f "${LyxSourceDir}"/configure -o "${LyxSourceDir}"/configure -ot "${LyxSourceDir}"/configure.ac ]; then
427         ( cd "${LyxSourceDir}" && sh autogen.sh )
428 else
429         find "${LyxSourceDir}" -name Makefile.am -print | while read file ; do
430                 dname=`dirname "$file"`
431                 if [ -f "$dname/Makefile.in" -a "$dname/Makefile.in" -ot "$file" ]; then
432                         ( cd "${LyxSourceDir}" && sh autogen.sh )
433                         break
434                 fi
435         done
436 fi
437
438 FILE_LIST="lyx lyxclient tex2lyx"
439 BUNDLE_PATH="Contents/MacOS"
440 LYX_BUNDLE_PATH="${LyxAppPrefix}/${BUNDLE_PATH}"
441 build_lyx() {
442         # Clear Output
443         if [ -n "${LyxAppZip}" -a -f "${LyxAppZip}" ]; then rm "${LyxAppZip}"; fi
444         if [ -d "${LyxAppPrefix}" ]; then rm -rf "${LyxAppPrefix}"; fi
445
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 ${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                                 otool -L "${filename}" 2>/dev/null | while read library ; do
565                                         # pattern match for: /path/to/qt4/lib/QtGui.framework/Versions/4/QtGui (compatibility version 4.6.0, current version 4.6.2)
566                                         case "${library}" in
567                                         *"${libnm}"*"("*")"*)
568                                                 echo Correct library id reference to "${libnm}" in "${filename}"
569                                                 install_name_tool -change\
570                                                         "${source}/lib/${dirname}/${version}${libnm}"\
571                                                         "@executable_path/../${fwdir}/${version}${libnm}"\
572                                                         "${filename}"
573                                                 ;;
574                                         esac
575                                 done
576                         done
577                 )
578                 echo Correct library id reference to "${libnm}" in "${target}"
579                 install_name_tool -change\
580                         "${source}/lib/${dirname}/${version}${libnm}"\
581                         "@executable_path/../${fwdir}/${version}${libnm}"\
582                         "${target}"
583         done
584 }
585
586 # -------------------------
587 # Create universal binaries
588 # -------------------------
589 convert_universal() {
590         cd "${LyxAppPrefix}"
591         for file in ${FILE_LIST} ; do
592                 OBJ_LIST=
593                 for arch in ${ARCH_LIST} ; do
594                         if [ -f "${BUNDLE_PATH}/${file}-${arch}" ]; then
595                                 OBJ_LIST="${OBJ_LIST} ${BUNDLE_PATH}/${file}-${arch}"
596                         fi
597                 done
598                 if [ -n "${OBJ_LIST}" ]; then
599                         lipo -create ${OBJ_LIST} -o "${BUNDLE_PATH}/${file}"
600                 fi
601                 if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_deployment}" ]; then
602                         private_framework Aspell "${ASpellInstallDir}/lib/libaspell.15.dylib" "${LYX_BUNDLE_PATH}/${file}"
603                 fi
604                 if [ -d "${HunSpellInstallDir}" -a "yes" = "${hunspell_deployment}" ]; then
605                         private_framework Hunspell "${HunSpellInstallDir}/lib/libhunspell-1.2.0.dylib" "${LYX_BUNDLE_PATH}/${file}"
606                 fi
607                 if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt4_deployment}" ]; then
608                         deploy_qtlibs "${LYX_BUNDLE_PATH}/${file}"
609                 fi
610                 otool -L "${BUNDLE_PATH}/${file}" | while read reference ; do
611                         case "${reference}" in
612                         *"${LyxBuildDir}"*"("*")")
613                                 echo ERROR: Bad reference to "${reference}" found!!
614                                 ;;
615                         esac
616                 done
617         done
618         for arch in ${ARCH_LIST} ; do
619                 rm -f ${BUNDLE_PATH}/*-${arch}
620         done
621 }
622
623 copy_dictionaries() {
624         if [ -d "${ASpellInstallDir}" -a "yes" = "${aspell_dictionaries}" ]; then
625                 ASpellResources="${LyxAppPrefix}/Contents/Resources"
626                 # try to reuse macports dictionaries for now
627                 if [ -d /opt/local/lib/aspell-0.60 ]; then ASpellInstallDir=/opt/local ; fi
628                 mkdir -p "${ASpellResources}"
629                 echo Copy Aspell dictionaries from "${ASpellInstallDir}"
630                 mkdir -p "${ASpellResources}"/data "${ASpellResources}"/dicts
631                 cp -p -r "${ASpellInstallDir}/lib/aspell-0.60"/* "${ASpellResources}"/data
632                 cp -p -r "${ASpellInstallDir}/share/aspell"/* "${ASpellResources}"/dicts
633         fi
634         if [ -d "${HunSpellInstallDir}" -a "yes" = "${hunspell_dictionaries}" ]; then
635                 HunSpellResources="${LyxAppPrefix}/Contents/Resources"
636                 if [ -d "${DictionarySourceDir}" ]; then
637                         ( cd "${DictionarySourceDir}" && find dicts -name .svn -prune -o -type f -print | cpio -pmdv "${HunSpellResources}" )
638                 fi
639         fi
640         if [ -d "${DictionarySourceDir}" -a "yes" = "${thesaurus_deployment}" ]; then
641                 MyThesResources="${LyxAppPrefix}/Contents/Resources"
642                 ( cd "${DictionarySourceDir}" && find thes -name .svn -prune -o -type f -print | cpio -pmdv "${MyThesResources}" )
643         fi
644 }
645
646 function set_bundle_display_options() {
647         osascript <<-EOF
648     tell application "Finder"
649         set f to POSIX file ("${1}" as string) as alias
650         tell folder f
651             open
652             tell container window
653                 set toolbar visible to false
654                 set statusbar visible to false
655                 set current view to icon view
656                 delay 1 -- sync
657                 set the bounds to {20, 50, $2, $3}
658             end tell
659             delay 1 -- sync
660             set icon size of the icon view options of container window to 64
661             set arrangement of the icon view options of container window to not arranged
662             set position of item "${LyxName}.app" to {100,$4}
663             set position of item "Applications" to {280,$4}
664             set background picture of the icon view options\
665                                         of container window to file "background.png" of folder "Pictures"
666             set the bounds of the container window to {0, 0, $2, $3}
667             update without registering applications
668             delay 5 -- sync
669             close
670         end tell
671         delay 5 -- sync
672     end tell
673 EOF
674 }
675
676 function make_dmg() {
677         cd "${1}"
678
679         BGSIZE=`file "$BACKGROUND" | awk -F , '/PNG/{print $2 }' | tr x ' '`
680         BG_W=`echo ${BGSIZE} | awk '{print $1 }'`
681         BG_H=`echo ${BGSIZE} | awk '{h = $2 + 20 ;print h }'`
682         BG_Y=`echo ${BGSIZE} | awk '{y = $2 - 60 ;print y }'`
683
684         rm -f "${DMGNAME}.sparseimage" "${DMGNAME}.dmg"
685
686         hdiutil create -type SPARSE -size ${DMGSIZE:-"250m"} -fs HFS+ -volname "${LyxBase}" "${DMGNAME}"
687         # Unmount currently mounted disk image
688         test -d /Volumes/"${LyxBase}" && umount /Volumes/"${LyxBase}"
689
690         # Mount the disk image
691         hdiutil attach "${DMGNAME}.sparseimage"
692
693         # Obtain device information
694         DEVS=$(hdiutil attach "${DMGNAME}.sparseimage" | cut -f 1)
695         DEV=$(echo $DEVS | cut -f 1 -d ' ')
696         VOLUME=$(mount |grep ${DEV} | cut -f 3 -d ' ')
697
698         # copy in the application bundle
699         cp -Rp "${LyxAppDir}.app" "${VOLUME}/${LyxName}.app"
700
701         # copy in background image
702         mkdir -p "${VOLUME}/Pictures"
703         cp "${BACKGROUND}" "${VOLUME}/Pictures/background.png"
704         # symlink applications
705         ln -s /Applications/ "${VOLUME}"/Applications
706         set_bundle_display_options "${VOLUME}" ${BG_W} ${BG_H} ${BG_Y}
707         mv "${VOLUME}/Pictures" "${VOLUME}/.Pictures"
708
709         # Unmount the disk image
710         hdiutil detach ${DEV}
711
712         # Convert the disk image to read-only
713         hdiutil convert "${DMGNAME}.sparseimage" -format UDBZ -o "${DMGNAME}.dmg"
714         rm -f "${DMGNAME}.sparseimage"
715 }
716
717 build_lyx
718 convert_universal
719 copy_dictionaries
720
721 # ------------------------------
722 # Building distribution packages
723 # ------------------------------
724
725 test -n "${LyxAppZip}" && (
726         cd "${LyxAppPrefix}" && zip -r "${LyxAppZip}" .
727 )
728
729 test -n "${DMGLocation}" && (
730         make_dmg "${DMGLocation}"
731         if [ -d "${QtInstallDir}/lib/QtCore.framework/Versions/${QtFrameworkVersion}" -a "yes" = "${qt4_deployment}" ]; then
732                 rm -f "${DMGLocation}/${DMGNAME}+qt4.dmg"
733                 echo move to "${DMGLocation}/${DMGNAME}+qt4.dmg"
734                 mv "${DMGLocation}/${DMGNAME}.dmg" "${DMGLocation}/${DMGNAME}+qt4.dmg"
735                 #for libnm in ${QtLibraries} ; do
736                 #       fwdir=`framework_name "$libnm"`
737                 #       rm -rf "${LyxAppDir}.app/Contents/${fwdir}"
738                 #done
739                 #make_dmg "${DMGLocation}"
740         fi
741 )