Commit: dd12be90aa918af0e4f9f7de452a9f1b946928b7
Parent: fcd5c18b7cd0ab6b11a4d25f6e57900b6ce91056
Author: Randy Palamar
Date: Sat, 25 Jan 2025 10:05:56 -0700
build.sh: built raylib's bundled glfw separately
raylib is not-architected to have multiple OpenGL contexts so we
need to do it behind their back. We can still use the bundled GLFW
but we have to tell raylib that it is external.
This also makes it so that touching the build.sh will cause the
built external libraries to rebuild.
Diffstat:
M | build.sh | | | 77 | ++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------- |
1 file changed, 52 insertions(+), 25 deletions(-)
diff --git a/build.sh b/build.sh
@@ -23,6 +23,7 @@ done
case $(uname -sm) in
MINGW64*)
win32=1
+ glfw="libglfw.dll"
raylib="libraylib.dll"
raylib_out_lib="external/bin/libraylib.dll"
main="main_w32.c"
@@ -37,6 +38,7 @@ MINGW64*)
${extra_ldflags}
;;
Linux*)
+ glfw="libglfw.so.3"
raylib="libraylib.so.550"
raylib_out_lib="external/lib/libraylib.so.5.5.0"
main="main_linux.c"
@@ -51,6 +53,49 @@ if [ ! -f external/raylib/README.md ] || [ "$(git status --short external/raylib
git submodule update --init --depth=1 external/raylib
fi
+build_raylib()
+{
+ rm -r ${2} 2>/dev/null
+ cmake --install-prefix="${PWD}/external" \
+ -G "Ninja" -B ${2} -S external/raylib \
+ ${1} \
+ -D CMAKE_INSTALL_LIBDIR=lib -D CMAKE_BUILD_TYPE="Release" \
+ -DCUSTOMIZE_BUILD=ON -DBUILD_EXAMPLES=OFF -DWITH_PIC=ON \
+ -DUSE_EXTERNAL_GLFW=ON \
+ -DOPENGL_VERSION=4.3 -DUSE_AUDIO=OFF -DSUPPORT_MODULE_RAUDIO=OFF
+ cmake --build ${2}
+ cmake --install ${2}
+}
+
+check_and_rebuild_libs()
+{
+ switch=OFF
+ [ ${1} = "shared" ] && switch=ON
+ if [ "./build.sh" -nt "${raylib}" ] || [ ! -f "${raylib}" ]; then
+ build_raylib "-D BUILD_SHARED_LIBS=${switch}" "external/raylib/build_${1}"
+ [ ${1} = "shared" ] && cp -L "${raylib_out_lib}" "${raylib}"
+ fi
+
+ # NOTE(rnp): we need to build this separately so that we can use functions from
+ # glfw directly - raylib doesn't let us open multiple opengl contexts even if
+ # we never plan on using them with raylib
+ case "${1}" in
+ static)
+ if [ "./build.sh" -nt "${glfw}" ] || [ ! -f ${glfw} ]; then
+ ${cc} ${cflags} -static -D_GLFW_X11 \
+ -c external/raylib/src/rglfw.c -o external/lib/rglfw.o
+ ar qc ${glfw} external/lib/rglfw.o
+ fi
+ ;;
+ shared)
+ if [ "./build.sh" -nt "${glfw}" ] || [ ! -f "${glfw}" ]; then
+ ${cc} ${cflags} -fPIC -shared -D_GLFW_X11 \
+ external/raylib/src/rglfw.c -o ${glfw}
+ fi
+ ;;
+ esac
+}
+
case "${build}" in
debug)
cflags="${cflags} -O0 -D_DEBUG -Wno-unused-function"
@@ -60,34 +105,16 @@ debug)
else
cflags="${cflags} -ggdb -Wl,-rpath,."
fi
- if [ ! -f "${raylib}" ]; then
- cmake --install-prefix="${PWD}/external" \
- -G "Ninja" -B external/raylib/build_shared -S external/raylib \
- -D BUILD_SHARED_LIBS=ON \
- -D CMAKE_INSTALL_LIBDIR=lib -D CMAKE_BUILD_TYPE="Release" \
- -DCUSTOMIZE_BUILD=ON -DBUILD_EXAMPLES=OFF -DWITH_PIC=ON \
- -DOPENGL_VERSION=4.3 -DUSE_AUDIO=OFF -DSUPPORT_MODULE_RAUDIO=OFF
- cmake --build external/raylib/build_shared
- cmake --install external/raylib/build_shared
- cp "${raylib_out_lib}" "${raylib}"
- fi
- ldflags="-L. -lraylib ${ldflags}"
- libcflags="${cflags} -fPIC -shared"
- ${cc} ${libcflags} beamformer.c -o ${libname} ${ldflags}
+ ldflags="-L. -lglfw -lraylib ${ldflags}"
+ check_and_rebuild_libs "shared"
+ ${cc} ${cflags} -fPIC -shared beamformer.c -o ${libname} ${ldflags}
;;
release)
cflags="${cflags} -O3"
- if [ ! -f external/lib/libraylib.a ]; then
- cmake --install-prefix="${PWD}/external" \
- -G "Ninja" -B external/raylib/build_static -S external/raylib \
- -D CMAKE_INSTALL_LIBDIR=lib -D CMAKE_BUILD_TYPE="Release" \
- -D BUILD_SHARED_LIBS=OFF \
- -DCUSTOMIZE_BUILD=ON -DBUILD_EXAMPLES=OFF -DWITH_PIC=ON \
- -DOPENGL_VERSION=4.3 -DUSE_AUDIO=OFF -DSUPPORT_MODULE_RAUDIO=OFF
- cmake --build external/raylib/build_static
- cmake --install external/raylib/build_static
- fi
- ldflags="./external/lib/libraylib.a ${ldflags}"
+ raylib="external/lib/libraylib.a"
+ glfw="external/lib/libglfw.a"
+ ldflags="${raylib} ${glfw} ${ldflags}"
+ check_and_rebuild_libs "static"
;;
esac