modify Makefile to be more in-line with the GNU standard.

Mainly so the makefile is a bit less esoteric to use, debugging flags
must be specified manually.

changed:
- `$RM` for calling `rm`
- removed unused `$ISWIN`
- renamed `test` to `check`
- added `install` and `install-strip` recipes, which for now remain
empty
- added `-g` to `$CFLAGS`, since it helps debugging, and in case of
failures makes bug report less of a headache.

I decided to not modify it further so "specialised tools" don't need to
store files in the git repo, which seemed to complicate logic.
This is the same reason to why I chose to not adapt clean in a way to
introduce `mostlyclean`.
This commit is contained in:
2025-10-20 15:04:17 +02:00
parent 316726a610
commit 87541d5789
2 changed files with 34 additions and 40 deletions

View File

@@ -54,4 +54,4 @@ jobs:
if: steps.cache-deps.outputs.cache-hit != 'true' && runner.os == 'Windows'
- run: make -j all
- run: make -j test
- run: make -j check

View File

@@ -1,36 +1,24 @@
# Copyright (c) 2025 Quinn
# Licensed under the MIT Licence. See LICENSE for details
SHELL = /bin/sh
.SUFFIXES:
# build configuration, information about the current build process
NAME = mcaselector-lite
DEBUG ?= 0
CC ?= cc
RM ?= rm -vf
CMAKE ?= cmake -G 'Unix Makefiles'
# setting default compilation flags
# some of which are able to be overwritten, others are always appended
CPPFLAGS ?=
CFLAGS ?= -O2 -Wall -Wextra -Wpedantic -Wno-pointer-arith
CPPFLAGS ?= -DNDEBUG
CFLAGS ?= -O2
LDFLAGS ?= -flto
CPPFLAGS += -DGLFW_INCLUDE_NONE
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
CPPFLAGS += -Iinclude -Ilib/glad/include -Ilib/glfw/include -Ilib/libarchive/libarchive
CPPFLAGS += -DGLFW_INCLUDE_NONE -Iinclude -Ilib/glad/include -Ilib/glfw/include -Ilib/libarchive/libarchive
CFLAGS += -std=gnu99 -g -Wall -Wextra -Wpedantic -Wno-pointer-arith -MMD -MP
LDFLAGS += -Llib/obj/glfw/src -Llib/obj/libarchive/libarchive
LDLIBS += -lglfw3 -larchive -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
LDLIBS += -lopengl32 -lgdi32
$(warning Detected Windows_NT, please refer to the documentation if you encounter issues.)
@@ -38,32 +26,37 @@ else ifeq ($(shell uname -s),Darwin)
LDLIBS += -framework Cocoa -framework OpenGL -framework IOKit
endif
# TODO: find a better method to find all source files
# find all the source files using wildcards
# TODO: find a better method to find all source files
# NOTE: MS-DOS and MS-Windows uses backslash `\`, this might break.
RES := $(wildcard res/*)
SRC := $(wildcard src/*.c src/*/*.c src/*/*/*.c src/*/*/*/*.c src/*/*/*/*/*.c src/*/*/*/*/*/*.c src/*/*/*/*/*/*/*.c src/*/*/*/*/*/*/*/*.c) lib/glad/src/gl.c
OBJ := $(SRC:%.c=obj/%.o) $(RES:%=obj/%.o)
TSRC := $(wildcard test/*.c test/*/*.c test/*/*/*.c test/*/*/*/*.c test/*/*/*/*/*.c test/*/*/*/*/*/*.c test/*/*/*/*/*/*/*.c test/*/*/*/*/*/*/*/*.c)
OBJ := $(RES:%=obj/%.o) $(SRC:%.c=obj/%.o)
TOBJ := $(TSRC:%.c=obj/%.o)
# TODO: potentially automatically detect whether we should compile libs, or if we can just go ahead.
.PHONY: all libs test clean clean-libs
.PHONY: all libs check clean clean-libs
all: bin/$(NAME)
libs: lib/obj/glfw/ lib/obj/libarchive/
test: bin/TEST_$(NAME); bin/TEST_$(NAME)
clean:
ifneq ($(wildcard bin/),)
rm -vr bin/
endif
ifneq ($(wildcard obj/),)
rm -vr obj/
endif
clean-libs:
ifneq ($(wildcard lib/obj/),)
rm -vr lib/obj/
check: bin/TEST_$(NAME); ./$<
clean:; @-$(RM) -r bin/ obj/
clean-libs:; @-$(RM) -r lib/obj/
.PHONY:
install: all
ifneq ($(OS),Windows_NT)
# TODO: POSIX-compliant installation
else
# TODO: WINDOWS_NT installation
endif
.PHONY:
install-strip: install
# TODO: strip the produced installation
# compiles the libraries using cmake
lib/obj/%/: lib/%/
$(CMAKE) -S $< -B $@
@@ -86,17 +79,18 @@ obj/res/%.c: res/%
@mkdir -p $(@D)
@cd res/ && xxd -i $(patsubst res/%,%,$<) $(abspath $@)
obj/res/%.o: obj/res/%.c
obj/%.o: %.c
$(info [CC] $@)
@mkdir -p $(@D)
@$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
obj/%.o: %.c
obj/%.o: obj/%.c
$(info [CC] $@)
@mkdir -p $(@D)
@$(CC) -c $(CPPFLAGS) $(CFLAGS) -MMD -MP -o $@ $<
@$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
# 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)
-include $(TOBJ:%.o=%.d)