-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
35 lines (26 loc) · 794 Bytes
/
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
# Compiler and flags
CXX := g++
CXXFLAGS := -Wall -Wextra -std=c++17 -Iinclude
# Directories
SRC_DIR := src
BUILD_DIR := build
# Output binary
TARGET := $(BUILD_DIR)/output
# Source files and corresponding object files
SRCS := $(wildcard $(SRC_DIR)/*.cpp)
OBJS := $(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.o,$(SRCS))
# Rule to build the final output
all: $(TARGET)
# Linking the final executable
$(TARGET): $(OBJS) | $(BUILD_DIR)
$(CXX) $(CXXFLAGS) $(OBJS) -o $@
# Rule to compile each source file to an object file
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp | $(BUILD_DIR)
$(CXX) $(CXXFLAGS) -c $< -o $@
# Create the build directory if it doesn't exist
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Clean up the build directory and the output binary
clean:
rm -rf $(BUILD_DIR)
.PHONY: all clean