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