From af9ae6d4f28feaa974458a2d313d314ba4e8084f Mon Sep 17 00:00:00 2001 From: Quinn Date: Mon, 15 Sep 2025 11:04:04 +0200 Subject: [PATCH] fix: using the linker for generating a `.o` file is a feature for only GNU ld. Now utilising a process to generate a .c file using `xxd`, and compiling those to object files. --- Makefile | 11 ++++++++--- src/io/shader.c | 25 +++++++++---------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 70433e3..cc2c0dc 100644 --- a/Makefile +++ b/Makefile @@ -72,10 +72,15 @@ bin/TEST_$(NAME): $(TOBJ) $(filter-out obj/src/main.o,$(OBJ)) @mkdir -p $(@D) @$(LD) -o $@ $^ $(LDFLAGS) $(LDLIBS) -obj/res/%.o: res/% - $(info [LD] $@) +obj/res/%.c: res/% + $(info [XXD] $@) @mkdir -p $(@D) - @$(LD) -r -b binary -o $@ $< + @xxd -i -n $(patsubst res/%,%,$<) $< $@ + +obj/res/%.o: obj/res/%.c + $(info [CC] $@) + @mkdir -p $(@D) + @$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $< obj/%.o: %.c $(info [CC] $@) diff --git a/src/io/shader.c b/src/io/shader.c index a2d06b8..dc57b37 100644 --- a/src/io/shader.c +++ b/src/io/shader.c @@ -8,20 +8,14 @@ #include "../error.h" -#define NAM_S(name) _binary_res_##name##_start // name of a start variable -#define NAM_E(name) _binary_res_##name##_end // name of an end variable - -// macro for generating the variable declarations -#define DEF_GLSL(name) \ - extern const char NAM_S(name)[]; \ - extern const char NAM_E(name)[] // NOTE: we are currently just sucking up the memory costs for ease. We can either include the source files themselves. Or use compression, where I'd prefer the latter for ease of installation. -// NOLINTBEGIN (bugprone-reserved-identifier) -DEF_GLSL(sh_vert_glsl); -DEF_GLSL(sh_frag_glsl); -DEF_GLSL(sh_geom_glsl); -// NOLINTEND +extern const char sh_vert_glsl[]; +extern const char sh_frag_glsl[]; +extern const char sh_geom_glsl[]; +extern const uint sh_vert_glsl_len; +extern const uint sh_frag_glsl_len; +extern const uint sh_geom_glsl_len; /* compile a shader */ static GLuint shader_compile(GLenum type, const char *src, size_t len) { @@ -42,11 +36,10 @@ static GLuint shader_compile(GLenum type, const char *src, size_t len) { return shader; } -#define COMPILE_NAME(_type, _name) shader_compile(_type, NAM_S(_name), (uintptr_t)NAM_E(_name) - (uintptr_t)NAM_S(_name)) int shader_init(GLuint pipe) { - GLuint vs = COMPILE_NAME(GL_VERTEX_SHADER, sh_vert_glsl); - GLuint fs = COMPILE_NAME(GL_FRAGMENT_SHADER, sh_frag_glsl); - GLuint gs = COMPILE_NAME(GL_GEOMETRY_SHADER, sh_geom_glsl); + GLuint vs = shader_compile(GL_VERTEX_SHADER, sh_vert_glsl, sh_vert_glsl_len); + GLuint fs = shader_compile(GL_FRAGMENT_SHADER, sh_frag_glsl, sh_frag_glsl_len); + GLuint gs = shader_compile(GL_GEOMETRY_SHADER, sh_geom_glsl, sh_geom_glsl_len); glAttachShader(pipe, vs); glAttachShader(pipe, fs);