Created
July 15, 2025 14:52
-
-
Save bones-ai/d87400af6e1494275069e167b1912896 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Use locally defined Raylib paths if available, otherwise fallback to system paths | |
# ci build paths are set during the pipeline run | |
RAYLIB_PATH="${RAYLIB_PATH:-/Users/grey/softwares/raylib/src}" | |
RAYLIB_LIB_PATH="${RAYLIB_LIB_PATH:-/Users/grey/softwares/raylib/build/raylib}" | |
C_FILES=$(find . -type f -name "*.c" ! -name "host.c" ! -name "release.c" ! -name "release_web.c") | |
# backend flags | |
# mac and windows - sdl | |
# web and linux - glfw | |
BACKEND_DEFINE="" | |
BACKEND_FLAGS="" | |
if [[ "$OSTYPE" == "linux"* ]]; then | |
echo "linux build: Using glfw backend" | |
BACKEND_DEFINE="-DPLATFORM_DESKTOP" | |
BACKEND_FLAGS=$(pkg-config --cflags --libs glfw3) | |
else | |
echo "-- Windows/macOS build: Using SDL backend --" | |
BACKEND_DEFINE="-DPLATFORM_DESKTOP_SDL" | |
BACKEND_FLAGS=$(pkg-config --cflags --libs sdl2) | |
fi | |
# detect windows | |
IS_WINDOWS=false | |
if [[ "$OSTYPE" == msys* || "$OSTYPE" == win32* || "$OSTYPE" == cygwin* ]]; then | |
IS_WINDOWS=true | |
fi | |
# net and system libs | |
NET_FLAGS="" | |
RES_FILE="" | |
SYS_LIBS="" | |
if [[ "$IS_WINDOWS" == true ]]; then | |
SYS_LIBS="-lwinhttp" | |
RES_FILE="build/resource.res" | |
echo "Windows build: nocurl specified, skipping libcurl" | |
else | |
NET_FLAGS=$(pkg-config --cflags --libs libcurl) | |
fi | |
# actions | |
case "$1" in | |
release) | |
echo "Release build" | |
if [[ "$IS_WINDOWS" == true ]]; then | |
echo "Generating Windows icon resource" | |
mkdir build | |
echo 'IDI_ICON1 ICON "assets/game_icon.ico"' > build/resource.rc | |
windres build/resource.rc -O coff -o build/resource.res | |
fi | |
echo "Building executable" | |
gcc release.c $C_FILES -lm -O2 -flto -march=native $BACKEND_DEFINE -o build/game_release \ | |
-L$RAYLIB_LIB_PATH -lraylib \ | |
-Wl,-rpath,$RAYLIB_LIB_PATH \ | |
$BACKEND_FLAGS $NET_FLAGS $SYS_LIBS $RES_FILE | |
echo "Done building executable" | |
"$0" pak | |
;; | |
wasm) | |
echo "Building for wasm" | |
mkdir build | |
mkdir build/wasm | |
# build pak | |
"$0" pak | |
# enable this for debugging wasm bugs | |
# -s ASSERTIONS=2 -s SAFE_HEAP=1 \ | |
# -s USE_SDL=2 \ # sdl didn't work cause raylib | |
emcc -o build/wasm/game.html -DWASM release_web.c $C_FILES \ | |
-Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces -Wunused-result \ | |
-O3 -DWASM -I "$RAYLIB_PATH" -I "$RAYLIB_PATH/external" \ | |
--preload-file build/assets.pak@/assets.pak \ | |
-L. -L "$RAYLIB_PATH" \ | |
--preload-file assets \ | |
-s ASYNCIFY \ | |
-s USE_GLFW=3 \ | |
-s INITIAL_MEMORY=512MB \ | |
-s ALLOW_MEMORY_GROWTH=1 \ | |
-s STACK_SIZE=5242880 \ | |
-s FORCE_FILESYSTEM=1 \ | |
-s MAX_WEBGL_VERSION=2 -s USE_WEBGL2=1 \ | |
-s FETCH=1 \ | |
--shell-file "$RAYLIB_PATH/minshell.html" "$RAYLIB_PATH/web/libraylib.a" \ | |
-s 'EXPORTED_FUNCTIONS=["_free","_malloc","_main"]' \ | |
-s EXPORTED_RUNTIME_METHODS=ccall | |
;; | |
assets) | |
# build dll and pak | |
"$0" dll | |
"$0" pak | |
;; | |
dll) | |
echo "Building a dll" | |
gcc -fPIC -DDEBUG -shared $C_FILES $BACKEND_DEFINE -o build/libgame.dylib \ | |
-L$RAYLIB_LIB_PATH -lraylib \ | |
-Wl,-rpath,$RAYLIB_LIB_PATH \ | |
$BACKEND_FLAGS $NET_FLAGS | |
echo "Done building dll" | |
;; | |
pak) | |
echo "Building pak file" | |
python3 tools/pak/make_pak.py | |
echo "Done building pak" | |
;; | |
clean) | |
rm -fr build | |
mkdir build | |
"$0" dll | |
"$0" pak | |
;; | |
watch) | |
# runs a nodemon server on all files to hot reload when there's something new | |
echo "Watching files" | |
nodemon --ext c,h,png --watch . --exec "./z_build.sh assets" | |
;; | |
gen-maps) | |
cd tools/map | |
python3 map_gen.py | |
cd .. | |
;; | |
*) | |
echo "Default debug run" | |
gcc host.c -DDEBUG $BACKEND_DEFINE -o build/game_debug \ | |
-L$RAYLIB_LIB_PATH -lraylib \ | |
-Wl,-rpath,$RAYLIB_LIB_PATH \ | |
$BACKEND_FLAGS | |
./build/game_debug | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment