-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
46 lines (35 loc) · 989 Bytes
/
Makefile
File metadata and controls
46 lines (35 loc) · 989 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
34
35
36
37
38
39
40
41
42
43
44
45
# Compiler
CXX := g++
CXXFLAGS := -std=c++17 -Wall -Wextra -g
# Directories
SRC_DIR := src
INCLUDE_DIR := include
BUILD_DIR := build
BIN_DIR := bin
# Output
TARGET := $(BIN_DIR)/my_program
# Find all source files recursively
SRCS := $(shell find $(SRC_DIR) -name '*.cpp')
# Generate object file names, preserving directory structure
OBJS := $(patsubst $(SRC_DIR)/%.cpp, $(BUILD_DIR)/%.o, $(SRCS))
# Find all include subdirectories
INCLUDE_PATHS := $(shell find $(INCLUDE_DIR) -type d)
# Add -I flag for each include path
CXXFLAGS += $(foreach dir, $(INCLUDE_PATHS), -I$(dir))
# Default target
all: $(TARGET)
# Link the executable
$(TARGET): $(OBJS)
@mkdir -p $(BIN_DIR)
$(CXX) $(CXXFLAGS) $^ -o $@
# Compile each source file to an object file
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -c $< -o $@
# Clean build artifacts
clean:
rm -rf $(BUILD_DIR) $(BIN_DIR)
# Rebuild everything
rebuild: clean all
# Phony targets
.PHONY: all clean rebuild