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