Compare commits

...

9 Commits

Author SHA1 Message Date
82ebe1f4d1 fix: use CC instead of LD, and deprecate LD
this is a bit confusing, since setting `LD=cc` would have the same
issue; `ld: -f may not be used without -shared`. So I've got no idea
what is going wrong, I guess it's something funky.
This works, so we shall stick with this.
2025-09-15 12:08:39 +02:00
5f3bd40a47 potato time.
this is quite upsetting.
2025-09-15 12:04:41 +02:00
158a7f8383 fix: don't use UNIX sh based ifs, instead opt for GNU Make.
This is more portable acorss machines
2025-09-15 12:04:41 +02:00
c32d1551c8 fix: regular xxd does not have -n, thus using some argument manipulation magic
On my main system I use `tinyxxd`, henceforth: "regular"
2025-09-15 12:04:41 +02:00
b04ce9998f fix: shader hex code is formatted incorrectly 2025-09-15 11:59:39 +02:00
218b98e684 fix: colour coding on error messages is incorrect 2025-09-15 11:59:39 +02:00
f20171c0d7 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.
2025-09-15 11:59:39 +02:00
3a7709c392 fix: use more accurate linker flags / calling. 2025-09-15 11:59:39 +02:00
ec36d8c475 add runner architecture to the action cache 2025-09-15 11:59:39 +02:00
4 changed files with 38 additions and 34 deletions

View File

@@ -25,13 +25,15 @@ jobs:
if: runner.os == 'Linux' if: runner.os == 'Linux'
run: | run: |
sudo apt update sudo apt update
sudo apt install -y libwayland-dev libxkbcommon-dev xorg-dev cmake sudo apt install -y libwayland-dev libxkbcommon-dev xorg-dev cmake xxd
- uses: actions/cache@v4 - uses: actions/cache@v4
with: with:
path: lib/obj/ path: lib/obj/
key: ${{runner.os}}-lib/obj-${{github.sha}} # I swear to god, if runner.arch displays x64 for x86_64, I will eat a potato.
restore-keys: ${{runner.os}}-lib/obj- # note: it is... fucking shit.
key: ${{runner.os}}_${{runner.arch}}-lib/obj-${{github.sha}}
restore-keys: ${{runner.os}}_${{runner.arch}}-lib/obj-
- run: make -Bj libs - run: make -Bj libs
- run: make -j all - run: make -j all
- run: make -j test - run: make -j test

View File

@@ -5,7 +5,6 @@
NAME = mcaselector-lite NAME = mcaselector-lite
DEBUG ?= 0 DEBUG ?= 0
CC ?= cc CC ?= cc
LD ?= ld
# setting default compilation flags # setting default compilation flags
# some of which are able to be overwritten, others are always appended # some of which are able to be overwritten, others are always appended
@@ -49,11 +48,16 @@ all: bin/$(NAME)
libs: lib/obj/glfw/ lib/obj/libarchive/ libs: lib/obj/glfw/ lib/obj/libarchive/
test: bin/TEST_$(NAME); bin/TEST_$(NAME) test: bin/TEST_$(NAME); bin/TEST_$(NAME)
clean: clean:
@[ -d bin/ ] && rm -vr bin/ || true ifneq ($(wildcard bin/),)
@[ -d obj/ ] && rm -vr obj/ || true rm -vr bin/
endif
ifneq ($(wildcard obj/),)
rm -vr obj/
endif
clean-libs: clean-libs:
@[ -d lib/obj/ ] && rm -vr lib/obj/ || true ifneq ($(wildcard lib/obj/),)
rm -vr lib/obj/
endif
# compiles the libraries using cmake # compiles the libraries using cmake
lib/obj/%/: lib/%/ lib/obj/%/: lib/%/
@@ -62,20 +66,25 @@ lib/obj/%/: lib/%/
# link together a runtime binary # link together a runtime binary
bin/$(NAME): $(OBJ) bin/$(NAME): $(OBJ)
$(info [CC/LD] $@) $(info [LD] $@)
@mkdir -p $(@D) @mkdir -p $(@D)
@$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS) @$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
# link together a testing binary # link together a testing binary
bin/TEST_$(NAME): $(TOBJ) $(filter-out obj/src/main.o,$(OBJ)) bin/TEST_$(NAME): $(TOBJ) $(filter-out obj/src/main.o,$(OBJ))
$(info [CC/LD] $@) $(info [LD] $@)
@mkdir -p $(@D) @mkdir -p $(@D)
@$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS) @$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
obj/res/%.o: res/% obj/res/%.c: res/%
$(info [LD] $@) $(info [XXD] $@)
@mkdir -p $(@D) @mkdir -p $(@D)
@$(LD) -r -b binary -o $@ $< @cd res/ && xxd -i $(patsubst res/%,%,$<) $(abspath $@)
obj/res/%.o: obj/res/%.c
$(info [CC] $@)
@mkdir -p $(@D)
@$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
obj/%.o: %.c obj/%.o: %.c
$(info [CC] $@) $(info [CC] $@)

