mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-16 19:25:46 +01:00
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:
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
@@ -54,4 +54,4 @@ jobs:
|
|||||||
if: steps.cache-deps.outputs.cache-hit != 'true' && runner.os == 'Windows'
|
if: steps.cache-deps.outputs.cache-hit != 'true' && runner.os == 'Windows'
|
||||||
|
|
||||||
- run: make -j all
|
- run: make -j all
|
||||||
- run: make -j test
|
- run: make -j check
|
||||||
|
|||||||
72
Makefile
72
Makefile
@@ -1,36 +1,24 @@
|
|||||||
# Copyright (c) 2025 Quinn
|
# Copyright (c) 2025 Quinn
|
||||||
# Licensed under the MIT Licence. See LICENSE for details
|
# Licensed under the MIT Licence. See LICENSE for details
|
||||||
|
SHELL = /bin/sh
|
||||||
|
.SUFFIXES:
|
||||||
|
|
||||||
# build configuration, information about the current build process
|
|
||||||
NAME = mcaselector-lite
|
NAME = mcaselector-lite
|
||||||
DEBUG ?= 0
|
CC ?= cc
|
||||||
CC ?= cc
|
RM ?= rm -vf
|
||||||
CMAKE ?= cmake -G 'Unix Makefiles'
|
CMAKE ?= cmake -G 'Unix Makefiles'
|
||||||
|
|
||||||
# setting default compilation flags
|
CPPFLAGS ?= -DNDEBUG
|
||||||
# some of which are able to be overwritten, others are always appended
|
CFLAGS ?= -O2
|
||||||
CPPFLAGS ?=
|
|
||||||
CFLAGS ?= -O2 -Wall -Wextra -Wpedantic -Wno-pointer-arith
|
|
||||||
LDFLAGS ?= -flto
|
LDFLAGS ?= -flto
|
||||||
CPPFLAGS += -DGLFW_INCLUDE_NONE
|
CPPFLAGS += -DGLFW_INCLUDE_NONE -Iinclude -Ilib/glad/include -Ilib/glfw/include -Ilib/libarchive/libarchive
|
||||||
CFLAGS += -std=gnu99
|
CFLAGS += -std=gnu99 -g -Wall -Wextra -Wpedantic -Wno-pointer-arith -MMD -MP
|
||||||
|
|
||||||
# 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
|
|
||||||
LDFLAGS += -Llib/obj/glfw/src -Llib/obj/libarchive/libarchive
|
LDFLAGS += -Llib/obj/glfw/src -Llib/obj/libarchive/libarchive
|
||||||
LDLIBS += -lglfw3 -larchive -lm
|
LDLIBS += -lglfw3 -larchive -lm
|
||||||
|
|
||||||
# detect if we're compiling on Windows, meaning
|
# detect if we're compiling on Windows, meaning
|
||||||
# a lot of things considered "standard" are unavailable.
|
# a lot of things considered "standard" are unavailable.
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
ISWIN = 1
|
|
||||||
NAME := $(NAME).exe
|
NAME := $(NAME).exe
|
||||||
LDLIBS += -lopengl32 -lgdi32
|
LDLIBS += -lopengl32 -lgdi32
|
||||||
$(warning Detected Windows_NT, please refer to the documentation if you encounter issues.)
|
$(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
|
LDLIBS += -framework Cocoa -framework OpenGL -framework IOKit
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# TODO: find a better method to find all source files
|
|
||||||
# find all the source files using wildcards
|
# 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.
|
# NOTE: MS-DOS and MS-Windows uses backslash `\`, this might break.
|
||||||
RES := $(wildcard res/*)
|
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
|
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)
|
TSRC := $(wildcard test/*.c test/*/*.c test/*/*/*.c test/*/*/*/*.c test/*/*/*/*/*.c test/*/*/*/*/*/*.c test/*/*/*/*/*/*/*.c test/*/*/*/*/*/*/*/*.c)
|
||||||
TOBJ := $(TSRC:%.c=obj/%.o)
|
|
||||||
|
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.
|
# 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)
|
all: bin/$(NAME)
|
||||||
libs: lib/obj/glfw/ lib/obj/libarchive/
|
libs: lib/obj/glfw/ lib/obj/libarchive/
|
||||||
test: bin/TEST_$(NAME); bin/TEST_$(NAME)
|
check: bin/TEST_$(NAME); ./$<
|
||||||
clean:
|
clean:; @-$(RM) -r bin/ obj/
|
||||||
ifneq ($(wildcard bin/),)
|
clean-libs:; @-$(RM) -r lib/obj/
|
||||||
rm -vr bin/
|
|
||||||
endif
|
.PHONY:
|
||||||
ifneq ($(wildcard obj/),)
|
install: all
|
||||||
rm -vr obj/
|
ifneq ($(OS),Windows_NT)
|
||||||
endif
|
# TODO: POSIX-compliant installation
|
||||||
clean-libs:
|
else
|
||||||
ifneq ($(wildcard lib/obj/),)
|
# TODO: WINDOWS_NT installation
|
||||||
rm -vr lib/obj/
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
.PHONY:
|
||||||
|
install-strip: install
|
||||||
|
# TODO: strip the produced installation
|
||||||
|
|
||||||
# compiles the libraries using cmake
|
# compiles the libraries using cmake
|
||||||
lib/obj/%/: lib/%/
|
lib/obj/%/: lib/%/
|
||||||
$(CMAKE) -S $< -B $@
|
$(CMAKE) -S $< -B $@
|
||||||
@@ -86,17 +79,18 @@ obj/res/%.c: res/%
|
|||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
@cd res/ && xxd -i $(patsubst res/%,%,$<) $(abspath $@)
|
@cd res/ && xxd -i $(patsubst res/%,%,$<) $(abspath $@)
|
||||||
|
|
||||||
obj/res/%.o: obj/res/%.c
|
obj/%.o: %.c
|
||||||
$(info [CC] $@)
|
$(info [CC] $@)
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
@$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
|
@$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
obj/%.o: %.c
|
obj/%.o: obj/%.c
|
||||||
$(info [CC] $@)
|
$(info [CC] $@)
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
@$(CC) -c $(CPPFLAGS) $(CFLAGS) -MMD -MP -o $@ $<
|
@$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
# Include the generated dependency files.
|
# Include the generated dependency files.
|
||||||
# Which creates rules for all dependencies,
|
# Which creates rules for all dependencies,
|
||||||
# as a result updating an .o file when a .h is updated.
|
# as a result updating an .o file when a .h is updated.
|
||||||
-include $(OBJ:%.o=%.d)
|
-include $(OBJ:%.o=%.d)
|
||||||
|
-include $(TOBJ:%.o=%.d)
|
||||||
|
|||||||
Reference in New Issue
Block a user