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