-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
59 lines (47 loc) · 1.26 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Pre-compiler and Compiler flags
CXX_FLAGS := -Wall -Wextra -std=c++17 -ggdb
PRE_FLAGS := -MMD -MP
# Project directory structure
BIN := bin
SRC := src
LIB := lib
INC := include
MAINFILE := $(SRC)/main.cpp
# Build directories and output
TARGET := $(BIN)/main
BUILD := build
# Library search directories and flags
EXT_LIB :=
LDFLAGS = -lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi
LDPATHS := $(addprefix -L,$(LIB) $(EXT_LIB))
# Include directories
INC_DIRS := $(INC) $(shell find $(SRC) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
# Construct build output and dependency filenames
SRCS := $(shell find $(SRC) -name *.cpp)
OBJS := $(subst $(SRC)/,$(BUILD)/,$(addsuffix .o,$(basename $(SRCS))))
DEPS := $(OBJS:.o=.d)
# Run task
run: build
@echo "🚀 Executing..."
./$(TARGET) $(ARGS)
# Build task
build: clean all
# Main task
all: $(TARGET)
# Task producing target from built files
$(TARGET): $(OBJS)
@echo "🚧 Building..."
mkdir -p $(dir $@)
$(CXX) $(OBJS) -o $@ $(LDPATHS) $(LDFLAGS)
# Compile all cpp files
$(BUILD)/%.o: $(SRC)/%.cpp
mkdir -p $(dir $@)
$(CXX) $(CXX_FLAGS) $(PRE_FLAGS) $(INC_FLAGS) -c -o $@ $< $(LDPATHS) $(LDFLAGS)
# Clean task
.PHONY: clean
clean:
@echo "🧹 Clearing..."
rm -rf build
# Include all dependencies
-include $(DEPS)