-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
executable file
·81 lines (58 loc) · 1.87 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
79
80
81
#!/usr/bin/make -f
CC := clang
CXX := clang++
PKG_CONFIG_LIBS := opencv libjpeg
BIN_D = bin
OUT_D = build
CFLAGS += -DUSE_CLANG_COMPLETER -Wall -Wextra #-Wl,--no-as-needed
CXXFLAGS += $(CFLAGS)
PKG_CFLAGS := $(shell pkg-config --cflags $(PKG_CONFIG_LIBS))
CFLAGS += $(filter-out --std=c99, ${PKG_CFLAGS})
CXXFLAGS += $(filter-out --std-c++11, ${PKG_CFLAGS})
CFLAGS += -x c -std=c11
CXXFLAGS += -x c++ -std=c++11 -stdlib=libc++
LDFLAGS += -lstdc++
LDFLAGS += $(shell pkg-config --libs --static $(PKG_CONFIG_LIBS))
TARGETS = $(addprefix $(BIN_D)/, server client)
OBJS_C = $(patsubst %.c, $(OUT_D)/%.o, $(wildcard *.c))
OBJS_CPP = $(patsubst %.cpp, $(OUT_D)/%.o, $(wildcard *.cpp))
OBJS_CEXT = $(patsubst %.c, $(OUT_D)/%.o, $(wildcard $(addprefix ext/, $(EXT_CDEPS))/*.c))
OBJS = $(OBJS_C) $(OBJS_CPP) $(OBJS_CEXT)
OBJS_ = $(filter-out $(patsubst $(BIN_D)/%, $(OUT_D)/%.o, $(TARGETS)), $(OBJS))
# ^ non-targets; files without main methods
HEADERS_C = $(wildcard *.h)
HEADERS_CPP = $(wildcard *.hpp)
HEADERS_CEXT = $(wildcard $(addprefix ext/, $(EXT_CDEPS))/*.h)
HEADERS = $(HEADERS_C) $(HEADERS_CPP) $(HEADERS_CEXT)
# util
RM = /bin/rm
.DEFAULT: default
.PHONY: all clean
.PRECIOUS: $(OBJS_)
default: $(TARGETS)
all: default
$(TARGETS): $(BIN_D)/%: $(OUT_D)/%.o $(OBJS_)
$(CXX) -o $@ \
$(LDFLAGS) \
$?
$(OBJS_C): $(OUT_D)/%.o: %.c $(HEADERS)
$(CC) -c $< -o $@ \
$(CFLAGS)
$(OBJS_CPP): $(OUT_D)/%.o: %.cpp $(HEADERS)
$(CXX) -c $< -o $@ \
$(CXXFLAGS)
$(OBJS_CEXT): $(OUT_D)/%.o: %.c $(HEADERS_CEXT)
@mkdir -p $(dir $@)
$(CC) -c $< -o $@ \
$(CFLAGS)
clean:
@echo 'cleaning...'
@printf '\t'
@find $(OUT_D) -mindepth 1 \
-type f -not -iname '.gitkeep' \
-printf '%P ' -delete
@find $(BIN_D) -mindepth 1 \
-type f -not -iname '.gitkeep' \
-printf '%P ' -delete
@printf '\n'
@echo 'done!'