Subversion Repositories Games.Carmageddon

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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"
  12.  
  13. # compiler and linker flags to use
  14. 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"
  15. LDFLAGS=""
  16.  
  17. cd "${MY_PATH}" || exit 1
  18.  
  19. # cleanup
  20. rm -rf .build
  21. if [ "$(uname)" = "Darwin" ]; then
  22.         # macOS
  23.         rm -rf "${APP_NAME}.app"
  24.         ARCHS="x86_64 arm64"
  25.         CPPFLAGS="-mmacosx-version-min=10.11 ${CPPFLAGS}"
  26.         LDFLAGS="-mmacosx-version-min=10.11 -framework Cocoa -framework OpenGL -F. -framework SDL2 -rpath @loader_path/../Frameworks ${LDFLAGS}"
  27. else
  28.         # Linux/BSD/whatever
  29.         rm -rf "${APP_NAME}.$(uname)-$(uname -m)"
  30.         ARCHS="$(uname -m)"
  31.         CPPFLAGS="${CPPFLAGS}"
  32.         LDFLAGS="-L/usr/local/lib -lSDL2 -lpthread -lm ${LDFLAGS}"
  33.         test "$(uname)" = "FreeBSD" && LDFLAGS="-linotify -lusbhid -lexecinfo ${LDFLAGS}"
  34. fi
  35.  
  36. # read the source files list from the Visual Studio project file if it exists, else list all the .c files from "lib" and "src"
  37. if [ -f "${APP_NAME}.vcxproj" ]; then
  38.         SRCLIST="$(grep "<ClCompile " "${APP_NAME}.vcxproj"|awk -F\" '{print $2}'|tr '\\' '/')"
  39. else
  40.         SRCLIST="$(find lib -name '*.c') $(find src -name '*.c')"
  41. fi
  42.  
  43. # generate the shader programs
  44. echo "Compacting GLSL shaders..."
  45. cd src/harness || exit 1
  46. for SHADER in resources/*.glsl; do
  47.         SYMBOL_NAME="$(echo "${SHADER}"|tr '[:lower:]' '[:upper:]'|sed 's/[\.\/]/_/g')"
  48.         echo "${SHADER} -> ${SYMBOL_NAME}"
  49.         (
  50.                 echo "// Auto generated file."
  51.                 echo "static const char ${SYMBOL_NAME}[] ="
  52.                 echo "{"
  53.                 cat "${SHADER}"|hexdump -e '16/1 "%02x" "\n"' -v|sed 's/[0-9a-f][0-9a-f]/0x&, /g' || exit 1
  54.                 echo "};"
  55.         ) > "${SHADER}.h" || exit 1
  56. done
  57. cd ../..
  58.  
  59. # for each specified architecture...
  60. THIN_OUTPUTS=
  61. for ARCH in ${ARCHS}; do
  62.         rm -rf ".build/${ARCH}"
  63.         mkdir -p ".build/${ARCH}" || exit 1
  64.         OPTIONAL_ARCH_FLAG="$(test "${ARCH}" = "${ARCHS}" || echo "-arch ${ARCH}")"
  65.  
  66.         # compile source files
  67.         echo "Compiling for ${ARCH}..."
  68.         for SRCFILE in ${SRCLIST}; do
  69.                 echo "${SRCFILE}"
  70.                 cc -o ".build/${ARCH}/$(basename "${SRCFILE}").o" -c "${SRCFILE}" ${OPTIONAL_ARCH_FLAG} ${CPPFLAGS} || exit 1
  71.         done
  72.  
  73.         # link them together
  74.         echo "Linking for ${ARCH}..."
  75.         cc -o ".build/${ARCH}/${APP_NAME}" ".build/${ARCH}/"*".o" ${OPTIONAL_ARCH_FLAG} ${LDFLAGS} || exit 1
  76.         THIN_OUTPUTS="${THIN_OUTPUTS} .build/${ARCH}/a.out"
  77. done
  78.  
  79. if [ "$(uname)" = "Darwin" ]; then
  80.         # create the macOS app layout
  81.         echo "Creating macOS app layout..."
  82.         mkdir "${APP_NAME}.app"                     || exit 1
  83.         mkdir "${APP_NAME}.app/Contents"            || exit 1
  84.         mkdir "${APP_NAME}.app/Contents/MacOS"      || exit 1
  85.         mkdir "${APP_NAME}.app/Contents/Frameworks" || exit 1
  86.         mkdir "${APP_NAME}.app/Contents/Resources"  || exit 1
  87.  
  88.         # generate and deploy fat Mach-O executable
  89.         echo "Generating fat executable..."
  90.         lipo ${THIN_OUTPUTS} -create -output "${APP_NAME}.app/Contents/MacOS/${APP_NAME}" || exit 1
  91.  
  92.         # deploy the SDL2 framework
  93.         echo "Deploying SDL2 framework..."
  94.         mkdir "${APP_NAME}.app/Contents/Frameworks/SDL2.framework"                                                     || exit 1
  95.         mkdir "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/Versions"                                            || exit 1
  96.         mkdir "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/Versions/A"                                          || exit 1
  97.         cp lib/SDL2/macOS/SDL2.framework/SDL2 "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/Versions/A/SDL2"     || exit 1
  98.         ln -s Versions/A/SDL2 "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/SDL2"                                || exit 1
  99.         cp -LR lib/SDL2/macOS/SDL2.framework/Resources "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/Versions/A" || exit 1
  100.         ln -s Versions/A/Resources "${APP_NAME}.app/Contents/Frameworks/SDL2.framework/Resources"                      || exit 1
  101.  
  102.         # deploy the game data
  103.         echo "Deploying game data..."
  104.         cp -LR DATA "${APP_NAME}.app/Contents/Resources" || exit 1
  105.  
  106.         # generate and deploy the app icon
  107.         echo "Generating app icon..."
  108.         mkdir ".build/${APP_NAME}.iconset" || exit 1
  109.         sips -z 16 16     "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_16x16.png"      > /dev/null
  110.         sips -z 32 32     "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_16x16@2x.png"   > /dev/null
  111.         sips -z 32 32     "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_32x32.png"      > /dev/null
  112.         sips -z 64 64     "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_32x32@2x.png"   > /dev/null
  113.         sips -z 128 128   "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_128x128.png"    > /dev/null
  114.         sips -z 256 256   "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_128x128@2x.png" > /dev/null
  115.         sips -z 256 256   "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_256x256.png"    > /dev/null
  116.         sips -z 512 512   "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_256x256@2x.png" > /dev/null
  117.         sips -z 512 512   "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_512x512.png"    > /dev/null
  118.         sips -z 1024 1024 "${ICON_FILE}" --out ".build/${APP_NAME}.iconset/icon_512x512@2x.png" > /dev/null
  119.         iconutil -c icns ".build/${APP_NAME}.iconset" -o "${APP_NAME}.app/Contents/Resources/AppIcon.icns" || exit 1
  120.  
  121.         # generate the PkgInfo file
  122.         echo -n "APPL???" > "${APP_NAME}.app/Contents/PkgInfo" || exit 1
  123.  
  124.         # generate the Info.plist
  125.         (
  126.                 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
  127.                 echo "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
  128.                 echo "<plist version=\"1.0\">"
  129.                 echo "<dict>"
  130.                 echo "  <key>CFBundleDevelopmentRegion</key>"
  131.                 echo "  <string>en</string>"
  132.                 echo "  <key>CFBundleExecutable</key>"
  133.                 echo "  <string>${APP_NAME}</string>"
  134.                 echo "  <key>CFBundleIconFile</key>"
  135.                 echo "  <string>AppIcon.icns</string>"
  136.                 echo "  <key>CFBundleIdentifier</key>"
  137.                 echo "  <string>${BUNDLE_ID}</string>"
  138.                 echo "  <key>CFBundleInfoDictionaryVersion</key>"
  139.                 echo "  <string>6.0</string>"
  140.                 echo "  <key>CFBundleName</key>"
  141.                 echo "  <string>${APP_NAME}</string>"
  142.                 echo "  <key>CFBundleVersion</key>"
  143.                 echo "  <string>${APP_VERSION}</string>"
  144.                 echo "  <key>NSHumanReadableCopyright</key>"
  145.                 echo "  <string>${APP_COPYRIGHT}</string>"
  146.                 echo "  <key>CFBundlePackageType</key>"
  147.                 echo "  <string>APPL</string>"
  148.                 echo "  <key>CFBundleSignature</key>"
  149.                 echo "  <string>????</string>"
  150.                 echo "</dict>"
  151.                 echo "</plist>"
  152.         ) > "${APP_NAME}.app/Contents/Info.plist" || exit 1
  153.  
  154.         echo "Output app bundle: ${APP_NAME}.app"
  155. else
  156.         # Linux/BSD/whatever: simply retrieve the compiled executable
  157.         cp ".build/${ARCH}/a.out" "${APP_NAME}.$(uname)-$(uname -m)"
  158.  
  159.         echo "Output executable: ${APP_NAME}.$(uname)-$(uname -m)"
  160. fi
  161.  
  162. # finished
  163. echo "${APP_NAME} was built successfully"
  164. exit 0
  165.