Subversion Repositories Games.Rick Dangerous

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
11 pmbaty 1
#!/bin/sh
2
 
3
MY_PATH="$(dirname "$0")"
4
 
5
APP_NAME="Rick Dangerous"
6
APP_VERSION="1.4"
7
APP_COPYRIGHT="© 2016 Pierre-Marie Baty
8
© 2002 BigOrno
9
© 1989 CORE Design
10
Artwork by Simon Phipps"
11
BUNDLE_ID="com.pmbaty.rick.rickdangerous"
12
ICON_FILE="icon.png"
13
 
14
# compiler and linker flags to use
15
CPPFLAGS="-Isrc -Ilib/SDL2/include"
16
LDFLAGS=""
17
 
18
cd "${MY_PATH}" || exit 1
19
 
20
# cleanup
21
rm -rf .build
22
if [ "$(uname)" = "Darwin" ]; then
23
        # macOS
24
        rm -rf "${APP_NAME}.app"
25
        ARCHS="x86_64 arm64"
26
        CPPFLAGS="-mmacosx-version-min=10.11 ${CPPFLAGS}"
27
        LDFLAGS="-mmacosx-version-min=10.11 -framework Cocoa -framework OpenGL -Flib/SDL2/macOS -framework SDL2 -rpath @loader_path/../Frameworks ${LDFLAGS}"
28
else
29
        # Linux/BSD/whatever
30
        rm -rf "${APP_NAME}.$(uname)-$(uname -m)"
31
        ARCHS="$(uname -m)"
32
        CPPFLAGS="${CPPFLAGS}"
33
        LDFLAGS="-L/usr/local/lib -lSDL2 -lpthread -lm ${LDFLAGS}"
34
        test "$(uname)" = "FreeBSD" && LDFLAGS="-linotify -lusbhid ${LDFLAGS}"
35
fi
36
 
37
# read the source files list from the Visual Studio project file if it exists, else list all the .c files from "lib" and "src"
38
if [ -f "${APP_NAME}.vcxproj" ]; then
39
        SRCLIST="$(grep "<ClCompile " "${APP_NAME}.vcxproj"|awk -F\" '{print $2}'|tr '\\' '/')"
40
else
41
        SRCLIST="$(find lib -name '*.c') $(find src -name '*.c')"
42
fi
43
 
44
# for each specified architecture...
45
THIN_OUTPUTS=
46
for ARCH in ${ARCHS}; do
47
        rm -rf ".build/${ARCH}"
48
        mkdir -p ".build/${ARCH}" || exit 1
49
        OPTIONAL_ARCH_FLAG="$(test "${ARCH}" = "${ARCHS}" || echo "-arch ${ARCH}")"
50
 
51
        # compile source files
52
        echo "Compiling for ${ARCH}..."
53
        for SRCFILE in ${SRCLIST}; do
54
                echo "${SRCFILE}"
55
                cc -o ".build/${ARCH}/$(basename "${SRCFILE}").o" -c "${SRCFILE}" ${OPTIONAL_ARCH_FLAG} ${CPPFLAGS} || exit 1
56
        done
57
 
58
        # link them together
59
        echo "Linking for ${ARCH}..."
60
        cc -o ".build/${ARCH}/a.out" ".build/${ARCH}/"*".o" ${OPTIONAL_ARCH_FLAG} ${LDFLAGS} || exit 1
61
        THIN_OUTPUTS="${THIN_OUTPUTS} .build/${ARCH}/a.out"
62
done
63
 
64
if [ "$(uname)" = "Darwin" ]; then
65
        # create the macOS app layout
66
        echo "Creating macOS app layout..."
67
        mkdir "${APP_NAME}.app"                     || exit 1
68
        mkdir "${APP_NAME}.app/Contents"            || exit 1
69
        mkdir "${APP_NAME}.app/Contents/MacOS"      || exit 1
70
        mkdir "${APP_NAME}.app/Contents/Frameworks" || exit 1
71
        mkdir "${APP_NAME}.app/Contents/Resources"  || exit 1
72
 
73
        # generate and deploy fat Mach-O executable
74
        echo "Generating fat executable..."
75
        lipo ${THIN_OUTPUTS} -create -output "${APP_NAME}.app/Contents/MacOS/${APP_NAME}" || exit 1
76
 
77
        # deploy the SDL2 framework
78
        echo "Deploying SDL2 framework..."
79
        mkdir "${APP_NAME}.app/Contents/Frameworks/SDL2.framework"                                                     || exit 1
80
        mkdir "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/Versions"                                            || exit 1
81
        mkdir "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/Versions/A"                                          || exit 1
82
        cp lib/SDL2/macOS/SDL2.framework/SDL2 "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/Versions/A/SDL2"     || exit 1
83
        ln -s Versions/A/SDL2 "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/SDL2"                                || exit 1
