mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-16 21:05:46 +01:00
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.
This commit is contained in:
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
|
||||||
137
Makefile
137
Makefile
@@ -1,102 +1,83 @@
|
|||||||
# 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 = bash
|
|
||||||
.SHELLFLAGS = -O globstar -c
|
|
||||||
|
|
||||||
# build configuration, information about the current build process
|
# build configuration, information about the current build process
|
||||||
NAME = mcaselector-lite
|
NAME = mcaselector-lite
|
||||||
VERSION = 0.0.0
|
|
||||||
DEBUG ?= 0
|
DEBUG ?= 0
|
||||||
CC ?= cc
|
CC ?= cc
|
||||||
LD ?= ld
|
LD ?= ld
|
||||||
|
|
||||||
# compilation flags
|
# setting default compilation flags
|
||||||
CFLAGS += -c -std=gnu99 -Wall -Wextra -Wpedantic -MMD -MP
|
# some of which are able to be overwritten, others are always appended
|
||||||
LDFLAGS += -flto
|
CPPFLAGS ?=
|
||||||
|
CFLAGS ?= -O2 -Wall -Wextra -Wpedantic
|
||||||
|
LDFLAGS ?= -flto
|
||||||
|
CFLAGS += -std=gnu99
|
||||||
|
|
||||||
# architecture/OS detection
|
# add a few extra flags depending on whether
|
||||||
ifeq ($(KERNEL),)
|
# we're debugging or not
|
||||||
ISWIN := $(if $(filter $(OS),Windows_NT),1,0)
|
ifeq ($(DEBUG),0)
|
||||||
ifeq ($(ISWIN),1)
|
CPPFLAGS += -DNDEBUG
|
||||||
KERNEL = mingw
|
|
||||||
MARCH = x86_64
|
|
||||||
else
|
else
|
||||||
MARCH := $(shell uname -m)
|
CFLAGS += -fsanitize=address -ftrapv -g
|
||||||
KERNEL := $(shell uname -s | tr '[:upper:]' '[:lower:]')
|
LDFLAGS += -fsanitize=address -ftrapv
|
||||||
endif
|
endif
|
||||||
else
|
CPPFLAGS += -Iinclude -Ilib/glad/include -Ilib/glfw/include -Ilib/libarchive/libarchive
|
||||||
ISWIN := $(if $(filter $(KERNEL),mingw),1,0)
|
LDFLAGS += -Lobj/lib/glfw/src -Lobj/lib/libarchive/libarchive
|
||||||
endif
|
LDLIBS += -lm -lglfw -larchive
|
||||||
ifeq ($(MARCH),)
|
|
||||||
$(error must also set MARCH when manually setting KERNEL)
|
# 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
|
endif
|
||||||
|
|
||||||
# profiles
|
# TODO: find a better method to find all source files
|
||||||
ifeq ($(DEBUG),1)
|
# find all the source files using wildcards
|
||||||
PROF = dbg
|
# NOTE: MS-DOS and MS-Windows uses backslash `\`, this might break.
|
||||||
CFLAGS += -UNDEBUG -Og -g -Wextra -Wpedantic
|
RES := $(wildcard res/*)
|
||||||
CFLAGS += $(if $(filter 1,$(ISWIN)),,-fsanitize=address,undefined) -ftrapv
|
SRC := $(wildcard src/*.c src/*/*.c src/*/*/*.c src/*/*/*/*.c src/*/*/*/*/*.c src/*/*/*/*/*/*.c src/*/*/*/*/*/*/*.c src/*/*/*/*/*/*/*/*.c) lib/glad/gl.c
|
||||||
LDFLAGS += $(if $(filter 1,$(ISWIN)),,-fsanitize=address,undefined) -ftrapv
|
OBJ := $(SRC:%.c=obj/%.o) $(RES:%=obj/%.o)
|
||||||
# |--profile: testing
|
TSRC := $(wildcard test/*.c test/*/*.c test/*/*/*.c test/*/*/*/*.c test/*/*/*/*/*.c test/*/*/*/*/*/*.c test/*/*/*/*/*/*/*.c test/*/*/*/*/*/*/*/*.c)
|
||||||
else ifeq ($(DEBUG),test)
|
TOBJ := $(TSRC:%.c=obj/%.o)
|
||||||
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
|
.PHONY: all test clean libs
|
||||||
LDFLAGS += $(shell pkg-config --libs glfw3 libarchive) -lm
|
all: bin/$(NAME)
|
||||||
|
libs: obj/lib/glfw/ obj/lib/libarchive/
|
||||||
# get source files
|
test: bin/TEST_$(NAME); bin/TEST_$(NAME)
|
||||||
SRC := $(shell echo src/**/*.c) lib/glad/src/gl.c
|
|
||||||
RES := $(wildcard res/*.glsl)
|
|
||||||
ifeq ($(DEBUG),test)
|
|
||||||
SRC := $(filter-out src/main.c, $(SRC)) $(shell echo test/**/*.c)
|
|
||||||
endif
|
|
||||||
|
|
||||||
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:
|
|
||||||
clean:
|
clean:
|
||||||
@[ -d obj/ ] && rm -rv obj/ || true
|
@[ -d bin/ ] && rm -vr bin/ || true
|
||||||
@[ -d bin/ ] && rm -rv bin/ || true
|
@[ -d obj/ ] && rm -vr obj/ || true
|
||||||
|
|
||||||
$(BIN): $(OBJ)
|
# compiles the libraries using cmake
|
||||||
$(info [CC/LD] $@)
|
obj/lib/%/: lib/%/
|
||||||
@mkdir -p $(@D)
|
cmake -S $< -B $@
|
||||||
@$(CC) -o $@ $^ $(LDFLAGS)
|
$(MAKE) -C $@
|
||||||
|
|
||||||
$(DIR_OBJ)/%.o: %.c
|
# link together a runtime binary
|
||||||
$(info [CC] $@)
|
bin/$(NAME): libs $(OBJ)
|
||||||
|
$(info [CC/LD] $@)
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
@$(CC) $(CFLAGS) -o $@ $<
|
@$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
|
||||||
|
|
||||||
$(DIR_OBJ)/res/%.o: res/%
|
# link together a testing binary
|
||||||
$(info [LD] $@)
|
bin/TEST_$(NAME): $(TOBJ) $(filter-out main.o,$(OBJ))
|
||||||
|
$(info [CC/LD] $@)
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
|
@$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
|
||||||
|
|
||||||
|
obj/res/%.o: res/%
|
||||||
|
$(info [LD] $@)
|
||||||
@$(LD) -r -b binary -o $@ $<
|
@$(LD) -r -b binary -o $@ $<
|
||||||
|
|
||||||
# some definitions for "default" and assumed compilers, for bulk selection
|
obj/%.o: %.c
|
||||||
.PHONY: x86_64-linux-gnu-gcc x86_64-w64-mingw32-gcc
|
$(info [CC] $@)
|
||||||
x86_64-linux-gnu-gcc:; $(MAKE) $(CALL) $(MAKEFLAGS) CC=$@ MARCH=x86_64 KERNEL=linux
|
@mkdir -p $(@D)
|
||||||
x86_64-w64-mingw32-gcc:; $(MAKE) $(CALL) $(MAKEFLAGS) CC=$@ MARCH=x86_64 KERNEL=mingw
|
@$(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)
|
||||||
|
|||||||
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
Reference in New Issue
Block a user