-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
65 lines (48 loc) · 1.59 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
56
57
58
59
60
61
62
63
64
65
CXX := g++
CXXFLAGS :=
MACROS :=
INC :=
LIBS := -fopenmp -lpthread -lm -lgmp -lgmpxx -lstdc++fs -lmpfr -pthread
DEFFLAGS := -g -std=c++17 -Wall -fdiagnostics-color=always $(LIBS) $(MACROS) $(INC)
DBGFLAGS := -Og -fno-omit-frame-pointer -fno-inline-functions \
-fno-inline-functions-called-once -fno-optimize-sibling-calls \
-fno-default-inline -fno-inline -pg -DDEBUG
RLSFLAGS := -march=native -frename-registers -funroll-loops
QUIFLAGS := -DQUIET
OPT := 3
OBJDIR := build
DEPDIR := deps
BINDIR := bin
NAME := $(BINDIR)/util
SRC := $(shell ./findsrc.py main.cc)
OBJ := $(SRC:%.cc=$(OBJDIR)/%.o)
DEP := $(SRC:%.cc=$(DEPDIR)/%.d)
override CXX := $(shell command -v ccache 2>/dev/null) $(CXX)
override CXXFLAGS := $(CXXFLAGS) $(DEFFLAGS)
.PHONY: clean reset
default: all
all: release
release: CXXFLAGS += $(RLSFLAGS) -O$(OPT)
release: $(NAME)
debug: CXXFLAGS += $(DBGFLAGS)
debug: $(NAME)
quiet: CXXFLAGS += $(QUIFLAGS)
quiet: $(NAME)
$(DEPDIR)/%.d: %.cc
@mkdir -p $(shell dirname $(shell readlink -m -- $(@)))
@$(CXX) -MM -MT $(@:$(DEPDIR)/%.d=$(OBJDIR)/%.o) -MF $(@) $(<) $(CXXFLAGS)
$(OBJDIR)/%.o: %.cc $(DEPDIR)/%.d
@mkdir -p $(shell dirname $(shell readlink -m -- $(@)))
$(CXX) -c -o $(@) $(<) $(CXXFLAGS)
$(NAME): $(OBJ)
@mkdir -p $(shell dirname $(shell readlink -m -- $(@)))
$(CXX) $(OBJ) -o $(NAME) $(CXXFLAGS)
clean:
$(RM) $(OBJ) $(DEP) $(NAME)
reset: clean
$(RM) -r $(OBJDIR) $(DEPDIR) $(BINDIR)
ifneq ($(MAKECMDGOALS), clean)
ifneq ($(MAKECMDGOALS), reset)
-include $(DEP)
endif
endif