-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
mac_build_release_dmg.sh
executable file
·141 lines (104 loc) · 5.06 KB
/
mac_build_release_dmg.sh
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
#!/bin/bash
# Dave Gnukem
# https://github.com/davidjoffe/dave_gnukem
# dj2016-10 simple quick n dirty script to try automatically build a
# release DMG etc. for Mac OS X
# dj2023-11 updating to use create-dmg for a more polished result and other improvements
# Also tries to recursively resolve .dylib dependencies
set -e
set -u
# Check for version number argument
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <version_number>"
exit 1
fi
APPNAME="Dave Gnukem"
VERSION=$1
#CODESIGNID=""
OUTFOLDER=MacReleases/DaveGnukem_$VERSION
#TMPDMG=MacReleases/tmp_$VERSION.dmg
FINALDMG=MacReleases/DaveGnukem_$VERSION.dmg
APPFOLDER="${APPNAME}.app"
##########
# Actually build the Dave Gnukem binary
make clean
make -j4
# hm why not statically link into one binary? no dylibs .. would simplify the packaging slightly ..
# Code-sign davegnukem binary itself
#echo codesign --timestamp -v -f --sign "TSHWANEDJE HUMAN LANGUAGE TECHNOLOGY CC" davegnukem
##########
# Create temporary output folder to store release files/folders
rm -rf MacReleases
mkdir -p "${OUTFOLDER}/${APPFOLDER}"
mkdir -p "${OUTFOLDER}/${APPFOLDER}/Contents"
mkdir -p "${OUTFOLDER}/${APPFOLDER}/Contents/MacOS"
mkdir -p "${OUTFOLDER}/${APPFOLDER}/Contents/Resources"
# Generate / copy Info.plist file
cp -f "Info.plist" "${OUTFOLDER}/${APPFOLDER}/Contents/"
# Generate PkgInfo file
echo -n 'APPL????' > "${OUTFOLDER}/${APPFOLDER}/Contents/PkgInfo"
APP_BINARY="${OUTFOLDER}/${APPFOLDER}/Contents/MacOS/davegnukem"
##########
# COPY REQUIRED APPLICATION FILES/FOLDERS
cp -r data "${OUTFOLDER}/${APPFOLDER}/Contents/"
cp davegnukem "${OUTFOLDER}/${APPFOLDER}/Contents/MacOS"
cp "./data/icon/Dave Gnukem.icns" "${OUTFOLDER}/${APPFOLDER}/Contents/Resources"
cp "./data/icon/Dave Gnukem.icns" "${OUTFOLDER}/${APPFOLDER}/Contents/Resources/appicon.icns"
cp COPYING "${OUTFOLDER}/${APPFOLDER}/Contents/Resources"
cp README.md "${OUTFOLDER}/${APPFOLDER}/Contents/Resources"
cp MIT-LICENSE.txt "${OUTFOLDER}/${APPFOLDER}/Contents/Resources"
cp History.txt "${OUTFOLDER}/${APPFOLDER}/Contents/Resources"
# Throw in the source as well I guess? May encourage someone to play around with it, and it isn't big
#cp Makefile "${OUTFOLDER}/${APPFOLDER}/Contents/Resources"
#cp -r src "${OUTFOLDER}/${APPFOLDER}/Contents/Resources"
install_name_tool -change /opt/local/lib/libsdl2.dylib @executable_path/libsdl2.dylib "$APP_BINARY"
install_name_tool -change /opt/local/lib/libsdl2_mixer.dylib @executable_path/libsdl2_mixer.dylib "$APP_BINARY"
# Function to copy and fix dylib dependencies
copy_and_fix_dylibs() {
local dylib=$1
local dest_dir=$2
# Copy the dylib to the destination directory
cp "$dylib" "$dest_dir"
# Get the base name of the dylib
local dylib_name=$(basename "$dylib")
# Get all dependencies of the dylib
local dependencies=$(otool -L "$dylib" | awk 'NR>1 {print $1}' | grep -v ':' | grep '/opt/local/lib')
for dep in $dependencies; do
local dep_name=$(basename "$dep")
# Change the install name for the dependency within the dylib
install_name_tool -change "$dep" "@executable_path/$dep_name" "$dest_dir/$dylib_name"
# Check if the dependency is already processed
if [ ! -f "$dest_dir/$dep_name" ]; then
# Recursively process the dependency
copy_and_fix_dylibs "$dep" "$dest_dir"
fi
done
}
#cp /opt/local/lib/libsdl2.dylib "${OUTFOLDER}/${APPFOLDER}/Contents/MacOS/"
#cp /opt/local/lib/libsdl2_mixer.dylib "${OUTFOLDER}/${APPFOLDER}/Contents/MacOS/"
# Process SDL2 and SDL2_mixer dylibs
# Directory where the dylibs will be copied to
FRAMEWORKS_DIR="${OUTFOLDER}/${APPFOLDER}/Contents/MacOS"
#mkdir -p "$FRAMEWORKS_DIR"
copy_and_fix_dylibs "/opt/local/lib/libsdl2.dylib" "${FRAMEWORKS_DIR}"
copy_and_fix_dylibs "/opt/local/lib/libsdl2_mixer.dylib" "${FRAMEWORKS_DIR}"
# Make sure all files that will go into the DMG are world-readable (otherwise if one user installs the app, and another runs it, some things might not work properly as the other user can't read those files if they're 'user-readable' only)
find "${OUTFOLDER}" -print0 | xargs -0 chmod a+r
# Not sure if this will be effective in DMG? But idea here is want levels etc. editable if someone copies the folder out to elsewhere .. so make data folder writable
find "${OUTFOLDER}/${APPFOLDER}/Contents/data" -print0 | xargs -0 chmod u+w
##########
# Now create DMG; this is a two-step process
# Sign the .app itself
#echo codesign --timestamp -v -f --sign "TSHWANEDJE HUMAN LANGUAGE TECHNOLOGY CC" --deep "${OUTFOLDER}/${APPFOLDER}"
# Update dmg creation to use create-dmg for a more polished result
create-dmg --volname "${APPNAME} $VERSION" "${FINALDMG}" "${OUTFOLDER}"
# Sign the .dmg itself
#echo codesign --timestamp -v -f --sign "TSHWANEDJE HUMAN LANGUAGE TECHNOLOGY CC" --deep "${FINALDMG}"
# Remove these first if there's some lying around from a previous build attempt
#rm -f ${TMPDMG}
#rm -f ${OUTFOLDER}.dmg
#hdiutil create -srcfolder ${OUTFOLDER} -ov ${TMPDMG} -volname "Dave Gnukem"
#hdiutil convert ${TMPDMG} -format UDBZ -o ${FINALDMG}
##########
# Clean up temp files a bit
#rm -f ${TMPDMG}