File: osx-package.sh

package info (click to toggle)
webissues 1.1.5-10
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 17,108 kB
  • sloc: ansic: 97,819; cpp: 33,773; javascript: 1,171; xml: 465; sh: 378; makefile: 17
file content (319 lines) | stat: -rwxr-xr-x 7,459 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#!/bin/sh
# Copyright 2008 AZEVEDO Filipe

#### app name ###################################################

APP_NAME=$1
QMAKE=$2

if [ ! -f "$QMAKE" ] ; then
	QMAKE=qmake
fi

### get system configuration ########################################

# as long as we can find qmake, we don't need QTDIR
QT_LIBS_PATH=`$QMAKE -query QT_INSTALL_LIBS`
QT_PLUGINS_PATH=`$QMAKE -query QT_INSTALL_PLUGINS`

if [ ! -d $QT_LIBS_PATH/QtCore.framework ] ; then
	echo "ERROR: cannot find the Qt frameworks. Make sure Qt is installed"
	echo "and qmake is in your environment path."
	exit
fi

### get required user input #########################################
if [ -z "$APP_NAME" ] ; then
	echo
	echo "This script prepares a Qt application bundle for deployment. It will"
	echo "copy over the required Qt frameworks and sets the installation"
	echo "identifications. Please see the \"Deploying an Application on Qt/Mac\""
	echo "page in the Qt documentation for more information."
	echo
	echo "This script assumes you have already built the application bundle."
	echo
	echo -n "What is the name of the application? "
	read userinput
	APP_NAME=$userinput
fi

APP_BASENAME=$(basename "$APP_NAME")
BUNDLE="$APP_NAME.app"
APP_BIN="$BUNDLE/Contents/MacOS/$APP_BASENAME"
APP_PLUGINS_PATH="$BUNDLE/Contents/plugins"
APP_RESOURCES_PATH="$BUNDLE/Contents/Resources"
APP_QT_PLUGINS_PATH="$APP_RESOURCES_PATH/qt/plugins"
APP_FRAMEWORKS_PATH="$BUNDLE/Contents/Frameworks"

if [ ! -d "${BUNDLE}" ] ; then
	echo "ERROR: cannot find application bundle \"$BUNDLE\" in current directory"
	exit
fi

if [ ! -x "${APP_BIN}" ] ; then
	echo "ERROR: cannot find application \"$APP_BIN\" in bundle. Did you forget to run make?"
	exit
fi

echo "application: ${APP_NAME}"
echo "bundle:      ${BUNDLE}"
echo

### functions ######################################################
copyPlugins()
{
	path="$2/$1"
	if [ ! -d "$QT_PLUGINS_PATH/${1}" ] ; then
		echo "Skipping $1 plugins, folder does not exists"
	else
		echo "Copying $1 plugins..."
		if [ ! -d "${path}" ] ; then
			mkdir -p "${path}"
		fi
		cp -R "$QT_PLUGINS_PATH/${1}" "${2}"
	fi
}

copyAllPlugins()
{
	copyPlugins "accessible" "$APP_QT_PLUGINS_PATH"
	copyPlugins "codecs" "$APP_QT_PLUGINS_PATH"
	copyPlugins "designer" "$APP_QT_PLUGINS_PATH"
	copyPlugins "graphicssystems" "$APP_QT_PLUGINS_PATH"
	copyPlugins "iconengines" "$APP_QT_PLUGINS_PATH"
	copyPlugins "imageformats" "$APP_QT_PLUGINS_PATH"
	copyPlugins "inputmethods" "$APP_QT_PLUGINS_PATH"
	copyPlugins "phonon_backend" "$APP_QT_PLUGINS_PATH"
	copyPlugins "script" "$APP_QT_PLUGINS_PATH"
	copyPlugins "sqldrivers" "$APP_QT_PLUGINS_PATH"
}

changeBinaryPaths()
{
	echo "Changing framework paths for `basename "${1}"`..."
	for path in $2 ; do
		name=$(basename "$path")
		echo -n " $name"
		install_name_tool -change $path @executable_path/../Frameworks/$name "${1}"
	done
}

getSourceFramework()
{
	framework="$QT_LIBS_PATH/$1"
		
	# check for non framework, like libQtCLuScene.4.dylib
	dylib=`expr "${framework}" : '.*\(dylib\)$'`
	if [ "x${dylib}" = "x" ] ; then
		framework="$QT_LIBS_PATH/$1.framework/Versions/4/$1"
	fi
	
	# is symlink ?
	if [ -h "${framework}" ] ; then
		symlink=`readlink "${framework}"`
		if [ $symlink[0] = '/' ] ; then
			$framework=$symlink
		else
			framework="$QT_LIBS_PATH/$symlink"
		fi
	fi
	
	echo "$framework"
}

getTargetFramework()
{
	echo "$APP_FRAMEWORKS_PATH/$1"
}

getBinaryDependencies()
{
	tmp=""
	for n in `otool -LX "${1}" | grep 'Qt\|phonon'` ; do
		path=`echo $n | grep 'Qt\|phonon'`
		if [ $path ] ; then
			tmp="$tmp $path"
		fi
	done
	
	echo $tmp
}

setId()
{
	echo "Updating $1 id..."
	install_name_tool -id @executable_path/../Frameworks/"${1}" "${2}"
}

