-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
33 lines (24 loc) · 748 Bytes
/
makefile
File metadata and controls
33 lines (24 loc) · 748 Bytes
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
# Compiler and flags
CPP := g++
CPPFLAGS := -std=c++17 -Isrc -Isrc/lib
# CPPFLAGS := -std=c++17 -Wall -Wextra -Isrc -Isrc/lib
# Directories
SRC_DIR := src
BUILD_DIR := build
# Files
EXECUTABLE := program
SRC_FILES := $(wildcard $(SRC_DIR)/*.cpp) $(wildcard $(SRC_DIR)/lib/**/*.cpp)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.o,$(SRC_FILES))
# Targets
all: $(BUILD_DIR) $(EXECUTABLE)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(EXECUTABLE): $(OBJ_FILES)
$(CPP) $(CPPFLAGS) -o $@ $^
# This pattern rule generates object files in the correct directory
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(dir $@)
$(CPP) $(CPPFLAGS) -c -o $@ $<
clean:
rm -rf $(BUILD_DIR) $(EXECUTABLE)
.PHONY: all clean