File: create_Mac_bundle.sh

package info (click to toggle)
spring 88.0%2Bdfsg1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 41,524 kB
  • sloc: cpp: 343,114; ansic: 38,414; python: 12,257; java: 12,203; awk: 5,748; sh: 1,204; xml: 997; perl: 405; objc: 192; makefile: 181; php: 134; sed: 2
file content (142 lines) | stat: -rwxr-xr-x 3,747 bytes parent folder | download
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
#!/bin/bash
set -e
. buildbot/slave/prepare.sh


DEST=${TMP_BASE}/inst
#FIXME: remove hardcoded /usr/local
INSTALLDIR=${DEST}/usr/local

echo "Installing into $DEST"

cd ${BUILDDIR}
make install DESTDIR=${DEST}

# The Spring.app bundle will have the following folder hierarchy:
# -> Contents
# ---> Info.plist
# ---> MacOS
# -----> executables
# ---> Resources
# -----> app icon
# ---> lib
# -----> Required libraries to run (from MacPorts)
# ---> share
# -----> game content, doc, etc.

BUNDLE_NAME=Spring_${VERSION}.app
BUNDLE_BASE=${TMP_PATH}/${BUNDLE_NAME}/Contents

echo "Creating ${BUNDLE_NAME}..."

MACPORTS_BASE=`which port | sed s/[/]bin[/]port//`
STRIP="strip -r -u"

mkdir -p ${BUNDLE_BASE}
cd ${BUNDLE_BASE}

# insert the version number in the Info.plist file
echo "-- installing header file"
cat ${SOURCEDIR}/installer/Mac/Info.plist | sed s/###VERSION###/${VERSION}/ > Info.plist

mkdir MacOS Resources

echo "-- installing executables"
mv ${INSTALLDIR}/bin/* MacOS/

echo "-- installing application icon"
cp ${SOURCEDIR}/installer/Mac/spring.icns Resources/

echo "-- installing spring libs"
mv ${INSTALLDIR}/lib .

echo "-- installing game content"
mv ${INSTALLDIR}/share .

# move spring libraries to the executable folder (avoids spring relative path issues)
mv lib/libunitsync.dylib MacOS/

# not needed (yet) for the server lib, uncomment if necessary
#mv lib/libspringserver.dylib MacOS/

echo "-- installing 3rd-party libraries (provided by MacPorts)"
for executable in `ls MacOS`
do
	# for each MacPorts's dylib required by the executable
	for dylib in `otool -L MacOS/${executable} | grep ${MACPORTS_BASE} | egrep -o lib.*dylib`
	do
		# dylib =~ "lib/lib*.dylib"

		echo "---- installing ${dylib}"
		cp ${MACPORTS_BASE}/${dylib} lib

		# take write permissions on the bundled lib
		chmod u+w ${dylib}

		# change the bundled lib's id to relative pathing mode (not necessary but cleaner)
		install_name_tool -id @loader_path/../${dylib} ${dylib}

		# point the executable to the bundled lib in relative pathing mode
		install_name_tool -change ${MACPORTS_BASE}/${dylib} @loader_path/../${dylib} MacOS/${executable}

		# the bundled lib is autonomous => it can be stripped
		${STRIP} ${dylib}
	done

	# finally, strip the executable
	${STRIP} MacOS/${executable}
done

# continue with recursive dependencies
end=0
while [ $end -eq 0 ]
do
	# don't loop unless necessary
	end=1

	# for each dylib already bundled
	for dylib in `ls lib`
	do
		# check if all dependent MacPorts libs are also bundled
		for requiredlib in `otool -L lib/${dylib} | grep ${MACPORTS_BASE} | egrep -o lib.*dylib`
		do
			#echo "MacPorts lib required: ${requiredlib}"
			if [ ! -f ${requiredlib} ]
			then
				# loop
				end=0

				echo "---- installing ${requiredlib}"
				cp ${MACPORTS_BASE}/${requiredlib} lib

				# take write permissions on the bundled lib
				chmod u+w ${requiredlib}

				# change the bundled lib's id to relative pathing mode (not necessary but cleaner)
				install_name_tool -id @loader_path/../${requiredlib} ${requiredlib}

				# the bundled lib is autonomous => it can be stripped
				${STRIP} ${requiredlib}
			fi

			# point the parent lib to the bundled lib in relative pathing mode
			install_name_tool -change ${MACPORTS_BASE}/${requiredlib} @loader_path/../${requiredlib} lib/${dylib}
		done
	done
done

# here, the bundle should be ready, a little compression and voila

ARCHIVE_NAME=Spring_${VERSION}-MacOSX-10.6-SnowLeopard.zip
echo "-- creating ${TMP_PATH}/${ARCHIVE_NAME}"
cd ${TMP_PATH}
zip -r9 ${ARCHIVE_NAME} ${BUNDLE_NAME}

#remove temp files
rm -rf ${TMP_PATH}/${BUNDLE_NAME}

#create symbolic link
cd ${TMP_PATH}/..
ln -sfv ${REV}/${ARCHIVE_NAME} Spring_testing-MacOSX-10.6-SnowLeopard.zip
echo "-- done"