relinkPlugins()
{
	tmp_plugins=`find "${1}" | egrep ".dylib"`
	
	old_ifs="$IFS"
	IFS=$'\n'
	count=0
	for plugin in $tmp_plugins ; do
		plugins[$count]="${plugin}"
		((count++))
	done
	IFS=$old_ifs
	
	count=${#plugins[@]}
	for ((i=0;i<$count;i++));
	do
		plugin=${plugins[${i}]}
		relinkBinary "$plugin"
		echo
	done
}

relinkBinary()
{
	echo "Striping `basename \"${1}\"` binary..."
	# strip libs (-x is max allowable for shared libs)
	#strip -x "${1}"
	
	# set id in target
	if [ ! "x${2}" = "x" ] ; then
		setId "${2}" "${1}"
	fi
	
	# get dependencies
	frameworks_path=`getBinaryDependencies "$1"`
	
	# update framework/library paths
	changeBinaryPaths "$1" "$frameworks_path"
	
	# copy dependencies frameworks/libraries
	for framework_path in $frameworks_path ; do
		# get framework
		framework=$(basename "$framework_path")
		
		# get filenames
		source=`getSourceFramework "$framework"`
		target=`getTargetFramework "$framework"`
		
		# copy file if needed
		if [ -e "${source}" ] ; then
			if [ ! -e "${target}" ] ; then
				#echo "Copying & striping `basename \"${source}\"` framework/library..."
				path=`dirname "${target}"`
				mkdir -p "${path}"
				cp -f "${source}" "${target}"

				# Copy required Cocoa nib folder for cocoa qt builds
				if [ "x$framework" == "xQtGui" ]; then
				    source_nib="`dirname \"${source}\"`/../../Resources/qt_menu.nib"
				    target_nib="$APP_RESOURCES_PATH"

				    if [ -d "$source_nib" ]; then
				      cp -Rf "$source_nib" "$target_nib"
				    fi
				fi
				
				echo
				relinkBinary "${target}" "${framework}"
			fi
		fi
	done
}

createTmpDmg()
{
	echo "Creating temporary dmg..."
	hdiutil create -megabytes 200 tmp.dmg -layout NONE -fs HFS+ -volname "$APP_BASENAME" -ov
	tmp=`hdid tmp.dmg`
	disk=`echo $tmp | cut -f 1 -d\ `
}

prepareDmg()
{
	# Copy qt files
	echo "Copying qt files"
	cp "qt.conf" "$APP_RESOURCES_PATH"
	
	#if [ ! -d "$APP_RESOURCES_PATH/qt/doc/qch" ] ; then
	#	mkdir -p "$APP_RESOURCES_PATH/qt/doc/qch"
	#fi
	#cp -f "${QT_LIBS_PATH}/../doc/qch/"*.qch "$APP_RESOURCES_PATH/qt/doc/qch"
	
	if [ ! -d "$APP_RESOURCES_PATH/qt/translations" ] ; then
		mkdir -p "$APP_RESOURCES_PATH/qt/translations"
	fi
	cp -f "$QT_LIBS_PATH/../translations/"qt_*.qm "$APP_RESOURCES_PATH/qt/translations"
	rm -f "$APP_RESOURCES_PATH/qt/translations/"qt_help*.qm
	
	# Copy original bundle
	echo "Copying $APP_BASENAME..."
	cp -fR "$BUNDLE" "/Volumes/$APP_BASENAME"
	
	# Copy standard files
	#echo "Copying standard files..."
	#cp -f ../../dev-readme "/Volumes/$APP_BASENAME"
	#cp -f ../../GPL-2 "/Volumes/$APP_BASENAME"
	#cp -f ../../GPL-3 "/Volumes/$APP_BASENAME"
	#cp -f ../../LGPL-3 "/Volumes/$APP_BASENAME"
	#cp -f ../../readme.txt "/Volumes/$APP_BASENAME"
	
	# cleanup
	echo "Cleaning up..."
	curPath=$PWD
	target="$BUNDLE/Contents"
	cd "$target"
	find . | egrep "CVS" | xargs rm -rf
	find . | egrep ".svn" | xargs rm -rf
	cd "/Volumes/$APP_BASENAME"
	find . | egrep "CVS" | xargs rm -rf
	find . | egrep ".svn" | xargs rm -rf
	cd "$curPath"
}

createReleaseDmg()
{
	echo "Creating release dmg..."
	hdiutil eject "$disk"
	if [ -f "../${APP_BASENAME}_VERSION-svnRELEASE.dmg" ] ; then
		rm -f "../${APP_BASENAME}_VERSION-svnRELEASE.dmg"
	fi
	hdiutil convert -format UDZO tmp.dmg -o "../${APP_BASENAME}_VERSION-svnRELEASE.dmg"
	rm tmp.dmg
}

# make install
curPath=$PWD
cd ../..
make install
cd $curPath

# Let go...
relinkBinary "$APP_BIN"
echo

#copyAllPlugins
#echo

echo "Cleaning debug libraries..."
cleanCurPath=$PWD
cleanTarget="$BUNDLE/Contents"
cd "$cleanTarget"
find . | egrep "*_debug.dylib" | xargs rm -rf
cd "$cleanCurPath"
echo "-n Finished."
echo

#relinkPlugins "$APP_QT_PLUGINS_PATH"
#echo

#relinkPlugins "$APP_PLUGINS_PATH"
#echo

createTmpDmg
echo

prepareDmg
echo

createReleaseDmg
echo

echo "Done"