Rev 11 | Details | Compare with Previous | 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" |
||
13 | pmbaty | 6 | APP_VERSION="1.5" |
7 | APP_COPYRIGHT="© 2024 Pierre-Marie Baty |
||
11 | pmbaty | 8 | © 2002 BigOrno |
9 | © 1989 CORE Design |
||
10 | Artwork by Simon Phipps" |
||
13 | pmbaty | 11 | BUNDLE_ID="com.pmbaty.rickdangerous" |
11 | pmbaty | 12 | ICON_FILE="icon.png" |
13 | pmbaty | 13 | CS_IDENTITY="Apple Distribution: Pierre-Marie Baty" |
11 | pmbaty | 14 | |
15 | # compiler and linker flags to use |
||
16 | CPPFLAGS="-Isrc -Ilib/SDL2/include" |
||
17 | LDFLAGS="" |
||
18 | |||
19 | cd "${MY_PATH}" || exit 1 |
||
20 | |||
21 | # cleanup |
||
22 | rm -rf .build |
||
23 | if [ "$(uname)" = "Darwin" ]; then |
||
24 | # macOS |
||
25 | rm -rf "${APP_NAME}.app" |
||
26 | ARCHS="x86_64 arm64" |
||
27 | CPPFLAGS="-mmacosx-version-min=10.11 ${CPPFLAGS}" |
||
28 | LDFLAGS="-mmacosx-version-min=10.11 -framework Cocoa -framework OpenGL -Flib/SDL2/macOS -framework SDL2 -rpath @loader_path/../Frameworks ${LDFLAGS}" |
||
29 | else |
||
30 | # Linux/BSD/whatever |
||
31 | rm -rf "${APP_NAME}.$(uname)-$(uname -m)" |
||
32 | ARCHS="$(uname -m)" |
||
33 | CPPFLAGS="${CPPFLAGS}" |
||
34 | LDFLAGS="-L/usr/local/lib -lSDL2 -lpthread -lm ${LDFLAGS}" |
||
35 | test "$(uname)" = "FreeBSD" && LDFLAGS="-linotify -lusbhid ${LDFLAGS}" |
||
36 | fi |
||
37 | |||
38 | # read the source files list from the Visual Studio project file if it exists, else list all the .c files from "lib" and "src" |
||
39 | if [ -f "${APP_NAME}.vcxproj" ]; then |
||
40 | SRCLIST="$(grep "<ClCompile " "${APP_NAME}.vcxproj"|awk -F\" '{print $2}'|tr '\\' '/')" |
||
41 | else |
||
42 | SRCLIST="$(find lib -name '*.c') $(find src -name '*.c')" |
||
43 | fi |
||
44 | |||
45 | # for each specified architecture... |
||
46 | THIN_OUTPUTS= |
||
47 | for ARCH in ${ARCHS}; do |
||
48 | rm -rf ".build/${ARCH}" |
||
49 | mkdir -p ".build/${ARCH}" || exit 1 |
||
50 | OPTIONAL_ARCH_FLAG="$(test "${ARCH}" = "${ARCHS}" || echo "-arch ${ARCH}")" |
||
51 | |||
52 | # compile source files |
||
53 | echo "Compiling for ${ARCH}..." |
||
54 | for SRCFILE in ${SRCLIST}; do |
||
55 | echo "${SRCFILE}" |
||
56 | cc -o ".build/${ARCH}/$(basename "${SRCFILE}").o" -c "${SRCFILE}" ${OPTIONAL_ARCH_FLAG} ${CPPFLAGS} || exit 1 |
||
57 | done |
||
58 | |||
59 | # link them together |
||
60 | echo "Linking for ${ARCH}..." |
||
61 | cc -o ".build/${ARCH}/a.out" ".build/${ARCH}/"*".o" ${OPTIONAL_ARCH_FLAG} ${LDFLAGS} || exit 1 |
||
62 | THIN_OUTPUTS="${THIN_OUTPUTS} .build/${ARCH}/a.out" |
||
63 | done |
||
64 | |||
65 | if [ "$(uname)" = "Darwin" ]; then |
||
66 | # create the macOS app layout |
||
67 | echo "Creating macOS app layout..." |
||
68 | mkdir "${APP_NAME}.app" || exit 1 |
||
69 | mkdir "${APP_NAME}.app/Contents" || exit 1 |
||
70 | mkdir "${APP_NAME}.app/Contents/MacOS" || exit 1 |
||
71 | mkdir "${APP_NAME}.app/Contents/Frameworks" || exit 1 |
||
72 | mkdir "${APP_NAME}.app/Contents/Resources" || exit 1 |
||
73 | |||
74 | # generate and deploy fat Mach-O executable |
||
75 | echo "Generating fat executable..." |
||
76 | lipo ${THIN_OUTPUTS} -create -output "${APP_NAME}.app/Contents/MacOS/${APP_NAME}" || exit 1 |
||
77 | |||
13 | pmbaty | 78 | # deploy the SDL2 framework without the symlinks and change the LC_LOAD_DYLIB in the main executable |
79 | # (macOS codesign will refuse to sign the executable if a bundled framework contains symlinks) |
||
11 | pmbaty | 80 | echo "Deploying SDL2 framework..." |
13 | pmbaty | 81 | mkdir "${APP_NAME}.app/Contents/Frameworks/SDL2.framework" || exit 1 |
82 | cp lib/SDL2/macOS/SDL2.framework/SDL2 "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/SDL2" || exit 1 |
||
83 | install_name_tool -change "@rpath/SDL2.framework/Versions/A/SDL2" "@rpath/SDL2.framework/SDL2" "${APP_NAME}.app/Contents/MacOS/${APP_NAME}" |
||
84 | cp -LR lib/SDL2/macOS/SDL2.framework/Resources "${APP_NAME}.app/Contents/Frameworks/SDL2.framework" || exit 1 |
||
85 | find "${APP_NAME}.app/Contents/Frameworks/SDL2.framework" -name Thumbs.db -exec rm {} \; |
||
86 | find "${APP_NAME}.app/Contents/Frameworks/SDL2.framework" -name .DS_Store -exec rm {} \; |
||
87 | find "${APP_NAME}.app/Contents/Frameworks/SDL2.framework" -type f -exec chmod -x {} \; |
||
11 | pmbaty | 88 | |
13 | pmbaty | 89 | # deploy the game data, remove executable flags from files and remove junk files |
11 | pmbaty | 90 | echo "Deploying game data..." |
91 | cp -LR sounds "${APP_NAME}.app/Contents/Resources" || exit 1 |
||
13 | pmbaty | 92 | find "${APP_NAME}.app/Contents/Resources" -name Thumbs.db -exec rm {} \; |
93 | find "${APP_NAME}.app/Contents/Resources" -name .DS_Store -exec rm {} \; |
||
94 | find "${APP_NAME}.app/Contents/Resources" -type f -exec chmod -x {} \; |
||
11 | pmbaty | 95 | |
96 | # generate and deploy the app icon |
||
97 | echo "Generating app icon..." |
||
98 | mkdir ".build/${APP_NAME}.iconset" || exit 1 |
||
99 | sips -z 16 16 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_16x16.png" > /dev/null |
||
100 | sips -z 32 32 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_16x16@2x.png" > /dev/null |
||
101 | sips -z 32 32 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_32x32.png" > /dev/null |
||
102 | sips -z 64 64 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_32x32@2x.png" > /dev/null |
||
103 | sips -z 128 128 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_128x128.png" > /dev/null |
||
104 | sips -z 256 256 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_128x128@2x.png" > /dev/null |
||
105 | sips -z 256 256 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_256x256.png" > /dev/null |
||
106 | sips -z 512 512 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_256x256@2x.png" > /dev/null |
||
107 | sips -z 512 512 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_512x512.png" > /dev/null |
||
108 | sips -z 1024 1024 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_512x512@2x.png" > /dev/null |
||
109 | iconutil -c icns ".build/${APP_NAME}.iconset" -o "${APP_NAME}.app/Contents/Resources/AppIcon.icns" || exit 1 |
||
110 | |||
111 | # generate the PkgInfo file |
||
112 | echo -n "APPL???" > "${APP_NAME}.app/Contents/PkgInfo" || exit 1 |
||
113 | |||
114 | # generate the Info.plist |
||
115 | ( |
||
116 | echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
||
117 | echo "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" |
||
118 | echo "<plist version=\"1.0\">" |
||
119 | echo "<dict>" |
||
120 | echo " <key>CFBundleDevelopmentRegion</key>" |
||
121 | echo " <string>en</string>" |
||
122 | echo " <key>CFBundleExecutable</key>" |
||
123 | echo " <string>${APP_NAME}</string>" |
||
124 | echo " <key>CFBundleIconFile</key>" |
||
125 | echo " <string>AppIcon.icns</string>" |
||
126 | echo " <key>CFBundleIdentifier</key>" |
||
127 | echo " <string>${BUNDLE_ID}</string>" |
||
128 | echo " <key>CFBundleInfoDictionaryVersion</key>" |
||
129 | echo " <string>6.0</string>" |
||
130 | echo " <key>CFBundleName</key>" |
||
131 | echo " <string>${APP_NAME}</string>" |
||
132 | echo " <key>CFBundleVersion</key>" |
||
133 | echo " <string>${APP_VERSION}</string>" |
||
134 | echo " <key>NSHumanReadableCopyright</key>" |
||
135 | echo " <string>${APP_COPYRIGHT}</string>" |
||
136 | echo " <key>CFBundlePackageType</key>" |
||
137 | echo " <string>APPL</string>" |
||
138 | echo " <key>CFBundleSignature</key>" |
||
139 | echo " <string>????</string>" |
||
140 | echo "</dict>" |
||
141 | echo "</plist>" |
||
142 | ) > "${APP_NAME}.app/Contents/Info.plist" || exit 1 |
||
143 | |||
13 | pmbaty | 144 | # code signing is mandatory |
145 | codesign --force --deep --sign "${CS_IDENTITY}" --timestamp "${APP_NAME}.app" |
||
146 | |||
11 | pmbaty | 147 | echo "Output app bundle: ${APP_NAME}.app" |
13 | pmbaty | 148 | |
149 | # zip on Mac to preserve executable flags |
||
150 | zip -r "${APP_NAME} (Mac).zip" "${APP_NAME}.app" && echo "A Zip file of the app bundle was created for convenience." |
||
11 | pmbaty | 151 | else |
152 | # Linux/BSD/whatever: simply retrieve the compiled executable |
||
153 | cp ".build/${ARCH}/a.out" "${APP_NAME}.$(uname)-$(uname -m)" |
||
154 | |||
155 | echo "Output executable: ${APP_NAME}.$(uname)-$(uname -m)" |
||
156 | fi |
||
157 | |||
158 | # finished |
||
159 | echo "${APP_NAME} was built successfully" |
||
160 | exit 0 |