allow makefile to execute the program, changed arguments to be environment variable based

This commit is contained in:
2025-03-13 14:27:11 +01:00
parent 9d1c63d635
commit 7fef5742cf

View File

@@ -6,6 +6,7 @@ STD := c17
LANG = c LANG = c
CFLAGS := $(shell pkg-config --cflags sdl2) -Wall -Wextra -Wpedantic -Wno-pointer-arith CFLAGS := $(shell pkg-config --cflags sdl2) -Wall -Wextra -Wpedantic -Wno-pointer-arith
LDFLAGS := $(shell pkg-config --libs sdl2) -lm LDFLAGS := $(shell pkg-config --libs sdl2) -lm
DEBUG ?= 0
ifeq ($(DEBUG),1) ifeq ($(DEBUG),1)
CFLAGS += -DDEBUG -fsanitize=address,undefined -g -Og CFLAGS += -DDEBUG -fsanitize=address,undefined -g -Og
@@ -35,16 +36,23 @@ define wr_colour
@echo -e "\033[$(2)m$(1)\033[0m" @echo -e "\033[$(2)m$(1)\033[0m"
endef endef
# sets the variables for the different targets # set the correct environment variables depending on the platform
linux-x86_64: ifeq ($(ARCH),linux-x86_64)
@$(MAKE) _build ARCH=$@ CFLAGS="$(CFLAGS) -target x86_64-pc-linux-gnu" CFLAGS += -target x86_64-pc-linux-gnu
win-x86_64: else ifeq ($(ARCH),win-x86_64)
@$(MAKE) _build ARCH=$@ CFLAGS="$(CFLAGS) -target x86_64-pc-windows-gnu" EXT=".exe" CFLAGS += -target x86_64-pc-windows-gnu
web: EXT=.exe
@$(MAKE) _build ARCH=$@ CC=emcc EXT=".html" else ifeq ($(ARCH),web)
CC=emcc
EXT=.html
else
$(error you must set the ARCH environment variable to either 'linux-x86_64', 'win-x86_64' or 'web')
endif
all: linux-x86_64 win-x86_64 web # compiles and execute the binary
_build: compile_commands.json $(DIR) $(TARGET) $(ASSETS) run: compile
./$(TARGET)
compile: compile_commands.json $(DIR) $(TARGET) $(ASSETS)
clean: clean:
rm -rf $(DIR_BIN) $(DIR_OBJ) compile_commands.json rm -rf $(DIR_BIN) $(DIR_OBJ) compile_commands.json
@@ -77,11 +85,9 @@ ifeq ($(DEBUG),1)
compile_commands.json: makefile compile_commands.json: makefile
$(MAKE) clean $(MAKE) clean
@touch compile_commands.json @touch compile_commands.json
bear -- make $(ARCH) bear -- make compile
else else
compile_commands.json: makefile compile_commands.json:
$(MAKE) clean
@touch compile_commands.json
endif endif
# include the dependencies # include the dependencies