mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-18 20:55:44 +01:00
Compare commits
5 Commits
88eae600c4
...
7db3e97085
| Author | SHA1 | Date | |
|---|---|---|---|
| 7db3e97085 | |||
| ed5aed474e | |||
| 14caacf95e | |||
| e377b4ee29 | |||
| 21bb6ff79a |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -18,4 +18,6 @@
|
||||
*.lock
|
||||
/bin/
|
||||
/obj/
|
||||
/lib/obj/
|
||||
compile_commands.json
|
||||
compile_commands.events.json
|
||||
|
||||
6
.gitmodules
vendored
Normal file
6
.gitmodules
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
[submodule "lib/glfw"]
|
||||
path = lib/glfw
|
||||
url = https://github.com/glfw/glfw
|
||||
[submodule "lib/libarchive"]
|
||||
path = lib/libarchive
|
||||
url = https://github.com/libarchive/libarchive
|
||||
136
Makefile
136
Makefile
@@ -1,102 +1,88 @@
|
||||
# Copyright (c) 2025 Quinn
|
||||
# Licensed under the MIT Licence. See LICENSE for details
|
||||
SHELL = bash
|
||||
.SHELLFLAGS = -O globstar -c
|
||||
|
||||
# build configuration, information about the current build process
|
||||
NAME = mcaselector-lite
|
||||
VERSION = 0.0.0
|
||||
DEBUG ?= 0
|
||||
CC ?= cc
|
||||
LD ?= ld
|
||||
|
||||
# compilation flags
|
||||
CFLAGS += -c -std=gnu99 -Wall -Wextra -Wpedantic -MMD -MP
|
||||
LDFLAGS += -flto
|
||||
# setting default compilation flags
|
||||
# some of which are able to be overwritten, others are always appended
|
||||
CPPFLAGS ?=
|
||||
CFLAGS ?= -O2 -Wall -Wextra -Wpedantic
|
||||
LDFLAGS ?= -flto
|
||||
CFLAGS += -std=gnu99
|
||||
|
||||
# architecture/OS detection
|
||||
ifeq ($(KERNEL),)
|
||||
ISWIN := $(if $(filter $(OS),Windows_NT),1,0)
|
||||
ifeq ($(ISWIN),1)
|
||||
KERNEL = mingw
|
||||
MARCH = x86_64
|
||||
# add a few extra flags depending on whether
|
||||
# we're debugging or not
|
||||
ifeq ($(DEBUG),0)
|
||||
CPPFLAGS += -DNDEBUG
|
||||
else
|
||||
MARCH := $(shell uname -m)
|
||||
KERNEL := $(shell uname -s | tr '[:upper:]' '[:lower:]')
|
||||
CFLAGS += -fsanitize=address -ftrapv -g
|
||||
LDFLAGS += -fsanitize=address -ftrapv
|
||||
endif
|
||||
else
|
||||
ISWIN := $(if $(filter $(KERNEL),mingw),1,0)
|
||||
endif
|
||||
ifeq ($(MARCH),)
|
||||
$(error must also set MARCH when manually setting KERNEL)
|
||||
CPPFLAGS += -Iinclude -Ilib/glad/include -Ilib/glfw/include -Ilib/libarchive/libarchive
|
||||
LDFLAGS += -Llib/obj/glfw/src -Llib/obj/libarchive/libarchive
|
||||
LDLIBS += -lm -lglfw -larchive
|
||||
|
||||
# detect if we're compiling on Windows, meaning
|
||||
# a lot of things considered "standard" are unavailable.
|
||||
ifeq ($(OS),Windows_NT)
|
||||
ISWIN = 1
|
||||
NAME := $(NAME).exe
|
||||
$(warning Detected Windows_NT, please refer to the documentation if you encounter issues.)
|
||||
endif
|
||||
|
||||
# profiles
|
||||
ifeq ($(DEBUG),1)
|
||||
PROF = dbg
|
||||
CFLAGS += -UNDEBUG -Og -g -Wextra -Wpedantic
|
||||
CFLAGS += $(if $(filter 1,$(ISWIN)),,-fsanitize=address,undefined) -ftrapv
|
||||
LDFLAGS += $(if $(filter 1,$(ISWIN)),,-fsanitize=address,undefined) -ftrapv
|
||||
# |--profile: testing
|
||||
else ifeq ($(DEBUG),test)
|
||||
PROF = test
|
||||
CFLAGS += -UNDEBUG -O2 -g
|
||||
CFLAGS += $(if $(filter 1,$(ISWIN)),,-fsanitize=address) -ftrapv
|
||||
LDFLAGS += $(if $(filter 1,$(ISWIN)),,-fsanitize=address) -ftrapv
|
||||
else
|
||||
PROF = rel
|
||||
CFLAGS += -DNDEBUG -O2
|
||||
endif
|
||||
|
||||
CFLAGS += $(shell pkg-config --cflags glfw3 libarchive) -Iinclude -Ilib/glad/include
|
||||
LDFLAGS += $(shell pkg-config --libs glfw3 libarchive) -lm
|
||||
|
||||
# get source files
|
||||
SRC := $(shell echo src/**/*.c) lib/glad/src/gl.c
|
||||
# TODO: find a better method to find all source files
|
||||
# WARN: find a better method for selecting the object files
|
||||
# find all the source files using wildcards
|
||||
# NOTE: MS-DOS and MS-Windows uses backslash `\`, this might break.
|
||||
RES := $(wildcard res/*.glsl)
|
||||
ifeq ($(DEBUG),test)
|
||||
SRC := $(filter-out src/main.c, $(SRC)) $(shell echo test/**/*.c)
|
||||
endif
|
||||
SRC := $(wildcard src/*.c src/*/*.c src/*/*/*.c src/*/*/*/*.c src/*/*/*/*/*.c src/*/*/*/*/*/*.c src/*/*/*/*/*/*/*.c src/*/*/*/*/*/*/*/*.c) lib/glad/gl.c
|
||||
OBJ := $(SRC:%.c=obj/%.o)
|
||||
TEST := $(wildcard test/*.c test/*/*.c test/*/*/*.c test/*/*/*/*.c test/*/*/*/*/*.c test/*/*/*/*/*/*.c test/*/*/*/*/*/*/*.c test/*/*/*/*/*/*/*/*.c)
|
||||
|
||||
NAME += $(if $(filter 1,$(ISWIN)),.exe,)
|
||||
DIR_BIN := bin/$(MARCH)-$(KERNEL)/$(VERSION)/$(PROF)
|
||||
DIR_OBJ := obj/$(MARCH)-$(KERNEL)/$(VERSION)/$(PROF)
|
||||
|
||||
# output files
|
||||
BIN := $(DIR_BIN)/$(NAME)
|
||||
OBJ := $(SRC:%.c=$(DIR_OBJ)/%.o) $(RES:%=$(DIR_OBJ)/%.o)
|
||||
DEP := $(OBJ:%.o=%.d)
|
||||
|
||||
.PHONY:
|
||||
run: compile
|
||||
$(if $(filter 1,$(ISWIN)),wine,) $(BIN)
|
||||
|
||||
.PHONY:
|
||||
compile: $(BIN)
|
||||
|
||||
.PHONY .NOTPARALLEL:
|
||||
# TODO: potentially automatically detect whether we should compile libs, or if we can just go ahead.
|
||||
.PHONY: all libs test clean clean-libs
|
||||
all: bin/$(NAME)
|
||||
libs: lib/obj/glfw/ lib/obj/libarchive/
|
||||
test: bin/TEST_$(NAME); bin/TEST_$(NAME)
|
||||
clean:
|
||||
@[ -d obj/ ] && rm -rv obj/ || true
|
||||
@[ -d bin/ ] && rm -rv bin/ || true
|
||||
@[ -d bin/ ] && rm -vr bin/ || true
|
||||
@[ -d obj/ ] && rm -vr obj/ || true
|
||||
clean-libs:
|
||||
@[ -d lib/obj/ ] && rm -vr lib/obj/
|
||||
|
||||
$(BIN): $(OBJ)
|
||||
|
||||
# compiles the libraries using cmake
|
||||
lib/obj/%/: lib/%/
|
||||
cmake -S $< -B $@
|
||||
$(MAKE) -C $@
|
||||
|
||||
# link together a runtime binary
|
||||
bin/$(NAME): $(OBJ)
|
||||
$(info [CC/LD] $@)
|
||||
@mkdir -p $(@D)
|
||||
@$(CC) -o $@ $^ $(LDFLAGS)
|
||||
@$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
$(DIR_OBJ)/%.o: %.c
|
||||
$(info [CC] $@)
|
||||
# link together a testing binary
|
||||
# BUG: testing sources must be selected better
|
||||
bin/TEST_$(NAME): $(OBJ)
|
||||
$(info [CC/LD] $@)
|
||||
@mkdir -p $(@D)
|
||||
@$(CC) $(CFLAGS) -o $@ $<
|
||||
@$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
$(DIR_OBJ)/res/%.o: res/%
|
||||
obj/res/%.o: res/%
|
||||
$(info [LD] $@)
|
||||
@mkdir -p $(@D)
|
||||
@$(LD) -r -b binary -o $@ $<
|
||||
|
||||
# some definitions for "default" and assumed compilers, for bulk selection
|
||||
.PHONY: x86_64-linux-gnu-gcc x86_64-w64-mingw32-gcc
|
||||
x86_64-linux-gnu-gcc:; $(MAKE) $(CALL) $(MAKEFLAGS) CC=$@ MARCH=x86_64 KERNEL=linux
|
||||
x86_64-w64-mingw32-gcc:; $(MAKE) $(CALL) $(MAKEFLAGS) CC=$@ MARCH=x86_64 KERNEL=mingw
|
||||
obj/%.o: %.c
|
||||
$(info [CC] $@)
|
||||
@mkdir -p $(@D)
|
||||
@$(CC) -c $(CPPFLAGS) $(CFLAGS) -MMD -MP -o $@ $<
|
||||
|
||||
-include $(DEP)
|
||||
# Include the generated dependency files.
|
||||
# Which creates rules for all dependencies,
|
||||
# as a result updating an .o file when a .h is updated.
|
||||
-include $(OBJ:%.o=%.d)
|
||||
|
||||
@@ -16,19 +16,19 @@
|
||||
#define htole16(x) (x)
|
||||
#define htole32(x) (x)
|
||||
#define htole64(x) (x)
|
||||
#define be16toh(x) __bswap_16(x)
|
||||
#define be32toh(x) __bswap_32(x)
|
||||
#define be64toh(x) __bswap_64(x)
|
||||
#define htobe16(x) __bswap_16(x)
|
||||
#define htobe32(x) __bswap_32(x)
|
||||
#define htobe64(x) __bswap_64(x)
|
||||
#define be16toh(x) bswap_16(x)
|
||||
#define be32toh(x) bswap_32(x)
|
||||
#define be64toh(x) bswap_64(x)
|
||||
#define htobe16(x) bswap_16(x)
|
||||
#define htobe32(x) bswap_32(x)
|
||||
#define htobe64(x) bswap_64(x)
|
||||
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
#define le16toh(x) __bswap_16(x)
|
||||
#define le32toh(x) __bswap_32(x)
|
||||
#define le64toh(x) __bswap_64(x)
|
||||
#define htole16(x) __bswap_16(x)
|
||||
#define htole32(x) __bswap_32(x)
|
||||
#define htole64(x) __bswap_64(x)
|
||||
#define le16toh(x) bswap_16(x)
|
||||
#define le32toh(x) bswap_32(x)
|
||||
#define le64toh(x) bswap_64(x)
|
||||
#define htole16(x) bswap_16(x)
|
||||
#define htole32(x) bswap_32(x)
|
||||
#define htole64(x) bswap_64(x)
|
||||
#define be16toh(x) (x)
|
||||
#define be32toh(x) (x)
|
||||
#define be64toh(x) (x)
|
||||
|
||||
1
lib/glfw
Submodule
1
lib/glfw
Submodule
Submodule lib/glfw added at 7b6aead9fb
1
lib/libarchive
Submodule
1
lib/libarchive
Submodule
Submodule lib/libarchive added at 9525f90ca4
10
src/error.h
10
src/error.h
@@ -15,8 +15,8 @@ void error_war(uint ln, const char *restrict file, const char *restrict fmt, ...
|
||||
void error_err(uint ln, const char *restrict file, const char *restrict fmt, ...);
|
||||
void error_fat(uint ln, const char *restrict file, const char *restrict fmt, ...) NORET;
|
||||
|
||||
#define debug(s, ...) error_dbg(__LINE__, __FILE__, s, ##__VA_ARGS__)
|
||||
#define info(s, ...) error_inf(__LINE__, __FILE__, s, ##__VA_ARGS__)
|
||||
#define warn(s, ...) error_war(__LINE__, __FILE__, s, ##__VA_ARGS__)
|
||||
#define error(s, ...) error_err(__LINE__, __FILE__, s, ##__VA_ARGS__)
|
||||
#define fatal(s, ...) error_fat(__LINE__, __FILE__, s, ##__VA_ARGS__)
|
||||
#define debug(...) error_dbg(__LINE__, __FILE__ __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define info(...) error_inf(__LINE__, __FILE__ __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define warn(...) error_war(__LINE__, __FILE__ __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define error(...) error_err(__LINE__, __FILE__ __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define fatal(...) error_fat(__LINE__, __FILE__ __VA_OPT__(, ) __VA_ARGS__)
|
||||
|
||||
Reference in New Issue
Block a user