File: mkappbundle.sh

package info (click to toggle)
flamp 2.2.14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,204 kB
  • sloc: cpp: 35,035; ansic: 5,806; sh: 4,264; makefile: 243
file content (126 lines) | stat: -rwxr-xr-x 3,074 bytes parent folder | download | duplicates (2)
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
#!/bin/sh

### Script to create the .app structure for osx
### 20180201  David Freese W1HKJ

if [ $# -ne 2 ]; then
	echo "Syntax: $0 data-dir build-dir" >&2
	exit 1
fi

upcase1()
{
	sed 'h; s/\(^.\).*/\1/; y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/; G; s/\n.//'
}

function copy_libs()
{
	list="$1"
	while test "x$list" != "x"; do
	change="$list"
	list=""

	for obj in $change; do
		for lib in `otool -L $obj | \
			sed -n 's!^.*[[:space:]]\([^[:space:]]*\.dylib\).*$!\1!p' | \
				grep -Ev '^/(usr/lib|System)'`; do
		libfn="`basename $lib`"
		if ! test -f "Frameworks/$libfn"; then
			cp "$lib" "Frameworks/$libfn"
			install_name_tool -id "@executable_path/../Frameworks/$libfn" "Frameworks/$libfn"
			list="$list Frameworks/$libfn"
		fi
		install_name_tool -change "$lib" "@executable_path/../Frameworks/$libfn" "$obj"
		done
	done
	done
}

function bundle()
{
	appname="${binary}-${appversion}.app"

	cd "$build"

	echo "creating ${build}/$bundle_dir/$appname"

	$mkinstalldirs "$bundle_dir/$appname/Contents/MacOS" "$bundle_dir/$appname/Contents/Resources"
	cd "$bundle_dir"

	$INSTALL_PROGRAM "${build}/$binary" "$appname/Contents/MacOS"
	test "x$NOSTRIP" = "x" && ${STRIP:-strip} -S "$appname/Contents/MacOS/$binary"
	$INSTALL_DATA "$icon" "$appname/Contents/Resources"

	echo "APPL${signature}" > "$appname/Contents/PkgInfo"
	sed -e "s!%%IDENTIFIER%%!${identifier}!g; s!%%NAME%%!${name}!g;\
		s!%%SIGNATURE%%!${signature}!g; s!%%BINARY%%!${binary}!g;\
		s!%%VERSION%%!${version}!g; s!%%ICON%%!${icon##*/}!g;" < "$plist" > "$appname/Contents/Info.plist"

	if grep '%%[A-Z]*%%' "$appname/Contents/Info.plist"; then
		echo "E: unsubstituted variables in $appname/Contents/Info.plist" >&2
	exit 1
	fi

	$mkinstalldirs "$appname/Contents/Frameworks"
	cd "$appname/Contents"

	copy_libs "MacOS/$binary"

}

#=======================================================================

if [ -z "$PACKAGE_TARNAME" ]; then
	echo "E: \$PACKAGE_TARNAME undefined"
	exit 1
fi

PWD=`pwd`
data="${PWD}/$1"
build="${PWD}/$2"
bundle_dir="$APPBUNDLE"

# more sanity checks
for d in "$data" "$build"; do
	test -d "$d" && continue
	echo "E: ${d}: not a directory" >&2
	exit 1
done
if ! test -w "$build"; then
	echo "E: ${build} is not writeable" >&2
	exit 1
fi

plist="${data}/mac/Info.plist.in"
flamp_icon="${data}/mac/flamp.icns"
for f in "$plist" "$flamp_icon"; do
	test -r "$f" && continue
	echo "E: ${f}: not readable" >&2
	exit 1
done

set -e

identifier="com.w1hkj.$PACKAGE_TARNAME"
name=$(echo "$PACKAGE_TARNAME" | upcase1)

# we'll use the first four consonants as the signature

signature="$(echo $PACKAGE_TARNAME | sed 's/[aeiouAEIOU]//g; s/\(^....\).*/\1/')"

signature="$PACKAGE_TARNAME"
binary="$PACKAGE_TARNAME"
icon="$flamp_icon"
version="${flamp_VERSION_MAJOR}.${flamp_VERSION_MINOR}${flamp_VERSION_PATCH}"
appversion="$flamp_VERSION"

bundle

cd "$build"

echo "creating disk image"

echo "    source: " $bundle_dir
echo "    target: " ${APPBUNDLE}.dmg

hdiutil create -ov -srcfolder "$bundle_dir" -format UDZO -tgtimagekey zlib-level=9 "${APPBUNDLE}.dmg"