-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
66 lines (51 loc) · 1.39 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
CXX = g++
CPPFLAGS += -Wall -Wextra -Werror
# sadly, it does warn about designated initializers
# (despite what is stated in docs)
CPPFLAGS += -Wno-missing-field-initializers
#CPPFLAGS += -DSPDLOG_FMT_EXTERNAL
CXXFLAGS += -std=c++17 -O3 -flto
LDFLAGS += -lboost_program_options$(BOOST_SUFFIX) -lfmt
DISABLE_LIB ?=
NAME = megumi
SRCS = $(wildcard $(addsuffix /*.cpp,. model block))
OBJS = $(SRCS:.cpp=.o)
LIB_SRCS = $(filter-out ./main.cpp,$(SRCS))
LIB_OBJS = $(LIB_SRCS:.cpp=.o)
ifeq ($(OS),Windows_NT)
LDFLAGS += -lws2_32
EXE_LDFLAGS += -Wl,--enable-auto-import
LIB_LDFLAGS += -Wl,--out-implib,$(TARGET_LIB).a -Wl,--export-all-symbols
LIB_EXT = .dll
EXE_EXT = .exe
else
EXE_EXT =
LIB_EXT = .so
endif
ifneq ($(PREFIX),)
CPPFLAGS += -I$(PREFIX)/include
LDFLAGS += -L$(PREFIX)/lib
endif
TARGET_EXE = $(NAME)$(EXE_EXT)
ifeq ($(DISABLE_LIB),)
TARGET_LIB = $(NAME)$(LIB_EXT)
TARGET_EXE_OBJS = $(TARGET_LIB)
CXXFLAGS += -fPIC
else
TARGET_LIBS =
TARGET_EXE_OBJS = $(LIB_OBJS)
endif
.PHONY: default all clean
default: $(TARGET_EXE)
all: $(TARGET_LIB) $(TARGET_EXE)
-include $(OBJS:.o=.d)
$(TARGET_EXE): $(TARGET_EXE_OBJS) main.o
$(CXX) main.o $(TARGET_EXE_OBJS) -o $@ $(LDFLAGS) $(EXE_LDFLAGS)
ifeq ($(DISABLE_LIB),)
$(TARGET_LIB): $(LIB_OBJS)
$(CXX) $(LIB_OBJS) -o $@ -shared $(LDFLAGS) $(LIB_LDFLAGS)
endif
%.o: %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -c $< -o $@
clean:
rm -f $(TARGET) $(OBJS) $(OBJS:.o=.d)