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