-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
55 lines (43 loc) · 1.16 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
# Compiler and compiler flags
CXX := g++
CXXFLAGS := -std=c++20 -Wall -Wextra -pedantic -I./src -I/usr/include/boost
DEBUG_CXXFLAGS := $(CXXFLAGS) \
-g3 \
-ggdb \
-O0 \
-fsanitize=address,undefined \
-fno-inline \
-fvar-tracking \
-ftrapv \
-fno-eliminate-unused-debug-types \
-fdiagnostics-color=auto
# Directories
SRCDIR := src
BUILDDIR := build
BINDIR := bin
# Source files and headers
HEADERS := $(shell find $(SRCDIR) -type f -name "*.h")
SOURCES := $(shell find $(SRCDIR) -type f -name "*.cpp")
# Object files
OBJECTS := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SOURCES))
# Executable
EXECUTABLE := $(BINDIR)/gcp
INPUT_FILE :=
# Targets
all: $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
@mkdir -p $(BINDIR)
$(CXX) $(CXXFLAGS) -o $@ $^ -lboost_program_options
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp $(HEADERS)
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -c -o $@ $<
debug: CXXFLAGS := $(DEBUG_CXXFLAGS)
debug: all
@if [ -z "$(INPUT_FILE)" ]; then \
echo "Usage: make debug INPUT_FILE=<input_file>"; \
else \
gdb -ex "break main" -ex "layout src" -ex run --args $(EXECUTABLE) --input $(INPUT_FILE); \
fi
clean:
@rm -rf $(BUILDDIR) $(BINDIR)
.PHONY: all clean debug