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
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)
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
23 QtInstallDir=${QTDIR:-"/opt/qt4"}
24 DMGLocation=.. # one level above LyxSourceDir
25 ASpellSourceVersion="aspell-0.60.6"
28 GetText="--with-included-gettext"
29 ConfigureOptions="--enable-warnings --enable-optimization=-Os"
33 # detection of script home
34 LyxSourceDir=${1:-`dirname "$0"`}
35 if [ ! -d "${LyxSourceDir}" ]; then
36 echo Missing LyX source directory.
39 case "${LyxSourceDir}" in
41 LyxSourceDir=`dirname "${LyxSourceDir}"`
45 */development|development)
46 LyxSourceDir=`dirname "${LyxSourceDir}"`
47 LyxSourceDir=`cd "${LyxSourceDir}";pwd`
50 LyxSourceDir=`cd "${LyxSourceDir}";pwd`
54 ASpellSourceDir=${ASpellSourceDir:-`dirname "${LyxSourceDir}"`/${ASpellSourceVersion}}
55 ASpellInstallDir=${ASpellInstallDir:-`dirname "${LyxSourceDir}"`/${ASpellSourceVersion}.lib}
57 if [ ! -f "${LyxSourceDir}"/configure ]; then
58 ( cd "${LyxSourceDir}" && sh autogen.sh )
60 if [ -z "${LyXVersion}" ]; then
61 LyXVersion=`grep AC_INIT "${LyxSourceDir}"/configure.ac | cut -d, -f2 | tr -d " ()"`
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"
73 BuildSystem=`"${LyxSourceDir}/config/config.guess"`
75 # ---------------------------------
76 # DON'T MODIFY ANYTHING BELOW HERE!
77 # ---------------------------------
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
84 HostSystem_i386="i686-apple-darwin8"
85 HostSystem_ppc="powerpc-apple-darwin8"
87 # Check for existing SDKs
88 # 10.6 cannot be used for 10.4 currently
89 SDKs=`echo /Developer/SDKs/MacOSX10*sdk`
92 MACOSX_DEPLOYMENT_TARGET="10.5"; export MACOSX_DEPLOYMENT_TARGET
93 SDKROOT="/Developer/SDKs/MacOSX10.5.sdk"; export SDKROOT
96 MACOSX_DEPLOYMENT_TARGET="10.4"; export MACOSX_DEPLOYMENT_TARGET
97 SDKROOT="/Developer/SDKs/MacOSX10.4u.sdk"; export SDKROOT
100 echo Unknown or missing SDK for Mac OS X.
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 " ()"`
113 ASpellBase="${ASpellName}-${ASpellVersion}"
114 ASpellLib="${ASpellBase}.lib"
115 ASpellLibDir=`dirname "${ASpellSourceDir}"`/"${ASpellBase}"
116 ASpellLibPrefix="${ASpellInstallDir:-${ASpellLibDir}.lib}"
119 if [ -n "${ASpellLibZip}" -a -f "${ASpellLibZip}" ]; then rm "${ASpellLibZip}"; fi
120 if [ -d "${ASpellLibPrefix}" ]; then rm -r "${ASpellLibPrefix}"; fi
122 # ASpell builds inplace only :(
123 cd "${ASpellSourceDir}" && make distclean
125 # ----------------------------------------
126 # Build ASpell for different architectures
127 # ----------------------------------------
128 FILE_LIST="libaspell.15.dylib libpspell.15.dylib"
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}"\
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}
144 echo Cannot build and install ASpell for ${arch}.
150 # -------------------------
151 # Create universal binaries
152 # -------------------------
153 for file in ${FILE_LIST} ; do
155 for arch in ${ARCH_LIST} ; do
156 OBJ_LIST="${OBJ_LIST} lib/${file}-${arch}"
159 cd "${ASpellLibPrefix}"
160 lipo -create ${OBJ_LIST} -o lib/${file}
166 for arch in ${ARCH_LIST} ; do
167 rm -f "${ASpellLibPrefix}"/lib/*-${arch}
172 if [ -n "${LyxAppZip}" -a -f "${LyxAppZip}" ]; then rm "${LyxAppZip}"; fi
173 if [ -d "${LyxAppPrefix}" ]; then rm -r "${LyxAppPrefix}"; fi
175 # -------------------------------------
176 # Build LyX for different architectures
177 # -------------------------------------
178 FILE_LIST="lyx lyxclient tex2lyx"
180 if [ -d "${ASpellInstallDir}" ]; then
181 ConfigureOptions="${ConfigureOptions} --with-extra-inc=${ASpellInstallDir}/include"
182 ConfigureOptions="${ConfigureOptions} --with-extra-lib=${ASpellInstallDir}/lib"
185 for arch in ${ARCH_LIST} ; do
187 if [ -d "${LyxBuildDir}" ]; then rm -r "${LyxBuildDir}"; fi
188 mkdir "${LyxBuildDir}" && cd "${LyxBuildDir}"
190 CPPFLAGS="${SDKROOT:+-isysroot ${SDKROOT}} -arch ${arch}"; export CPPFLAGS
191 LDFLAGS="${CPPFLAGS}"; export LDFLAGS
192 HOSTSYSTEM=`eval "echo \\$HostSystem_$arch"`
194 echo LDFLAGS="${LDFLAGS}"
195 echo CPPFLAGS="${CPPFLAGS}"
196 "${LyxSourceDir}/configure"\
197 --prefix="${LyxAppPrefix}" --with-version-suffix="-${LyXVersion}"\
198 ${QtInstallDir:+"--with-qt4-dir=${QtInstallDir}"} \
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}
207 echo Cannot build and install LyX for ${arch}.
213 # -------------------------
214 # Create universal binaries
215 # -------------------------
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}"
225 for file in ${FILE_LIST} ; do
227 for arch in ${ARCH_LIST} ; do
228 OBJ_LIST="${OBJ_LIST} Contents/MacOS/${file}-${arch}"
231 cd "${LyxAppPrefix}" &&
232 lipo -create ${OBJ_LIST} -o "${LyxAppPrefix}"/Contents/MacOS/${file}
234 if [ -d "${ASpellInstallDir}" ]; then
235 install_name_tool -change \
236 "${ASpellInstallDir}/lib/${ASpellDyLib}" "@executable_path/../${ASpellFramework}/${ASpellDyLib}" \
237 "${LyxAppPrefix}"/Contents/MacOS/${file}
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
253 for arch in ${ARCH_LIST} ; do
254 rm -f "${LyxAppPrefix}"/Contents/MacOS/*-${arch}
257 # ------------------------------
258 # Building distribution packages
259 # ------------------------------
261 test -n "${LyxAppZip}" && (
262 cd "${LyxAppPrefix}" && zip -r "${LyxAppZip}" .
265 DMGNAME="${LyxBase}-Uncompressed.dmg"
267 COMPRESSEDDMGNAME="${LyxBase}.dmg"
268 BACKGROUND="${LyxBase}.app/Contents/Resources/images/banner.png"
270 function set_bundle_display_options() {
272 tell application "Finder"
273 set f to POSIX file ("${1}" as string) as alias
276 tell container window
277 set toolbar visible to false
278 set statusbar visible to false
279 set current view to icon view
281 set the bounds to {20, 50, $2, $3}
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
301 test -n "${DMGLocation}" && (
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 }'`
310 rm -f ${COMPRESSEDDMGNAME}
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}"
316 # Mount the disk image
317 hdiutil attach ${DMGNAME}
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 ' ')
324 # copy in the application bundle
325 cp -Rp ${LyxBase}.app ${VOLUME}/${LyxName}.app
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
335 # Unmount the disk image
336 hdiutil detach ${DEV}
338 # Convert the disk image to read-only
339 hdiutil convert ${DMGNAME} -format UDBZ -o ${COMPRESSEDDMGNAME}