-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
33 lines (25 loc) · 702 Bytes
/
Makefile
File metadata and controls
33 lines (25 loc) · 702 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
CXX = g++
CXXFLAGS = -Wall -Wextra -c
# Directories
SRCDIR = src
OBJDIR = obj
# Find all source files recursively
SOURCES = $(shell find $(SRCDIR) -type f -name "*.cpp")
# Convert source paths to object file names in obj/
OBJECTS = $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(SOURCES))
# Output Executable
TARGET = main
# Default rule: Build the program
all: $(TARGET)
# Link all object files into final executable
$(TARGET): $(OBJECTS)
$(CXX) -Wall -Wextra -o $@ $^
# Compile each source file into obj/ without subdirectories
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $< -o $@
# Clean compiled files
clean:
rm -rf $(OBJDIR) $(TARGET)
rm -rf reports