84
        cp -LR lib/SDL2/macOS/SDL2.framework/Resources "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/Versions/A" || exit 1
85
        ln -s Versions/A/Resources "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/Resources"                      || exit 1
86
 
87
        # deploy the game data
88
        echo "Deploying game data..."
89
        cp -LR sounds "${APP_NAME}.app/Contents/Resources" || exit 1
90
 
91
        # generate and deploy the app icon
92
        echo "Generating app icon..."
93
        mkdir ".build/${APP_NAME}.iconset" || exit 1
94
        sips -z 16 16     "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_16x16.png"      > /dev/null
95
        sips -z 32 32     "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_16x16@2x.png"   > /dev/null
96
        sips -z 32 32     "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_32x32.png"      > /dev/null
97
        sips -z 64 64     "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_32x32@2x.png"   > /dev/null
98
        sips -z 128 128   "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_128x128.png"    > /dev/null
99
        sips -z 256 256   "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_128x128@2x.png" > /dev/null
100
        sips -z 256 256   "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_256x256.png"    > /dev/null
101
        sips -z 512 512   "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_256x256@2x.png" > /dev/null
102
        sips -z 512 512   "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_512x512.png"    > /dev/null
103
        sips -z 1024 1024 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_512x512@2x.png" > /dev/null
104
        iconutil -c icns ".build/${APP_NAME}.iconset" -o "${APP_NAME}.app/Contents/Resources/AppIcon.icns" || exit 1
105
 
106
        # generate the PkgInfo file
107
        echo -n "APPL???" > "${APP_NAME}.app/Contents/PkgInfo" || exit 1
108
 
109
        # generate the Info.plist
110
        (
111
                echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
112
                echo "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
113
                echo "<plist version=\"1.0\">"
114
                echo "<dict>"
115
                echo "  <key>CFBundleDevelopmentRegion</key>"
116
                echo "  <string>en</string>"
117
                echo "  <key>CFBundleExecutable</key>"
118
                echo "  <string>${APP_NAME}</string>"
119
                echo "  <key>CFBundleIconFile</key>"
120
                echo "  <string>AppIcon.icns</string>"
121
                echo "  <key>CFBundleIdentifier</key>"
122
                echo "  <string>${BUNDLE_ID}</string>"
123
                echo "  <key>CFBundleInfoDictionaryVersion</key>"
124
                echo "  <string>6.0</string>"
125
                echo "  <key>CFBundleName</key>"
126
                echo "  <string>${APP_NAME}</string>"
127
                echo "  <key>CFBundleVersion</key>"
128
                echo "  <string>${APP_VERSION}</string>"
129
                echo "  <key>NSHumanReadableCopyright</key>"
130
                echo "  <string>${APP_COPYRIGHT}</string>"
131
                echo "  <key>CFBundlePackageType</key>"
132
                echo "  <string>APPL</string>"
133
                echo "  <key>CFBundleSignature</key>"
134
                echo "  <string>????</string>"
135
                echo "</dict>"
136
                echo "</plist>"
137
        ) > "${APP_NAME}.app/Contents/Info.plist" || exit 1
138
 
139
        echo "Output app bundle: ${APP_NAME}.app"
140
else
141
        # Linux/BSD/whatever: simply retrieve the compiled executable
142
        cp ".build/${ARCH}/a.out" "${APP_NAME}.$(uname)-$(uname -m)"
143
 
144
        echo "Output executable: ${APP_NAME}.$(uname)-$(uname -m)"
145
fi
146
 
147
# finished
148
echo "${APP_NAME} was built successfully"
149
exit 0
150
 
151
 
152
 
153
 
154
 
155
 
156
 
157
 
158
 
159
 
160
 
161
 
162
rm -rf "${APP_NAME}.app"
163
 
164
# create app bundle
165
echo "Creating macOS app layout..."
166
mkdir "${APP_NAME}.app"                     || exit 1
167
mkdir "${APP_NAME}.app/Contents"            || exit 1
168
mkdir "${APP_NAME}.app/Contents/MacOS"      || exit 1
169
mkdir "${APP_NAME}.app/Contents/Frameworks" || exit 1
170
mkdir "${APP_NAME}.app/Contents/Resources"  || exit 1
171
 
172
# target El Capitan
173
for ARCH in x86_64 arm64; do
174
        cc -mmacosx-version-min=10.11 -arch "${ARCH}" *.c osx-sdlmain.m -I3rdparty/SDL2/include -framework Foundation -framework Cocoa -F3rdparty/SDL2/macOS -framework SDL2 -rpath "@loader_path/../Frameworks" -o "${APP_NAME}.mac-${ARCH}"
175
        if [ ! "_$?" = "_0" ]; then
176
                rm -rf "${APP_NAME}.app"
177
                exit 1
178
        fi
