]> git.lyx.org Git - lyx.git/blob - development/LyX-Mac-binary-release.sh
Don't overwrite identical files on export even when FORCE is in effect.
[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: 17 April 2010
9
10 # Prerequisite:
11 # * a decent checkout of LyX sources (probably you have it already)
12 # * Qt4 - build with static libraries for the used platforms (i386 and ppc)
13 # * for aspell support:
14 #   the aspell sources placed in a sibling directory (variable ASpellSourceVersion)
15
16 # Set these variables -- to
17 # (1) the location of your Qt4 installation and optionally
18 # (2) the location of resulting DMG
19 # (3) the version of private aspell installation
20 #     (to define the location assign ASpellSourceDir instead)
21 # (4) the list of architectures to build for
22
23 QtInstallDir=${QTDIR:-"/opt/qt4"}
24 DMGLocation=.. # one level above LyxSourceDir
25 ASpellSourceVersion="aspell-0.60.6"
26 ARCH_LIST="ppc i386"
27
28 GetText="--with-included-gettext"
29 ConfigureOptions="--enable-warnings --enable-optimization=-Os"
30
31 # strip="-strip"
32
33 # detection of script home
34 LyxSourceDir=${1:-`dirname "$0"`}
35 if [ ! -d "${LyxSourceDir}" ]; then
36         echo Missing LyX source directory.
37         exit 2
38 fi
39 case "${LyxSourceDir}" in
40 /*/development)
41         LyxSourceDir=`dirname "${LyxSourceDir}"`
42         ;;
43 /*)
44         ;;
45 */development|development)
46         LyxSourceDir=`dirname "${LyxSourceDir}"`
47         LyxSourceDir=`cd "${LyxSourceDir}";pwd`
48         ;;
49 *)
50         LyxSourceDir=`cd "${LyxSourceDir}";pwd`
51         ;;
52 esac
53
54 ASpellSourceDir=${ASpellSourceDir:-`dirname "${LyxSourceDir}"`/${ASpellSourceVersion}}
55 ASpellInstallDir=${ASpellInstallDir:-`dirname "${LyxSourceDir}"`/${ASpellSourceVersion}.lib}
56
57 if [ ! -f "${LyxSourceDir}"/configure ]; then
58         ( cd "${LyxSourceDir}" && sh autogen.sh )
59 fi
60 if [ -z "${LyXVersion}" ]; then
61         LyXVersion=`grep AC_INIT "${LyxSourceDir}"/configure.ac | cut -d, -f2 | tr -d " ()"`
62 fi
63
64 LyxName="LyX"
65 LyxBase="${LyxName}-${LyXVersion}"
66 LyxApp="${LyxBase}.app"
67 LyxAppDir=`dirname "${LyxSourceDir}"`/"${LyxBase}"
68 LyxBuildDir="${LyxAppDir}.build"
69 LyxAppPrefix="${LyxAppDir}.app"
70 # if zip file is needed... remove the comment sign
71 #LyxAppZip="${LyxAppPrefix}.zip"
72
73 BuildSystem=`"${LyxSourceDir}/config/config.guess"`
74
75 # ---------------------------------
76 # DON'T MODIFY ANYTHING BELOW HERE!
77 # ---------------------------------
78
79 # These variables define the identifiers of the
80 # system (both Intel and PowerPC) to compile for.
81 # (Note: darwin8 is 10.4; darwin9 is 10.5.)
82 # Only change these if necessary
83
84 HostSystem_i386="i686-apple-darwin8"
85 HostSystem_ppc="powerpc-apple-darwin8"
86
87 # Check for existing SDKs
88 # 10.6 cannot be used for 10.4 currently
89 SDKs=`echo /Developer/SDKs/MacOSX10*sdk`
90 case "$SDKs" in
91 *10.6*)
92         MACOSX_DEPLOYMENT_TARGET="10.5"; export MACOSX_DEPLOYMENT_TARGET
93         SDKROOT="/Developer/SDKs/MacOSX10.5.sdk"; export SDKROOT
94         ;;
95 *10.5*)
96         MACOSX_DEPLOYMENT_TARGET="10.4"; export MACOSX_DEPLOYMENT_TARGET
97         SDKROOT="/Developer/SDKs/MacOSX10.4u.sdk"; export SDKROOT
98         ;;
99 *)
100         echo Unknown or missing SDK for Mac OS X.
101         exit 1
102         ;;
103 esac
104
105 if [ -d "${ASpellSourceDir}" -a ! -d "${ASpellInstallDir}" ]; then
106         # we have a private ASpell source tree at hand...
107         # so let's build and install it
108         if [ -z "${ASpellVersion}" ]; then
109                 ASpellVersion=`grep AC_INIT "${ASpellSourceDir}"/configure.ac | cut -d, -f2|tr -d " ()"`
110         fi
111
112         ASpellName="Aspell"
113         ASpellBase="${ASpellName}-${ASpellVersion}"
114         ASpellLib="${ASpellBase}.lib"
115         ASpellLibDir=`dirname "${ASpellSourceDir}"`/"${ASpellBase}"
116         ASpellLibPrefix="${ASpellInstallDir:-${ASpellLibDir}.lib}"
117
118         # Clear Output
119         if [ -n "${ASpellLibZip}" -a -f "${ASpellLibZip}" ]; then rm "${ASpellLibZip}"; fi
120         if [ -d "${ASpellLibPrefix}" ]; then rm -r "${ASpellLibPrefix}"; fi
121
122         # ASpell builds inplace only :(
123         cd "${ASpellSourceDir}" && make distclean
124
125         # ----------------------------------------
126         # Build ASpell for different architectures
127         # ----------------------------------------
128         FILE_LIST="libaspell.15.dylib libpspell.15.dylib"
129
130         for arch in ${ARCH_LIST} ; do
131                 LDFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch}"; export LDFLAGS
132                 LDFLAGS="${CPPFLAGS}"; export LDFLAGS
133                 HOSTSYSTEM=`eval "echo \\$HostSystem_$arch"`
134                 "${ASpellSourceDir}/configure"\
135                         --prefix="${ASpellLibPrefix}"\
136                         ${ConfigureOptions}\
137                         ${GetText} --host="${HOSTSYSTEM}" ${BuildSystem:+"--build=${BuildSystem}"} --enable-build-type=rel
138                 make && make install${strip}
139                 for file in ${FILE_LIST} ; do
140                         if [ -f "${ASpellLibPrefix}"/lib/${file} ]; then
141                                 mv "${ASpellLibPrefix}"/lib/${file}\
142                                         "${ASpellLibPrefix}"/lib/${file}-${arch} 
143                         else
144                                 echo Cannot build and install ASpell for ${arch}.
145                                 exit 1
146                         fi
147                 done
148                 make distclean
149         done
150         # -------------------------
151         # Create universal binaries
152         # -------------------------
153         for file in ${FILE_LIST} ; do
154                 OBJ_LIST=
155                 for arch in ${ARCH_LIST} ; do
156                         OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
157                 done
158                 (
159                         cd "${ASpellLibPrefix}"
160                         lipo -create ${OBJ_LIST} -o lib/${file}
161                 )
162         done
163         # --------
164         # Clean up
165         # --------
166         for arch in ${ARCH_LIST} ; do
167                 rm -f "${ASpellLibPrefix}"/lib/*-${arch}
168         done
169 fi
170
171 # Clear Output
172 if [ -n "${LyxAppZip}" -a -f "${LyxAppZip}" ]; then rm "${LyxAppZip}"; fi
173 if [ -d "${LyxAppPrefix}" ]; then rm -r "${LyxAppPrefix}"; fi
174
175 # -------------------------------------
176 # Build LyX for different architectures
177 # -------------------------------------
178 FILE_LIST="lyx lyxclient tex2lyx"
179
180 if [ -d "${ASpellInstallDir}" ]; then
181         ConfigureOptions="${ConfigureOptions} --with-extra-inc=${ASpellInstallDir}/include"
182         ConfigureOptions="${ConfigureOptions} --with-extra-lib=${ASpellInstallDir}/lib"
183 fi
184
185 for arch in ${ARCH_LIST} ; do
186
187         if [ -d "${LyxBuildDir}" ];  then rm -r "${LyxBuildDir}"; fi
188         mkdir "${LyxBuildDir}" && cd "${LyxBuildDir}"
189
190         CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch}"; export CPPFLAGS
191         LDFLAGS="${CPPFLAGS}"; export LDFLAGS
192         HOSTSYSTEM=`eval "echo \\$HostSystem_$arch"`
193
194         echo LDFLAGS="${LDFLAGS}"
195         echo CPPFLAGS="${CPPFLAGS}"
196         "${LyxSourceDir}/configure"\
197                 --prefix="${LyxAppPrefix}" --with-version-suffix="-${LyXVersion}"\
198                 ${QtInstallDir:+"--with-qt4-dir=${QtInstallDir}"} \
199                 ${ConfigureOptions}\
200                 ${GetText} --host="${HOSTSYSTEM}" --build="${BuildSystem}" --enable-build-type=rel
201         make && make install${strip}
202         for file in ${FILE_LIST} ; do
203                 if [ -f "${LyxAppPrefix}"/Contents/MacOS/${file} ]; then
204                         mv "${LyxAppPrefix}"/Contents/MacOS/${file}\
205                                 "${LyxAppPrefix}"/Contents/MacOS/${file}-${arch} 
206                 else
207                         echo Cannot build and install LyX for ${arch}.
208                         exit 1
209                 fi
210         done
211 done
212
213 # -------------------------
214 # Create universal binaries
215 # -------------------------
216
217 ASpellFramework="Frameworks/Aspell.framework"
218 if [ -d "${ASpellInstallDir}" ]; then
219         ASpellDyLib=`basename "${ASpellInstallDir}/lib/"libaspell.*.dylib`
220         mkdir -p "${LyxAppPrefix}"/Contents/${ASpellFramework}/lib
221         cp -p "${ASpellInstallDir}/lib/${ASpellDyLib}" "${LyxAppPrefix}"/Contents/${ASpellFramework}/lib
222         install_name_tool -id "@executable_path/../${ASpellFramework}/lib/${ASpellDyLib}" "${LyxAppPrefix}"/Contents/${ASpellFramework}/lib/"${ASpellDyLib}"
223 fi
224
225 for file in ${FILE_LIST} ; do
226         OBJ_LIST=
227         for arch in ${ARCH_LIST} ; do
228                 OBJ_LIST="${OBJ_LIST} Contents/MacOS/${file}-${arch}"
229         done
230         (
231                 cd "${LyxAppPrefix}" &&
232                 lipo -create ${OBJ_LIST} -o "${LyxAppPrefix}"/Contents/MacOS/${file}
233         )
234         if [ -d "${ASpellInstallDir}" ]; then
235                 install_name_tool -change \
236                         "${ASpellInstallDir}/lib/${ASpellDyLib}" "@executable_path/../${ASpellFramework}/${ASpellDyLib}" \
237                         "${LyxAppPrefix}"/Contents/MacOS/${file}
238         fi
239 done
240
241 if [ -d "${ASpellInstallDir}" ]; then
242         if [ -d /opt/local/lib/aspell-0.60 ]; then ASpellInstallDir=/opt/local ; fi
243         mkdir -p "${LyxAppPrefix}"/Contents/${ASpellFramework}/lib
244         cp -p -r "${ASpellInstallDir}/lib/aspell-0.60" "${LyxAppPrefix}"/Contents/${ASpellFramework}/lib
245         mkdir -p "${LyxAppPrefix}"/Contents/${ASpellFramework}/share
246         cp -p -r "${ASpellInstallDir}/share/aspell" "${LyxAppPrefix}"/Contents/${ASpellFramework}/share
247 fi
248
249 # --------
250 # Clean up
251 # --------
252
253 for arch in ${ARCH_LIST} ; do
254         rm -f "${LyxAppPrefix}"/Contents/MacOS/*-${arch}
255 done
256
257 # ------------------------------
258 # Building distribution packages
259 # ------------------------------
260
261 test -n "${LyxAppZip}" && (
262         cd "${LyxAppPrefix}" && zip -r "${LyxAppZip}" .
263 )
264
265 DMGNAME="${LyxBase}-Uncompressed.dmg"
266 DMGSIZE="350m"
267 COMPRESSEDDMGNAME="${LyxBase}.dmg"
268 BACKGROUND="${LyxBase}.app/Contents/Resources/images/banner.png"
269
270 function set_bundle_display_options() {
271         osascript <<-EOF
272     tell application "Finder"
273         set f to POSIX file ("${1}" as string) as alias
274         tell folder f
275             open
276             tell container window
277                 set toolbar visible to false
278                 set statusbar visible to false
279                 set current view to icon view
280                 delay 1 -- sync
281                 set the bounds to {20, 50, $2, $3}
282             end tell
283             delay 1 -- sync
284             set icon size of the icon view options of container window to 64
285             set arrangement of the icon view options of container window to not arranged
286             set position of item "${LyxName}.app" to {100,$4}
287             set position of item "Applications" to {280,$4}
288             set background picture of the icon view options\
289                                         of container window to file "background.png" of folder "Pictures"
290             set the bounds of the container window to {0, 0, $2, $3}
291             update without registering applications
292             delay 5 -- sync
293             close
294         end tell
295         delay 5 -- sync
296     end tell
297 EOF
298
299 }
300
301 test -n "${DMGLocation}" && (
302         cd "${DMGLocation}"
303
304         BGSIZE=`file "$BACKGROUND" | awk -F , '/PNG/{print $2 }' | tr x ' '`
305         BG_W=`echo ${BGSIZE} | awk '{print $1 }'`
306         BG_H=`echo ${BGSIZE} | awk '{h = $2 + 20 ;print h }'`
307         BG_Y=`echo ${BGSIZE} | awk '{y = $2 - 60 ;print y }'`
308
309         rm -f ${DMGNAME}
310         rm -f ${COMPRESSEDDMGNAME}
311
312         hdiutil create -size ${DMGSIZE:-"250m"} -fs HFS+ -volname "${LyxBase}" "${DMGNAME}"
313         # Unmount currently mounted disk image
314         test -d /Volumes/"${LyxBase}" && umount /Volumes/"${LyxBase}"
315
316         # Mount the disk image
317         hdiutil attach ${DMGNAME}
318
319         # Obtain device information
320         DEVS=$(hdiutil attach ${DMGNAME} | cut -f 1)
321         DEV=$(echo $DEVS | cut -f 1 -d ' ')
322         VOLUME=$(mount |grep ${DEV} | cut -f 3 -d ' ')
323
324         # copy in the application bundle
325         cp -Rp ${LyxBase}.app ${VOLUME}/${LyxName}.app
326
327         # copy in background image
328         mkdir -p ${VOLUME}/Pictures
329         cp ${BACKGROUND} ${VOLUME}/Pictures/background.png
330         # symlink applications
331         ln -s /Applications/ ${VOLUME}/Applications
332         set_bundle_display_options ${VOLUME} ${BG_W} ${BG_H} ${BG_Y}
333         mv ${VOLUME}/Pictures ${VOLUME}/.Pictures
334
335         # Unmount the disk image
336         hdiutil detach ${DEV}
337
338         # Convert the disk image to read-only
339         hdiutil convert ${DMGNAME} -format UDBZ -o ${COMPRESSEDDMGNAME}
340         rm -f ${DMGNAME}
341 )