-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
79 lines (55 loc) · 2.5 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
66
67
68
69
70
71
72
73
74
75
76
77
78
ODIR ?= obj
SDIR ?= src
OS_SDIR ?= compat
PLDIR ?= plugins
INCLUDE_DIRS = -I$(SDIR) -I$(OS_SDIR)
# python interpreter is normally set by the shebang of the scripts, but some environments don't support standard
# shebangs, and should export this variable before running scripts:
PYTHON ?=
CXX ?= g++
CXXFLAGS ?= -std=c++11 -Wall -Wextra -Wpedantic -pthread $(INCLUDE_DIRS) -include compat/compat.hpp
LDFLAGS ?= -ldl -lpthread
DEP_TARGETS ?= agent/agent.o util/util.o msa.o event/event.o event/handler.o event/dispatch.o event/timer.o input/input.o util/string.o cfg/cfg.o cmd/cmd.o log/log.o output/output.o util/var.o plugin/plugin.o
DEP_INCS = $(patsubst %.o,$(SDIR)/%.hpp,$(DEP_TARGETS))
DEP_OBJS = $(patsubst %,$(ODIR)/%,$(DEP_TARGETS))
DEP_SOURCES = $(patsubst %.o,%.cpp,$(DEP_TARGETS))
DEP_EXS = $(SDIR)/debug_macros.hpp
OS_DEP_TARGETS = thread/thread.o file/file.o lib/lib.o
OS_DEP_OBJS = $(patsubst %,$(ODIR)/platform/%,$(notdir $(OS_DEP_TARGETS)))
OS_DEP_SOURCES = $(patsubst %.o,platform/%.cpp,$(OS_DEP_TARGETS))
.PHONY: clean test all debug plugins clean-plugins gen-deps
all: moe-serifu plugins
debug: CXXFLAGS += -g -O0 -Werror -DDEBUG
debug: moe-serifu
test: debug
valgrind --leak-check=yes --track-origins=yes moe-serifu
clean: clean-plugins
rm -f $(ODIR)/*.o
rm -f $(patsubst %,$(ODIR)/%*.o,$(sort $(subst ./,,$(dir $(DEP_TARGETS)))))
rm -f $(ODIR)/platform/*.o
rm -f moe-serifu
gen-deps:
$(PYTHON) scripts/gendeps.py SDIR $(SDIR) $(INCLUDE_DIRS) $(patsubst %,-E%,$(DEP_EXS)) $(DEP_SOURCES) > scripts/modules.mk
$(PYTHON) scripts/gendeps.py OS_SDIR $(OS_SDIR) $(INCLUDE_DIRS) $(OS_DEP_SOURCES) -c1 > scripts/os_modules.mk
include scripts/*.mk
# ----------------- #
# Binary Recipies #
# ----------------- #
moe-serifu: $(ODIR)/main.o $(DEP_OBJS) $(OS_DEP_OBJS)
$(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS)
$(ODIR)/main.o: $(SDIR)/main.cpp $(DEP_INCS)
$(CXX) -c -o $@ $(SDIR)/main.cpp $(CXXFLAGS)
# --------- #
# Plugins #
# --------- #
clean-plugins:
rm -f $(PLDIR)/autoload/*.so
rm -f $(PLDIR)/example/*.so
rm -f $(PLDIR)/example/*.o
plugins: $(PLDIR)/autoload/example.so
$(PLDIR)/autoload/example.so: $(PLDIR)/example/example.so
cp $(PLDIR)/example/example.so $(PLDIR)/autoload/example.so
$(PLDIR)/example/example.so: $(PLDIR)/example/example.o
$(CXX) -o $@ $(PLDIR)/example/example.o -shared
$(PLDIR)/example/example.o: $(PLDIR)/example/example.cpp $(SDIR)/plugin/plugin.hpp
$(CXX) -c -o $@ $(PLDIR)/example/example.cpp -I$(SDIR) -include compat/compat.hpp -fPIC -std=c++11 -Wall -Wextra -Wpedantic