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