mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 05:55:46 +01:00
update makefile to be similar to the one in the template
This commit is contained in:
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@@ -2,20 +2,30 @@
|
||||
"version": "2.0.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "(lldb) C Launch",
|
||||
"name": "(lldb) debug project",
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"program": "",
|
||||
"linux": {
|
||||
"program": "${workspaceFolder}/bin/linux-x86_64/tetris_clone",
|
||||
"preLaunchTask": "build linux-x86_64"
|
||||
"program": "make",
|
||||
"args": [
|
||||
"run"
|
||||
],
|
||||
"env": {
|
||||
"ARCH": "linux-x86_64",
|
||||
"DEBUG": "1",
|
||||
},
|
||||
},
|
||||
"windows": {
|
||||
"program": "${workspaceFolder}/bin/win-x86_64/sdl_template",
|
||||
"preLaunchTask": "build win-x86_64"
|
||||
"program": "make",
|
||||
"args": [
|
||||
"run"
|
||||
],
|
||||
"env": {
|
||||
"ARCH": "win-x86_64",
|
||||
"DEBUG": "1",
|
||||
},
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}",
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
58
.vscode/tasks.json
vendored
58
.vscode/tasks.json
vendored
@@ -1,58 +0,0 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"options": {
|
||||
"env": {
|
||||
"DEBUG": "1"
|
||||
}
|
||||
},
|
||||
"tasks": [
|
||||
{
|
||||
"type": "shell",
|
||||
"label": "build linux-x86_64",
|
||||
"command": "make",
|
||||
"args": [
|
||||
"linux-x86_64"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"detail": "builds the program for linux x86_64"
|
||||
},
|
||||
{
|
||||
"type": "shell",
|
||||
"label": "build win-x86_64",
|
||||
"command": "make",
|
||||
"args": [
|
||||
"win-x86_64"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": false
|
||||
},
|
||||
"detail": "builds the program for windows x86_64"
|
||||
},
|
||||
{
|
||||
"type": "shell",
|
||||
"label": "build web",
|
||||
"command": "make",
|
||||
"args": [
|
||||
"web"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": false
|
||||
},
|
||||
"detail": "builds the program for web using emscripten"
|
||||
}
|
||||
]
|
||||
}
|
||||
49
makefile
49
makefile
@@ -13,45 +13,68 @@ else
|
||||
REL_FLAGS += -O3
|
||||
endif
|
||||
|
||||
# file locations
|
||||
# dirs
|
||||
DIR_BIN := bin
|
||||
DIR_OBJ := obj
|
||||
DIR_BUILD := $(DIR_BIN)/$(ARCH)
|
||||
DIR := $(DIR_BIN)/$(ARCH) $(DIR_OBJ)/$(ARCH)
|
||||
|
||||
# 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))
|
||||
DEP := $(OBJ:.o=.d)
|
||||
TARGET := $(DIR_BIN)/$(ARCH)/$(NAME)$(EXT)
|
||||
ASSETS := $(patsubst assets/%,$(DIR_BUILD)/%,$(SRC_ASSETS))
|
||||
TARGET := $(DIR_BUILD)/$(NAME)$(EXT)
|
||||
|
||||
|
||||
# sets the variables for the different targets
|
||||
linux-x86_64:
|
||||
$(MAKE) build ARCH=linux-x86_64 CFLAGS="$(CFLAGS) -target x86_64-pc-linux-gnu"
|
||||
@$(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"
|
||||
@$(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"
|
||||
@$(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
|
||||
build: $(DIR) $(TARGET) compile_commands.json
|
||||
_build: $(DIR) $(TARGET) $(ASSETS) compile_commands.json
|
||||
clean:
|
||||
rm -rf $(DIR_BIN) $(DIR_OBJ)
|
||||
|
||||
# creates the binary
|
||||
# create the binary
|
||||
$(TARGET): $(OBJ)
|
||||
$(CC) -o $(TARGET) $^ $(CFLAGS) $(LDFLAGS)
|
||||
@echo "using arguments: $(CFLAGS) $(LDFLAGS)"
|
||||
@$(CC) -o $(TARGET) $^ $(CFLAGS) $(LDFLAGS)
|
||||
|
||||
# creates .o and .d files, include a flag for no unused command line arguments, because in this context it's unneeded
|
||||
# create .o and .d files
|
||||
$(DIR_OBJ)/$(ARCH)/%.o: src/%.c
|
||||
mkdir -p $(dir $@)
|
||||
$(CC) -o $@ -MD -MP -c $< $(CFLAGS) -std=$(STD) -x $(LANG) -Wno-unused-command-line-argument
|
||||
@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 $< $@
|
||||
|
||||
# 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
|
||||
touch compile_commands.json
|
||||
else
|
||||
compile_commands.json: makefile
|
||||
@touch compile_commands.json
|
||||
$(MAKE) clean
|
||||
bear -- make
|
||||
endif
|
||||
|
||||
# include the dependencies
|
||||
-include $(DEP)
|
||||
|
||||
Reference in New Issue
Block a user