179
done
180
lipo "${APP_NAME}.mac-x86_64" "${APP_NAME}.mac-arm64" -create -output "${APP_NAME}.app/Contents/MacOS/${APP_NAME}"
181
if [ ! "_$?" = "_0" ]; then
182
        rm "${APP_NAME}.mac-x86_64" "${APP_NAME}.mac-arm64"
183
        rm -rf "${APP_NAME}.app"
184
        exit 1
185
fi
186
rm "${APP_NAME}.mac-x86_64" "${APP_NAME}.mac-arm64"
187
 
188
# deploy the SDL2 framework
189
mkdir "${APP_NAME}.app/Contents/Frameworks/SDL2.framework" || exit 1
190
mkdir "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/Versions" || exit 1
191
mkdir "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/Versions/A" || exit 1
192
cp 3rdparty/SDL2/macOS/SDL2.framework/SDL2 "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/Versions/A/SDL2" || exit 1
193
ln -s Versions/A/SDL2 "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/SDL2" || exit 1
194
cp -LR 3rdparty/SDL2/macOS/SDL2.framework/Resources "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/Versions/A" || exit 1
195
ln -s Versions/A/Resources "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/Resources" || exit 1
196
 
197
# deploy icon
198
mkdir "__${APP_NAME}.iconset"
199
sips -z 16 16     "${ICON_FILE}" --out "__${APP_NAME}.iconset/icon_16x16.png"      > /dev/null
200
sips -z 32 32     "${ICON_FILE}" --out "__${APP_NAME}.iconset/icon_16x16@2x.png"   > /dev/null
201
sips -z 32 32     "${ICON_FILE}" --out "__${APP_NAME}.iconset/icon_32x32.png"      > /dev/null
202
sips -z 64 64     "${ICON_FILE}" --out "__${APP_NAME}.iconset/icon_32x32@2x.png"   > /dev/null
203
sips -z 128 128   "${ICON_FILE}" --out "__${APP_NAME}.iconset/icon_128x128.png"    > /dev/null
204
sips -z 256 256   "${ICON_FILE}" --out "__${APP_NAME}.iconset/icon_128x128@2x.png" > /dev/null
205
sips -z 256 256   "${ICON_FILE}" --out "__${APP_NAME}.iconset/icon_256x256.png"    > /dev/null
206
sips -z 512 512   "${ICON_FILE}" --out "__${APP_NAME}.iconset/icon_256x256@2x.png" > /dev/null
207
sips -z 512 512   "${ICON_FILE}" --out "__${APP_NAME}.iconset/icon_512x512.png"    > /dev/null
208
sips -z 1024 1024 "${ICON_FILE}" --out "__${APP_NAME}.iconset/icon_512x512@2x.png" > /dev/null
209
iconutil -c icns "__${APP_NAME}.iconset"
210
if [ ! "_$?" = "_0" ]; then
211
        rm -rf "__${APP_NAME}.iconset"
212
        rm -rf "${APP_NAME}.app"
213
        exit 1
214
fi
215
rm -rf "__${APP_NAME}.iconset"
216
mv "__${APP_NAME}.icns" "${APP_NAME}.app/Contents/Resources/${APP_NAME}.icns"
217
 
218
# deploy resources
219
cp -r "../sounds" "${APP_NAME}.app/Contents/Resources"
220
 
221
# create PkgInfo file
222
printf "%s" "APPL???" > "${APP_NAME}.app/Contents/PkgInfo"
223
 
224
# create Info.plist
225
(
226
        echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
227
        echo "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
228
        echo "<plist version=\"1.0\">"
229
        echo "<dict>"
230
        echo "  <key>CFBundleDevelopmentRegion</key>"
231
        echo "  <string>en</string>"
232
        echo "  <key>CFBundleExecutable</key>"
233
        echo "  <string>${APP_NAME}</string>"
234
        echo "  <key>CFBundleIconFile</key>"
235
        echo "  <string>${APP_NAME}.icns</string>"
236
        echo "  <key>CFBundleIdentifier</key>"
237
        echo "  <string>${BUNDLE_ID}</string>"
238
        echo "  <key>CFBundleInfoDictionaryVersion</key>"
239
        echo "  <string>6.0</string>"
240
        echo "  <key>CFBundleName</key>"
241
        echo "  <string>${APP_NAME}</string>"
242
        echo "  <key>CFBundleVersion</key>"
243
        echo "  <string>${APP_VERSION}</string>"
244
        echo "  <key>NSHumanReadableCopyright</key>"
245
        echo "  <string>${APP_COPYRIGHT}</string>"
246
        echo "  <key>CFBundlePackageType</key>"
247
        echo "  <string>APPL</string>"
248
        echo "  <key>CFBundleSignature</key>"
249
        echo "  <string>????</string>"
250
        echo "</dict>"
251
        echo "</plist>"
252
) > "${APP_NAME}.app/Contents/Info.plist"
253
 
254
# finished
255
echo "${APP_NAME} was built successfully"
256
exit 0