sync config files with template

This commit is contained in:
2025-03-22 11:15:53 +01:00
parent bd904b5e32
commit d44e99ade5
6 changed files with 284 additions and 70 deletions

View File

@@ -1,30 +1,41 @@
# dependencies:
# - make
# - clang
# - bear (debug)
# - sdl2
# - git bash (windows)
#
# project name = the workspace directory name
NAME := $(shell basename $(PWD))
# compiler settings
CC := clang
STD := c17
LANG = c
CFLAGS := $(shell pkg-config --cflags sdl2 SDL2_ttf) -Wall -Wextra -Wpedantic -Wno-pointer-arith
LDFLAGS := $(shell pkg-config --libs sdl2 SDL2_ttf) -lm
CFLAGS := $(shell pkg-config --cflags sdl2) -Wall -Wextra -Wpedantic -Wno-pointer-arith
LDFLAGS := $(shell pkg-config --libs sdl2) -lm
DEBUG ?= 0
ifeq ($(DEBUG),1)
CFLAGS += -DDEBUG -Og -g
CFLAGS += -DDEBUG -fsanitize=address,undefined -g -Og
PROF := dbg
else
REL_FLAGS += -O3
REL_FLAGS += -O2
PROF := rel
endif
# dirs
DIR_BIN := bin
DIR_OBJ := obj
DIR_BUILD := $(DIR_BIN)/$(ARCH)
DIR := $(DIR_BIN)/$(ARCH) $(DIR_OBJ)/$(ARCH)
DIR_BUILD := $(DIR_BIN)/$(ARCH)/$(PROF)
DIR := $(DIR_BIN)/$(ARCH)/$(PROF) $(DIR_OBJ)/$(ARCH)/$(PROF)
# source files
SRC := $(wildcard src/*.c) $(wildcard src/**/*.c) $(wildcard src/**/**/*.c) $(wildcard src/**/**/**/*.c) $(wildcard src/**/**/**/**/*.c)
SRC_ASSETS := $(wildcard assets/*)
# output locations
OBJ := $(patsubst src/%,$(DIR_OBJ)/$(ARCH)/%,$(SRC:.c=.o))
OBJ := $(patsubst src/%,$(DIR_OBJ)/$(ARCH)/$(PROF)/%,$(SRC:.c=.o))
DEP := $(OBJ:.o=.d)
ASSETS := $(patsubst assets/%,$(DIR_BUILD)/%,$(SRC_ASSETS))
TARGET := $(DIR_BUILD)/$(NAME)$(EXT)
@@ -33,50 +44,55 @@ define wr_colour
@echo -e "\033[$(2)m$(1)\033[0m"
endef
# sets the variables for the different targets
linux-x86_64:
@$(MAKE) _build ARCH=linux-x86_64 CFLAGS="$(CFLAGS) -target x86_64-pc-linux-gnu"
win-x86_64:
@$(MAKE) _build ARCH=win-x86-64 CFLAGS="$(CFLAGS) -target x86_64-pc-windows-gnu" EXT=".exe"
web:
@$(MAKE) _build ARCH=web CC=emcc EXT=".html"
# set the correct environment variables depending on the platform
ifeq ($(ARCH),linux-x86_64)
CFLAGS += -target x86_64-pc-linux-gnu
else ifeq ($(ARCH),win-x86_64)
CFLAGS += -target x86_64-pc-windows-gnu
EXT=.exe
else
$(error you must set the ARCH environment variable to one of these: 'linux-x86_64' 'win-x86_64')
endif
all: linux-x86_64 win-x86_64 web
_build: compile_commands.json $(DIR) $(TARGET) $(ASSETS)
# compiles and execute the binary
run: compile
./$(TARGET)
compile: compile_commands.json $(DIR) $(TARGET) $(ASSETS)
clean:
rm -rf $(DIR_BIN) $(DIR_OBJ) compile_commands.json
# create the binary
# create the binary (linking step)
$(TARGET): $(OBJ)
@$(call wr_colour,"using arguments: $(CFLAGS) $(LDFLAGS)",94)
@$(call wr_colour,"CC: '$(CC)'",94)
@$(call wr_colour,"CFLAGS: '$(CFLAGS)'",94)
@$(call wr_colour,"LDFLAGS: '$(LDFLAGS)'",94)
@$(call wr_colour,"linking to: '$@'",92)
@$(CC) -o $(TARGET) $^ $(CFLAGS) $(LDFLAGS)
@$(call wr_colour,"current profile: '$(PROF)'",93)
# create .o and .d files
$(DIR_OBJ)/$(ARCH)/%.o: src/%.c
$(DIR_OBJ)/$(ARCH)/$(PROF)/%.o: src/%.c
@$(call wr_colour,"compiling $(notdir $@) from $(notdir $<)",92)
@mkdir -p $(dir $@)
@$(CC) -o $@ -MD -MP -c $< $(CFLAGS) -std=$(STD) -x $(LANG) -Wno-unused-command-line-argument
# copy assets
$(DIR_BUILD)/%: assets/%
@mkdir -p $(dir $@)
cp $< $@
cp -v $< $@
# create directories
$(DIR):
@mkdir -p $@
mkdir -p $@
# update compile commands if the makefile has been updated (for linting)
ifeq ($(DEBUG),1)
compile_commands.json: makefile
@$(call wr_colour,"compiling in debug mode",93)
$(MAKE) clean
@touch compile_commands.json
bear -- make
bear -- make compile
else
compile_commands.json: makefile
@$(call wr_colour,"compiling in non-debug mode",93)
$(MAKE) clean
@touch compile_commands.json
compile_commands.json:
endif
# include the dependencies