File: mkpkg.sh

package info (click to toggle)
allegro4.2 2:4.2.0-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 24,436 kB
  • ctags: 14,714
  • sloc: ansic: 126,425; asm: 17,011; cpp: 3,846; sh: 2,120; objc: 925; makefile: 715; python: 216; pascal: 179; perl: 73
file content (219 lines) | stat: -rwxr-xr-x 6,587 bytes parent folder | download | duplicates (10)
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
#!/bin/sh
#
#	Shell script to create a MacOS X package of the library.
#	The package will hold an end-user version of Allegro,
#	installing just the system wide library framework.
#	The created package is compatible with MacOS X 10.2 and newer.
#
#	Thanks to macosxhints.com for the hint!
#
#	Usage: mkpkg <allegro_dir>
#
#	Will create a package in the current directory; allegro_dir
#	must be a valid Allegro directory structure, holding the
#	previously compiled MacOS X dynamic library.
#

if [ ! $# -eq 1 ]; then
        echo "Usage: mkpkg.sh <allegro_dir>"
        exit 1
fi


echo "Checking version number"
	version=$(sed -n -e 's/shared_version = //p' $1/makefile.ver)
	major_minor_version=$(sed -n -e 's/shared_major_minor = //p' $1/makefile.ver)

libname=$1/lib/macosx/liballeg-${version}.dylib

if [ ! -f $libname ]; then
	echo "Cannot find valid dynamic library archive"
	exit 1
fi


if [ -d dstroot ]; then
	rm -fr dstroot
fi

basename=allegro-enduser-${version}


###########################
# Prepare package structure
###########################

echo "Setting up package structure"

framework=dstroot/Library/Frameworks/Allegro.framework
mkdir -p $framework
mkdir -p ${framework}/Versions/${version}/Resources
cp $libname ${framework}/Versions/${version}/allegro
(cd $framework && {
	(cd Versions; ln -s $version Current)
	ln -s Versions/Current/Resources Resources
	ln -s Versions/Current/allegro allegro
})

infofile=${framework}/Resources/Info.plist
cat > $infofile << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>CFBundleIdentifier</key>
        <string>com.allegro.lib</string>
        <key>CFBundleName</key>
        <string>allegro</string>
        <key>CFBundleShortVersionString</key>
        <string>Allegro ${version}</string>
</dict>
</plist>
EOF


##################
# Make the package
##################

echo "Creating package"

packagefile=${basename}.pkg
if [ -d $packagefile ]; then rm -fr $packagefile; fi
mkdir -p -m 0755 ${packagefile}/Contents/Resources

echo pmkrpkg1 > ${packagefile}/Contents/PkgInfo

infofile=${packagefile}/Contents/Info.plist
cat > $infofile << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleGetInfoString</key>
	<string>Allegro $version (EndUser)</string>
	<key>CFBundleName</key>
	<string>Allegro $version (EndUser)</string>
	<key>CFBundleShortVersionString</key>
	<string>${version}</string>
	<key>IFMajorVersion</key>
	<integer>0</integer>
	<key>IFMinorVersion</key>
	<integer>0</integer>
	<key>IFPkgFlagAllowBackRev</key>
	<false/>
	<key>IFPkgFlagAuthorizationAction</key>
	<string>RootAuthorization</string>
	<key>IFPkgFlagDefaultLocation</key>
	<string>/</string>
	<key>IFPkgFlagInstallFat</key>
	<false/>
	<key>IFPkgFlagIsRequired</key>
	<false/>
	<key>IFPkgFlagRelocatable</key>
	<false/>
	<key>IFPkgFlagRestartAction</key>
	<string>NoRestart</string>
	<key>IFPkgFlagRootVolumeOnly</key>
	<true/>
	<key>IFPkgFlagUpdateInstalledLanguages</key>
	<false/>
	<key>IFPkgFormatVersion</key>
	<real>0.10000000149011612</real>
</dict>
</plist>
EOF

descfile=${packagefile}/Contents/Resources/Description.plist
cat > $descfile << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>IFPkgDescriptionDeleteWarning</key>
	<string></string>
	<key>IFPkgDescriptionDescription</key>
	<string>Allegro $version end user package</string>
	<key>IFPkgDescriptionTitle</key>
	<string>Allegro $version (EndUser)</string>
	<key>IFPkgDescriptionVersion</key>
	<string>${version}</string>
</dict>
</plist>
EOF

gcc -o _makedoc $1/docs/src/makedoc/*.c
./_makedoc -rtf ${packagefile}/Contents/Resources/ReadMe.rtf $1/misc/pkgreadme._tx

bomfile=${packagefile}/Contents/Archive.bom
mkbom dstroot $bomfile

paxfile=${packagefile}/Contents/Archive.pax.gz
(cd dstroot && pax -x cpio -w -z . > ../${paxfile})

postflight=${packagefile}/Contents/Resources/postflight
cat > $postflight << EOF
#!/bin/sh
mkdir -p /usr/local/lib
if [ -f /usr/local/lib/liballeg-${version}.dylib ]; then
	rm -f /usr/local/lib/liballeg-${version}.dylib
fi
if [ -f /usr/local/lib/liballeg-${major_minor_version}.dylib ]; then
	rm -f /usr/local/lib/liballeg-${major_minor_version}.dylib
fi
if [ -f /usr/local/lib/liballeg-4.dylib ]; then
	rm -f /usr/local/lib/liballeg-4.dylib
fi
if [ -f /usr/local/lib/liballeg.dylib ]; then
	rm -f /usr/local/lib/liballeg.dylib
fi
ln -s /Library/Frameworks/Allegro.framework/Versions/${version}/Allegro /usr/local/lib/liballeg-${version}.dylib
ln -s /Library/Frameworks/Allegro.framework/Versions/${version}/Allegro /usr/local/lib/liballeg-${major_minor_version}.dylib
ln -s /Library/Frameworks/Allegro.framework/Versions/${version}/Allegro /usr/local/lib/liballeg-4.dylib
ln -s /Library/Frameworks/Allegro.framework/Versions/${version}/Allegro /usr/local/lib/liballeg.dylib

EOF
chmod a+x $postflight

sizesfile=${packagefile}/Contents/Resources/Archive.sizes
numfiles=`lsbom -s $bomfile | wc -l`
size=`du -k dstroot | tail -n 1 | awk '{ print $1;}'`
zippedsize=`du -k ${packagefile} | tail -n 1 | awk '{ print $1;}'`
bomsize=`ls -l $bomfile | awk '{ print $5;}'`
infosize=`ls -l $infofile | awk '{ print $5;}'`
((size += (bomsize + infosize)))
echo NumFiles $numfiles > $sizesfile
echo InstalledSize $size >> $sizesfile
echo CompressedSize $zippedsize >> $sizesfile


######################
# Build the disk image
######################

echo "Creating compressed disk image"
volume=allegro-enduser-${version}
diskimage=${volume}.dmg
tempimage=temp.dmg
mountpoint=temp_volume
rm -fr $diskimage $tempimage $mountpoint
hdiutil create $tempimage -megabytes 4 -layout NONE
drive=`hdid -nomount $tempimage`
newfs_hfs -v "$volume" $drive
mkdir $mountpoint
mount -t hfs $drive $mountpoint

cp -r $packagefile $mountpoint
./_makedoc -ascii ${mountpoint}/readme.txt $1/misc/pkgreadme._tx
./_makedoc -ascii ${mountpoint}/CHANGES $1/docs/src/changes._tx
./_makedoc -part -ascii ${mountpoint}/AUTHORS $1/docs/src/thanks._tx
./_makedoc -part -ascii ${mountpoint}/THANKS $1/docs/src/thanks._tx

umount $mountpoint
hdiutil eject $drive
hdiutil convert -format UDCO $tempimage -o $diskimage
echo "Compressing image"
gzip -f -9 $diskimage
rm -fr $tempimage ${packagefile} dstroot _makedoc $mountpoint

echo "Done!"