Rev 9 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
9 | pmbaty | 1 | #!/bin/sh |
2 | |||
3 | MY_PATH="$(dirname "$0")" |
||
4 | |||
5 | APP_NAME="Carmageddon" |
||
6 | APP_VERSION="1.0" |
||
7 | APP_COPYRIGHT="© 2023 Pierre-Marie Baty |
||
8 | © 2023 Dethrace Labs |
||
9 | © 1997 Stainless Games" |
||
10 | BUNDLE_ID="com.pmbaty.carmageddon" |
||
11 | ICON_FILE="icon.png" |
||
11 | pmbaty | 12 | CS_IDENTITY="Apple Distribution: Pierre-Marie Baty" |
9 | pmbaty | 13 | |
14 | # compiler and linker flags to use |
||
11 | pmbaty | 15 | CPPFLAGS="-O3 -DDETHRACE_FIX_BUGS=1 -Isrc/harness/include -Isrc/harness -Isrc/smackw32/include -Isrc/BRSRC13/include -Isrc/BRSRC13 -Isrc/S3/include -Isrc/S3 -Isrc/DETHRACE/common -Isrc/DETHRACE/pd -Isrc/DETHRACE -Ilib/glad/include -Ilib/libsmacker -Ilib/miniaudio/include -Ilib/miniaudio/include/miniaudio -Ilib/SDL2/include/SDL2 -Ilib" |
9 | pmbaty | 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 -F. -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 -lexecinfo ${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 | # generate the shader programs |
||
45 | echo "Compacting GLSL shaders..." |
||
46 | cd src/harness || exit 1 |
||
47 | for SHADER in resources/*.glsl; do |
||
48 | SYMBOL_NAME="$(echo "${SHADER}"|tr '[:lower:]' '[:upper:]'|sed 's/[\.\/]/_/g')" |
||
49 | echo "${SHADER} -> ${SYMBOL_NAME}" |
||
50 | ( |
||
51 | echo "// Auto generated file." |
||
52 | echo "static const char ${SYMBOL_NAME}[] =" |
||
53 | echo "{" |
||
54 | cat "${SHADER}"|hexdump -e '16/1 "%02x" "\n"' -v|sed 's/[0-9a-f][0-9a-f]/0x&, /g' || exit 1 |
||
55 | echo "};" |
||
56 | ) > "${SHADER}.h" || exit 1 |
||
57 | done |
||
58 | cd ../.. |
||
59 | |||
60 | # for each specified architecture... |
||
61 | THIN_OUTPUTS= |
||
62 | for ARCH in ${ARCHS}; do |
||
63 | rm -rf ".build/${ARCH}" |
||
64 | mkdir -p ".build/${ARCH}" || exit 1 |
||
65 | OPTIONAL_ARCH_FLAG="$(test "${ARCH}" = "${ARCHS}" || echo "-arch ${ARCH}")" |
||
66 | |||
67 | # compile source files |
||
68 | echo "Compiling for ${ARCH}..." |
||
69 | for SRCFILE in ${SRCLIST}; do |
||
70 | echo "${SRCFILE}" |
||
71 | cc -o ".build/${ARCH}/$(basename "${SRCFILE}").o" -c "${SRCFILE}" ${OPTIONAL_ARCH_FLAG} ${CPPFLAGS} || exit 1 |
||
72 | done |
||
73 | |||
74 | # link them together |
||
75 | echo "Linking for ${ARCH}..." |
||
11 | pmbaty | 76 | cc -o ".build/${ARCH}/a.out" ".build/${ARCH}/"*".o" ${OPTIONAL_ARCH_FLAG} ${LDFLAGS} || exit 1 |
9 | pmbaty | 77 | THIN_OUTPUTS="${THIN_OUTPUTS} .build/${ARCH}/a.out" |
78 | done |
||
79 | |||
80 | if [ "$(uname)" = "Darwin" ]; then |
||
81 | # create the macOS app layout |
||
82 | echo "Creating macOS app layout..." |
||
83 | mkdir "${APP_NAME}.app" || exit 1 |
||
84 | mkdir "${APP_NAME}.app/Contents" || exit 1 |
||
85 | mkdir "${APP_NAME}.app/Contents/MacOS" || exit 1 |
||
86 | mkdir "${APP_NAME}.app/Contents/Frameworks" || exit 1 |
||
87 | mkdir "${APP_NAME}.app/Contents/Resources" || exit 1 |
||
88 | |||
89 | # generate and deploy fat Mach-O executable |
||
90 | echo "Generating fat executable..." |
||
91 | lipo ${THIN_OUTPUTS} -create -output "${APP_NAME}.app/Contents/MacOS/${APP_NAME}" || exit 1 |
||
92 | |||
11 | pmbaty | 93 | # deploy the SDL2 framework without the symlinks and change the LC_LOAD_DYLIB in the main executable |
94 | # (macOS codesign will refuse to sign the executable if a bundled framework contains symlinks) |
||
9 | pmbaty | 95 | echo "Deploying SDL2 framework..." |
11 | pmbaty | 96 | mkdir "${APP_NAME}.app/Contents/Frameworks/SDL2.framework" || exit 1 |
97 | cp lib/SDL2/macOS/SDL2.framework/SDL2 "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/SDL2" || exit 1 |
||
98 | install_name_tool -change "@rpath/SDL2.framework/Versions/A/SDL2" "@rpath/SDL2.framework/SDL2" "${APP_NAME}.app/Contents/MacOS/${APP_NAME}" |
||
99 | cp -LR lib/SDL2/macOS/SDL2.framework/Resources "${APP_NAME}.app/Contents/Frameworks/SDL2.framework" || exit 1 |
||
100 | find "${APP_NAME}.app/Contents/Frameworks/SDL2.framework" -name Thumbs.db -exec rm {} \; |
||
101 | find "${APP_NAME}.app/Contents/Frameworks/SDL2.framework" -name .DS_Store -exec rm {} \; |
||
102 | find "${APP_NAME}.app/Contents/Frameworks/SDL2.framework" -type f -exec chmod -x {} \; |
||
9 | pmbaty | 103 | |
11 | pmbaty | 104 | # deploy the game data (excluding the savegames) and drop a notice that the actual game data is instantiated elsewhere |
9 | pmbaty | 105 | echo "Deploying game data..." |
106 | cp -LR DATA "${APP_NAME}.app/Contents/Resources" || exit 1 |
||
11 | pmbaty | 107 | rm "${APP_NAME}.app/Contents/Resources/DATA/SAVEGAME/"* |
108 | echo "This game data is READONLY. The actual game data (read/write) is instantiated out of this template in ~/Library/Application Support/Carmageddon/DATA." > "${APP_NAME}.app/Contents/Resources/README.txt" |
||
9 | pmbaty | 109 | |
110 | # generate and deploy the app icon |
||
111 | echo "Generating app icon..." |
||
112 | mkdir ".build/${APP_NAME}.iconset" || exit 1 |
||
113 | sips -z 16 16 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_16x16.png" > /dev/null |
||
114 | sips -z 32 32 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_16x16@2x.png" > /dev/null |
||
115 | sips -z 32 32 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_32x32.png" > /dev/null |
||
116 | sips -z 64 64 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_32x32@2x.png" > /dev/null |
||
117 | sips -z 128 128 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_128x128.png" > /dev/null |
||
118 | sips -z 256 256 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_128x128@2x.png" > /dev/null |
||
119 | sips -z 256 256 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_256x256.png" > /dev/null |
||
120 | sips -z 512 512 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_256x256@2x.png" > /dev/null |
||
121 | sips -z 512 512 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_512x512.png" > /dev/null |
||
122 | sips -z 1024 1024 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_512x512@2x.png" > /dev/null |
||
123 | iconutil -c icns ".build/${APP_NAME}.iconset" -o "${APP_NAME}.app/Contents/Resources/AppIcon.icns" || exit 1 |
||
124 | |||
125 | # generate the PkgInfo file |
||
126 | echo -n "APPL???" > "${APP_NAME}.app/Contents/PkgInfo" || exit 1 |
||
127 | |||
128 | # generate the Info.plist |
||
129 | ( |
||
130 | echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
||
131 | echo "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" |
||
132 | echo "<plist version=\"1.0\">" |
||
133 | echo "<dict>" |
||
134 | echo " <key>CFBundleDevelopmentRegion</key>" |
||
135 | echo " <string>en</string>" |
||
136 | echo " <key>CFBundleExecutable</key>" |
||
137 | echo " <string>${APP_NAME}</string>" |
||
138 | echo " <key>CFBundleIconFile</key>" |
||
139 | echo " <string>AppIcon.icns</string>" |
||
140 | echo " <key>CFBundleIdentifier</key>" |
||
141 | echo " <string>${BUNDLE_ID}</string>" |
||
142 | echo " <key>CFBundleInfoDictionaryVersion</key>" |
||
143 | echo " <string>6.0</string>" |
||
144 | echo " <key>CFBundleName</key>" |
||
145 | echo " <string>${APP_NAME}</string>" |
||
146 | echo " <key>CFBundleVersion</key>" |
||
147 | echo " <string>${APP_VERSION}</string>" |
||
148 | echo " <key>NSHumanReadableCopyright</key>" |
||
149 | echo " <string>${APP_COPYRIGHT}</string>" |
||
150 | echo " <key>CFBundlePackageType</key>" |
||
151 | echo " <string>APPL</string>" |
||
152 | echo " <key>CFBundleSignature</key>" |
||
153 | echo " <string>????</string>" |
||
154 | echo "</dict>" |
||
155 | echo "</plist>" |
||
156 | ) > "${APP_NAME}.app/Contents/Info.plist" || exit 1 |
||
157 | |||
11 | pmbaty | 158 | # code signing is mandatory |
159 | codesign --force --deep --sign "${CS_IDENTITY}" --timestamp "${APP_NAME}.app" |
||
160 | |||
9 | pmbaty | 161 | echo "Output app bundle: ${APP_NAME}.app" |
11 | pmbaty | 162 | |
163 | # zip on Mac to preserve executable flags |
||
164 | zip -r "${APP_NAME} (Mac).zip" "${APP_NAME}.app" && echo "A Zip file of the app bundle was created for convenience." |
||
9 | pmbaty | 165 | else |
166 | # Linux/BSD/whatever: simply retrieve the compiled executable |
||
167 | cp ".build/${ARCH}/a.out" "${APP_NAME}.$(uname)-$(uname -m)" |
||
168 | |||
169 | echo "Output executable: ${APP_NAME}.$(uname)-$(uname -m)" |
||
170 | fi |
||
171 | |||
172 | # finished |
||
173 | echo "${APP_NAME} was built successfully" |
||
174 | exit 0 |