mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 05:55:46 +01:00
make heavy changes to makefile
- clean when makefile changes (ang generate compile_commands.json) - better handling for directory dependencies - reorganise code more - add dependency tracking so it triggers recompiles on header file changes
This commit is contained in:
8
.vscode/tasks.json
vendored
8
.vscode/tasks.json
vendored
@@ -48,14 +48,6 @@
|
|||||||
"isDefault": false
|
"isDefault": false
|
||||||
},
|
},
|
||||||
"detail": "builds the program for web using emscripten"
|
"detail": "builds the program for web using emscripten"
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "create compile_commands.json",
|
|
||||||
"type": "shell",
|
|
||||||
"command": "bear -- make",
|
|
||||||
"runOptions": {
|
|
||||||
"runOn": "folderOpen"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
32
makefile
32
makefile
@@ -8,9 +8,12 @@ LDFLAGS = $(shell pkg-config --libs sdl2) -lm
|
|||||||
# file locations
|
# file locations
|
||||||
DIR_BIN := bin
|
DIR_BIN := bin
|
||||||
DIR_OBJ := obj
|
DIR_OBJ := obj
|
||||||
SRC = $(wildcard src/*.c) $(wildcard src/**/*.c) $(wildcard src/**/**/*.c) $(wildcard src/**/**/**/*.c) $(wildcard src/**/**/**/**/*.c)
|
DIR := $(DIR_BIN)/$(ARCH) $(DIR_OBJ)/$(ARCH)
|
||||||
OBJ = $(patsubst src/%,$(DIR_OBJ)/$(ARCH)/%,$(SRC:.c=.o))
|
|
||||||
TARGET = $(DIR_BIN)/$(ARCH)/$(NAME)$(EXT)
|
SRC := $(wildcard src/*.c) $(wildcard src/**/*.c) $(wildcard src/**/**/*.c) $(wildcard src/**/**/**/*.c) $(wildcard src/**/**/**/**/*.c)
|
||||||
|
OBJ := $(patsubst src/%,$(DIR_OBJ)/$(ARCH)/%,$(SRC:.c=.o))
|
||||||
|
DEP := $(OBJ:.o=.d)
|
||||||
|
TARGET := $(DIR_BIN)/$(ARCH)/$(NAME)$(EXT)
|
||||||
|
|
||||||
# sets the variables for the different targets
|
# sets the variables for the different targets
|
||||||
linux-x86_64:
|
linux-x86_64:
|
||||||
@@ -21,21 +24,26 @@ web:
|
|||||||
$(MAKE) build ARCH=web CC=emcc EXT=".html"
|
$(MAKE) build ARCH=web CC=emcc EXT=".html"
|
||||||
|
|
||||||
all: linux-x86_64 win-x86_64 web
|
all: linux-x86_64 win-x86_64 web
|
||||||
|
build: $(DIR) $(TARGET) compile_commands.json
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(DIR_BIN) $(DIR_OBJ)
|
rm -rf $(DIR_BIN) $(DIR_OBJ)
|
||||||
|
|
||||||
build: dirs binary
|
|
||||||
|
|
||||||
# creates the binary
|
# creates the binary
|
||||||
binary: $(OBJ)
|
$(TARGET): $(OBJ)
|
||||||
$(CC) -o $(TARGET) $^ $(CFLAGS) $(LDFLAGS)
|
$(CC) -o $(TARGET) $^ $(CFLAGS) $(LDFLAGS)
|
||||||
|
|
||||||
# creates the object files, include a flag for no unused command line arguments, because in this context it's unneeded
|
# creates .o and .d files, include a flag for no unused command line arguments, because in this context it's unneeded
|
||||||
$(DIR_OBJ)/$(ARCH)/%.o: src/%.c
|
$(DIR_OBJ)/$(ARCH)/%.o: src/%.c
|
||||||
mkdir -p $(dir $@)
|
mkdir -p $(dir $@)
|
||||||
$(CC) -o $@ -c $< $(CFLAGS) $(LDFLAGS) -Wno-unused-command-line-argument
|
$(CC) -o $@ -MD -MP -c $< $(CFLAGS) -Wno-unused-command-line-argument
|
||||||
|
|
||||||
dirs:
|
$(DIR):
|
||||||
mkdir -p $(DIR_BIN)/$(ARCH)
|
mkdir -p $@
|
||||||
mkdir -p $(DIR_OBJ)/$(ARCH)
|
|
||||||
|
# update compile commands if the makefile has been updated (for linting)
|
||||||
|
compile_commands.json: makefile
|
||||||
|
touch compile_commands.json
|
||||||
|
$(MAKE) clean
|
||||||
|
bear -- make
|
||||||
|
|
||||||
|
-include $(DEP)
|
||||||
|
|||||||
Reference in New Issue
Block a user