View File

@@ -23,28 +23,28 @@ void error_dbg(uint ln, const char *restrict file, const char *restrict fmt, ...
void error_inf(uint ln, const char *restrict file, const char *restrict fmt, ...) { void error_inf(uint ln, const char *restrict file, const char *restrict fmt, ...) {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
error_log(stdout, "\033[93mINF\033[0m", ln, file, fmt, ap); error_log(stdout, "\033[94mINF\033[0m", ln, file, fmt, ap);
va_end(ap); va_end(ap);
} }
void error_war(uint ln, const char *restrict file, const char *restrict fmt, ...) { void error_war(uint ln, const char *restrict file, const char *restrict fmt, ...) {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
error_log(stdout, "\033[91mWAR\033[0m", ln, file, fmt, ap); error_log(stdout, "\033[93mWAR\033[0m", ln, file, fmt, ap);
va_end(ap); va_end(ap);
} }
void error_err(uint ln, const char *restrict file, const char *restrict fmt, ...) { void error_err(uint ln, const char *restrict file, const char *restrict fmt, ...) {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
error_log(stdout, "\033[mFAT\033[0m", ln, file, fmt, ap); error_log(stdout, "\033[91mERR\033[0m", ln, file, fmt, ap);
va_end(ap); va_end(ap);
} }
void error_fat(uint ln, const char *restrict file, const char *restrict fmt, ...) { void error_fat(uint ln, const char *restrict file, const char *restrict fmt, ...) {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
error_log(stdout, "\033[mFAT\033[0m", ln, file, fmt, ap); error_log(stdout, "\033[101mFAT\033[0m", ln, file, fmt, ap);
va_end(ap); va_end(ap);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

View File

@@ -8,20 +8,14 @@
#include "../error.h" #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. // 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) extern const char sh_vert_glsl[];
DEF_GLSL(sh_vert_glsl); extern const char sh_frag_glsl[];
DEF_GLSL(sh_frag_glsl); extern const char sh_geom_glsl[];
DEF_GLSL(sh_geom_glsl); extern const uint sh_vert_glsl_len;
// NOLINTEND extern const uint sh_frag_glsl_len;
extern const uint sh_geom_glsl_len;
/* compile a shader */ /* compile a shader */
static GLuint shader_compile(GLenum type, const char *src, size_t len) { static GLuint shader_compile(GLenum type, const char *src, size_t len) {
@@ -36,17 +30,16 @@ static GLuint shader_compile(GLenum type, const char *src, size_t len) {
char log[ilen]; char log[ilen];
glGetShaderInfoLog(shader, ilen, &ilen, log); glGetShaderInfoLog(shader, ilen, &ilen, log);
log[ilen - 1] = '\0'; // terminate the string one character sooner since the log includes a newline log[ilen - 1] = '\0'; // terminate the string one character sooner since the log includes a newline
error("error whilst compiling shader type '0X%X': '%s'", type, log); error("error whilst compiling shader type '0x%X': '%s'", type, log);
} }
return shader; 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) { int shader_init(GLuint pipe) {
GLuint vs = COMPILE_NAME(GL_VERTEX_SHADER, sh_vert_glsl); GLuint vs = shader_compile(GL_VERTEX_SHADER, sh_vert_glsl, sh_vert_glsl_len);
GLuint fs = COMPILE_NAME(GL_FRAGMENT_SHADER, sh_frag_glsl); GLuint fs = shader_compile(GL_FRAGMENT_SHADER, sh_frag_glsl, sh_frag_glsl_len);
GLuint gs = COMPILE_NAME(GL_GEOMETRY_SHADER, sh_geom_glsl); GLuint gs = shader_compile(GL_GEOMETRY_SHADER, sh_geom_glsl, sh_geom_glsl_len);
glAttachShader(pipe, vs); glAttachShader(pipe, vs);
glAttachShader(pipe, fs); glAttachShader(pipe, fs);