Commit: 8c1d52c4ca3f2cf6e85c984dca3b8e1d10b9425e
Parent: a92d96bfc2a857e0059550d675d65f236043f110
Author: Randy Palamar
Date: Tue, 30 Jul 2024 21:34:18 -0600
add optional bundled raylib
This makes it easier to build on Win32 and do releases.
Diffstat:
5 files changed, 46 insertions(+), 11 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1,4 @@
+colourpicker
+*.so
+external/lib
+external/include
diff --git a/.gitmodules b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "external/raylib"]
+ path = external/raylib
+ url = https://github.com/raysan5/raylib.git
diff --git a/README.md b/README.md
@@ -3,7 +3,9 @@
A basic colour picker written in C and [raylib][].
## Requirements
-* raylib > v5 (Current release has a bug in mouse button code).
+* C11 Compiler
+* [raylib][] - Optional, a static version will be be build if
+ `USE_SYSTEM_RAYLIB` is not set in the environment.
## Installation
@@ -11,9 +13,9 @@ Run `build.sh` and copy `colourpicker` where you want it.
## Debug Hot Reloading
-Add `-D_DEBUG` to the cflags and build. The program will load
+If `DEBUG` is set in the environment then the hot reloading
+version will be compiled. The program will load
`libcolourpicker.so` at runtime and reload it when it is updated.
-This is meant solely for development and is not guaranteed to be
-working everywhere.
+In this case raylib **MUST** be dynamically linked.
[raylib]: https://www.raylib.com/
diff --git a/build.sh b/build.sh
@@ -1,13 +1,38 @@
#!/bin/sh
-cflags="-march=native -ggdb -O3 -Wall"
+cflags="-march=native -O3 -Wall"
ldflags="-lraylib"
+debug=${DEBUG}
-# Hot Reloading/Debugging
-#cflags="$cflags -D_DEBUG"
+cc=${CC:-cc}
+system_raylib=${USE_SYSTEM_RAYLIB:-$debug}
-libcflags="$cflags -fPIC -flto"
-libldflags="$ldflags -shared"
+# NOTE: clones and builds a static raylib if system lib is not requested
+# NOTE: this requires cmake
+if [ "$system_raylib" ]; then
+ ldflags="-L/usr/local/lib $ldflags"
+else
+ if [ ! -f external/lib/libraylib.a ]; then
+ git submodule update --init --depth=1 external/raylib
+ cmake --install-prefix="${PWD}/external" \
+ -G "Ninja" -B external/raylib/build -S external/raylib \
+ -D CMAKE_INSTALL_LIBDIR=lib \
+ -D CUSTOMIZE_BUILD=ON -D WITH_PIC=ON -D BUILD_EXAMPLES=OFF
+ cmake --build external/raylib/build
+ cmake --install external/raylib/build
+ fi
+ cflags="$cflags -I./external/raylib/include"
+ ldflags="-L./external/lib $ldflags"
+fi
-cc $libcflags colourpicker.c -o libcolourpicker.so $libldflags
-cc $cflags -o colourpicker main.c $ldflags
+if [ "$debug" ]; then
+ # Hot Reloading/Debugging
+ cflags="$cflags -O0 -ggdb -D_DEBUG"
+
+ libcflags="$cflags -fPIC"
+ libldflags="$ldflags -shared"
+
+ ${cc} $libcflags colourpicker.c -o libcolourpicker.so $libldflags
+fi
+
+${cc} $cflags -o colourpicker main.c $ldflags
diff --git a/external/raylib b/external/raylib
@@ -0,0 +1 @@
+Subproject commit 9e39788e077f1d35c5fe54600f2143423a80bb3d