mirror of
https://github.com/thepigeongenerator/sdl_template.git
synced 2025-12-17 05:55:47 +01:00
update makefile to include colour printing, correctly dispose of all files and use the basename for the project name
This commit is contained in:
22
.vscode/launch.json
vendored
22
.vscode/launch.json
vendored
@@ -7,24 +7,14 @@
|
|||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "",
|
"program": "",
|
||||||
"linux": {
|
"linux": {
|
||||||
"program": "make",
|
"preLaunchTask": "(dbg) compile linux-x86_64",
|
||||||
"args": [
|
"program": "bin/linux-x86_64/${workspaceFolderBasename}",
|
||||||
"run"
|
"cwd": "bin/linux-x86_64/"
|
||||||
],
|
|
||||||
"env": {
|
|
||||||
"ARCH": "linux-x86_64",
|
|
||||||
"DEBUG": "1",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
"windows": {
|
"windows": {
|
||||||
"program": "make",
|
"preLaunchTask": "(dbg) compile win-x86_64",
|
||||||
"args": [
|
"program": "bin/win-x86_64/${workspaceFolderBasename}.exe",
|
||||||
"run"
|
"cwd": "bin/win-x86_64/"
|
||||||
],
|
|
||||||
"env": {
|
|
||||||
"ARCH": "win-x86_64",
|
|
||||||
"DEBUG": "1",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
15
.vscode/tasks.json
vendored
Normal file
15
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "(dbg) compile linux-x86_64",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "DEBUG=1 make linux-x86_64",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "(dbg) compile win-x86_64",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "DEBUG=1 make win-x86_64",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
25
makefile
25
makefile
@@ -1,4 +1,4 @@
|
|||||||
NAME := sdl_template
|
NAME := $(shell basename $(PWD))
|
||||||
|
|
||||||
# compiler settings
|
# compiler settings
|
||||||
CC := clang
|
CC := clang
|
||||||
@@ -8,7 +8,7 @@ CFLAGS := $(shell pkg-config --cflags sdl2) -Wall -Wextra -Wpedantic -Wno-pointe
|
|||||||
LDFLAGS := $(shell pkg-config --libs sdl2) -lm
|
LDFLAGS := $(shell pkg-config --libs sdl2) -lm
|
||||||
|
|
||||||
ifeq ($(DEBUG),1)
|
ifeq ($(DEBUG),1)
|
||||||
CFLAGS += -Og -g
|
CFLAGS += -DDEBUG -Og -g
|
||||||
else
|
else
|
||||||
REL_FLAGS += -O3
|
REL_FLAGS += -O3
|
||||||
endif
|
endif
|
||||||
@@ -29,6 +29,9 @@ DEP := $(OBJ:.o=.d)
|
|||||||
ASSETS := $(patsubst assets/%,$(DIR_BUILD)/%,$(SRC_ASSETS))
|
ASSETS := $(patsubst assets/%,$(DIR_BUILD)/%,$(SRC_ASSETS))
|
||||||
TARGET := $(DIR_BUILD)/$(NAME)$(EXT)
|
TARGET := $(DIR_BUILD)/$(NAME)$(EXT)
|
||||||
|
|
||||||
|
define wr_colour
|
||||||
|
@echo -e "\033[$(2)m$(1)\033[0m"
|
||||||
|
endef
|
||||||
|
|
||||||
# sets the variables for the different targets
|
# sets the variables for the different targets
|
||||||
linux-x86_64:
|
linux-x86_64:
|
||||||
@@ -38,18 +41,14 @@ win-x86_64:
|
|||||||
web:
|
web:
|
||||||
@$(MAKE) _build ARCH=web CC=emcc EXT=".html"
|
@$(MAKE) _build ARCH=web CC=emcc EXT=".html"
|
||||||
|
|
||||||
# execute the binary
|
|
||||||
run: $(ARCH)
|
|
||||||
cd $(DIR_BUILD) && ./$(NAME)$(EXT)
|
|
||||||
|
|
||||||
all: linux-x86_64 win-x86_64 web
|
all: linux-x86_64 win-x86_64 web
|
||||||
_build: $(DIR) $(TARGET) $(ASSETS) compile_commands.json
|
_build: compile_commands.json $(DIR) $(TARGET) $(ASSETS)
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(DIR_BIN) $(DIR_OBJ)
|
rm -rf $(DIR_BIN) $(DIR_OBJ) compile_commands.json
|
||||||
|
|
||||||
# create the binary
|
# create the binary
|
||||||
$(TARGET): $(OBJ)
|
$(TARGET): $(OBJ)
|
||||||
@echo "using arguments: $(CFLAGS) $(LDFLAGS)"
|
@$(call wr_colour,"using arguments: $(CFLAGS) $(LDFLAGS)",94)
|
||||||
@$(CC) -o $(TARGET) $^ $(CFLAGS) $(LDFLAGS)
|
@$(CC) -o $(TARGET) $^ $(CFLAGS) $(LDFLAGS)
|
||||||
|
|
||||||
# create .o and .d files
|
# create .o and .d files
|
||||||
@@ -69,11 +68,15 @@ $(DIR):
|
|||||||
# update compile commands if the makefile has been updated (for linting)
|
# update compile commands if the makefile has been updated (for linting)
|
||||||
ifeq ($(DEBUG),1)
|
ifeq ($(DEBUG),1)
|
||||||
compile_commands.json: makefile
|
compile_commands.json: makefile
|
||||||
|
@$(call wr_colour,"compiling in debug mode",93)
|
||||||
|
$(MAKE) clean
|
||||||
|
@touch compile_commands.json
|
||||||
|
bear -- make
|
||||||
else
|
else
|
||||||
compile_commands.json: makefile
|
compile_commands.json: makefile
|
||||||
@touch compile_commands.json
|
@$(call wr_colour,"compiling in non-debug mode",93)
|
||||||
$(MAKE) clean
|
$(MAKE) clean
|
||||||
bear -- make
|
@touch compile_commands.json
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# include the dependencies
|
# include the dependencies
|
||||||
|
|||||||
Reference in New Issue
Block a user