Subversion Repositories Games.Carmageddon

Rev

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