Files
mcaselector-lite/Makefile
Quinn 92b6606d7d rework makefile to put extera emphasis on us no longer performing cross-platform compilation
Furthermore, we removed a bunch of behaviour that wasn't needed, and
simplified the bunch.
2025-09-11 23:28:58 +02:00

81 lines
2.6 KiB
Makefile

# Copyright (c) 2025 Quinn
# Licensed under the MIT Licence. See LICENSE for details
# build configuration, information about the current build process
NAME = mcaselector-lite
DEBUG ?= 0
CC ?= cc
LD ?= ld
# 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
# add a few extra flags depending on whether
# we're debugging or not
ifeq ($(DEBUG),0)
CPPFLAGS += -DNDEBUG
else
CFLAGS += -fsanitize=address -ftrapv -g
LDFLAGS += -fsanitize=address -ftrapv
endif
# TODO: correctly add all libraries and headers here
CPPFLAGS += $(shell pkg-config --cflags glfw libarchive)
LDLIBS += $(shell pkg-config --libs glfw libarchive) -lm
# 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
# TODO: find a better method to find all source files
# TODO: 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)
SRC := $(wildcard src/*.c src/*/*.c src/*/*/*.c src/*/*/*/*.c src/*/*/*/*/*.c src/*/*/*/*/*/*.c src/*/*/*/*/*/*/*.c src/*/*/*/*/*/*/*/*.c)
TEST := $(wildcard test/*.c test/*/*.c test/*/*/*.c test/*/*/*/*.c test/*/*/*/*/*.c test/*/*/*/*/*/*.c test/*/*/*/*/*/*/*.c test/*/*/*/*/*/*/*/*.c)
.PHONY: all test clean
all: bin/$(NAME)
test: bin/TEST_$(NAME); bin/TEST_$(NAME)
clean:
@rm -v $(SRC:%.c=%.o) || true
@rm -v $(SRC:%.c=%.d) || true
@rm -v $(TEST:%.c=%.o) || true
@rm -v $(TEST:%.c=%.d) || true
@rm -vr bin/ || true
# link together a runtime binary
bin/$(NAME): $(SRC:%.c=%.o) $(RES:%=%.o)
$(info [CC/LD] $@)
@mkdir -p $(@D)
@$(CC) -o $@ $^ $(LDLIBS) $(LDFLAGS)
# link together a testing binary
bin/TEST_$(NAME): $(TEST:%.c=%.o) $(filter-out src/main.o, $(SRC:%.c=%.o)) $(RES:%=%.o)
$(info [CC/LD] $@)
@mkdir -p $(@D)
@$(CC) -o $@ $^ $(LDLIBS) $(LDFLAGS)
res/%.o: res/%.glsl
$(info [LD] $@)
@$(LD) -r -b binary -o $@ $<
# TODO: put object files, and dependency files in obj/ again, since putting them next to the files creates a specific type of nightmare
%.o: %.c
$(info [CC] $@)
@$(CC) -c $(CPPFLAGS) $(CFLAGS) -MMD -MP -o $@ $< -c
# Include the generated dependency files.
# Which creates rules for all dependencies,
# as a result updating an .o file when a .h is updated.
-include $(SRC:%.c=%.d)
-include $(TEST:%.c=%.d)