Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | #!/bin/sh |
2 | |||
3 | MY_PATH="$(dirname "$0")" |
||
6 | pmbaty | 4 | |
1 | pmbaty | 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" |
||
12 | |||
13 | cd "${MY_PATH}" || exit 1 |
||
14 | |||
15 | # cleanup |
||
16 | rm -rf .build |
||
17 | rm -rf "${APP_NAME}.app" |
||
18 | |||
19 | # compiler and linker flags to use |
||
20 | CPPFLAGS="-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 -Ilib" |
||
21 | |||
7 | pmbaty | 22 | # read the source files list from the Visual Studio project file if it exists, else list all the .c files from "lib" and "src" |
23 | if [ -f "${APP_NAME}.vcxproj" ]; then |
||
24 | SRCLIST="$(grep "<ClCompile " ${APP_NAME}.vcxproj|awk -F\" '{print $2}'|tr '\\' '/')" |
||
25 | else |
||
26 | SRCLIST="$(find lib -name '*.c') $(find src -name '*.c')" |
||
27 | fi |
||
1 | pmbaty | 28 | |
6 | pmbaty | 29 | # generate the shader programs |
30 | echo "Compacting GLSL shaders..." |
||
31 | cd src/harness || exit 1 |
||
32 | for SHADER in resources/*.glsl; do |
||
33 | echo "${SHADER}" |
||
34 | SYMBOL_NAME="$(echo "${SHADER}"|tr '[:lower:]' '[:upper:]'|sed 's/[\.\/]/_/g')" |
||
35 | ( |
||
36 | echo "// Auto generated file." |
||
37 | echo "static const char ${SYMBOL_NAME}[] =" |
||
38 | echo "{" |
||
8 | pmbaty | 39 | cat "${SHADER}"|hexdump -e '16/1 "%02x" "\n"' -v|sed 's/[0-9a-fA-F][0-9a-fA-F]/0x&, /g' || exit 1 |
6 | pmbaty | 40 | echo "};" |
41 | ) > "${SHADER}.h" |
||
42 | done |
||
43 | cd ../.. |
||
44 | |||
1 | pmbaty | 45 | # target x86_64 and ARM64 |
46 | for ARCH in x86_64 arm64; do |
||
47 | echo "Compiling for ${ARCH}..." |
||
48 | rm -rf ".build/${ARCH}" |
||
49 | mkdir -p ".build/${ARCH}" || exit 1 |
||
50 | |||
51 | # compile source files |
||
52 | for SRCFILE in ${SRCLIST}; do |
||
53 | echo "${SRCFILE}" |
||
54 | cc -o ".build/${ARCH}/$(basename "${SRCFILE}").o" -mmacosx-version-min=10.11 -arch "${ARCH}" ${CPPFLAGS} -c "${SRCFILE}" || exit 1 |
||
55 | done |
||
56 | |||
57 | # link them together |
||
58 | echo "Linking for ${ARCH}..." |
||
59 | cc -o ".build/${ARCH}/${APP_NAME}" ".build/${ARCH}/"*".o" -mmacosx-version-min=10.11 -arch "${ARCH}" -framework Cocoa -framework OpenGL -F. -framework SDL2 -rpath @loader_path/../Frameworks || exit 1 |
||
60 | done |
||
61 | |||
62 | # create the app layout |
||
63 | mkdir "${APP_NAME}.app" |
||
64 | mkdir "${APP_NAME}.app/Contents" |
||
65 | mkdir "${APP_NAME}.app/Contents/MacOS" |
||
66 | mkdir "${APP_NAME}.app/Contents/Frameworks" |
||
67 | mkdir "${APP_NAME}.app/Contents/Resources" |
||
68 | |||
69 | # generate and deploy fat Mach-O executable |
||
70 | echo "Generating fat executable..." |
||
71 | lipo ".build/x86_64/${APP_NAME}" ".build/arm64/${APP_NAME}" -create -output "${APP_NAME}.app/Contents/MacOS/${APP_NAME}" || exit 1 |
||
72 | |||
73 | # deploy the SDL2 framework |
||
74 | echo "Deploying SDL2 framework..." |
||
75 | cp -pPR SDL2.framework "${APP_NAME}.app/Contents/Frameworks" || exit 1 |
||
76 | rm -rf "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/Versions/A/_CodeSignature" |
||
77 | rm -rf "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/Versions/A/Headers" |
||
78 | rm -rf "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/Headers" |
||
79 | |||
80 | # deploy the game data |
||
81 | echo "Deploying game data..." |
||
82 | cp -pPR DATA "${APP_NAME}.app/Contents/Resources" || exit 1 |
||
83 | |||
84 | # generate and deploy the app icon |
||
85 | echo "Generating app icon..." |
||
86 | mkdir ".build/${APP_NAME}.iconset" || exit 1 |
||
87 | sips -z 16 16 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_16x16.png" > /dev/null |
||
88 | sips -z 32 32 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_16x16@2x.png" > /dev/null |
||
89 | sips -z 32 32 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_32x32.png" > /dev/null |
||
90 | sips -z 64 64 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_32x32@2x.png" > /dev/null |
||
91 | sips -z 128 128 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_128x128.png" > /dev/null |
||
92 | sips -z 256 256 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_128x128@2x.png" > /dev/null |
||
93 | sips -z 256 256 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_256x256.png" > /dev/null |
||
94 | sips -z 512 512 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_256x256@2x.png" > /dev/null |
||
95 | sips -z 512 512 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_512x512.png" > /dev/null |
||
96 | sips -z 1024 1024 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_512x512@2x.png" > /dev/null |
||
97 | iconutil -c icns ".build/${APP_NAME}.iconset" -o "${APP_NAME}.app/Contents/Resources/AppIcon.icns" || exit 1 |
||
98 | |||
99 | # generate the PkgInfo file |
||
100 | echo -n "APPL???" > "${APP_NAME}.app/Contents/PkgInfo" || exit 1 |
||
101 | |||
102 | # generate the Info.plist |
||
103 | ( |
||
104 | echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
||
105 | echo "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" |
||
106 | echo "<plist version=\"1.0\">" |
||
107 | echo "<dict>" |
||
108 | echo " <key>CFBundleDevelopmentRegion</key>" |
||
109 | echo " <string>en</string>" |
||
110 | echo " <key>CFBundleExecutable</key>" |
||
111 | echo " <string>${APP_NAME}</string>" |
||
112 | echo " <key>CFBundleIconFile</key>" |
||
113 | echo " <string>AppIcon.icns</string>" |
||
114 | echo " <key>CFBundleIdentifier</key>" |
||
115 | echo " <string>${BUNDLE_ID}</string>" |
||
116 | echo " <key>CFBundleInfoDictionaryVersion</key>" |
||
117 | echo " <string>6.0</string>" |
||
118 | echo " <key>CFBundleName</key>" |
||
119 | echo " <string>${APP_NAME}</string>" |
||
120 | echo " <key>CFBundleVersion</key>" |
||
121 | echo " <string>${APP_VERSION}</string>" |
||
122 | echo " <key>NSHumanReadableCopyright</key>" |
||
123 | echo " <string>${APP_COPYRIGHT}</string>" |
||
124 | echo " <key>CFBundlePackageType</key>" |
||
125 | echo " <string>APPL</string>" |
||
126 | echo " <key>CFBundleSignature</key>" |
||
127 | echo " <string>????</string>" |
||
128 | echo "</dict>" |
||
129 | echo "</plist>" |
||
130 | ) > "${APP_NAME}.app/Contents/Info.plist" || exit 1 |
||
131 | |||
132 | # finished |
||
133 | echo "Carmageddon was built successfully" |
||
134 | exit 0 |