-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
42 lines (33 loc) · 814 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
36
37
38
39
40
41
42
# Compiler
CC := g++
# Directories
SRCDIR := source
BUILDDIR := build
OBJDIR := $(BUILDDIR)/objects
BINDIR := $(BUILDDIR)/bin
# Files
SRCS := $(wildcard $(SRCDIR)/*.cpp)
OBJS := $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
EXEC := $(BINDIR)/run
# Compiler flags
CFLAGS := -I$(SRCDIR)/headers -g -Wall -Wextra -pedantic -std=c++17
# Default target
all: $(EXEC)
# Rule to build the executable
$(EXEC): $(OBJS)
@mkdir -p $(BINDIR)
$(CC) $^ -o $@ $(LDFLAGS)
# Rule to compile source files
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
@mkdir -p $(OBJDIR)
$(CC) $(CFLAGS) -c $< -o $@
# Clean target
clean:
rm -rf $(BUILDDIR)
# Dependency generation
DEPS := $(OBJS:.o=.d)
-include $(DEPS)
# Generate dependencies
$(OBJDIR)/%.d: $(SRCDIR)/%.cpp
@mkdir -p $(OBJDIR)
@$(CC) $(CFLAGS) -MM -MT '$(OBJDIR)/$*.o' $< > $@