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