-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathMakefile
68 lines (52 loc) · 1.84 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
SRCS_DIRS := $(shell find ./src/ -maxdepth 3 -type d)
TEST_SRCS_DIRS := $(shell find ./test/ -maxdepth 3 -type d)
ALL_SRCS_DIRS := $(shell find ./src/ -maxdepth 3 -type d)
ALL_SRCS_DIRS += $(shell find ./test/ -maxdepth 3 -type d)
SRCS := $(foreach dir,$(SRCS_DIRS),$(wildcard $(dir)/*.cpp))
TEST_SRCS := $(foreach dir,$(SRCS_DIRS),$(wildcard $(dir)/*.cpp))
ALL_SRCS := $(foreach dir,$(ALL_SRCS_DIRS),$(wildcard $(dir)/*.cpp))
MAKEROOT = $(shell pwd)
OBJ_DIR = $(MAKEROOT)/obj
DEP_DIR = $(MAKEROOT)/dep
OBJS = $(patsubst %.cpp, $(OBJ_DIR)/%.o, $(notdir $(SRCS)))
TEST_OBJS = $(patsubst %.cpp, $(OBJ_DIR)/%.o, $(notdir $(TEST_SRCS)))
ALL_OBJS = $(patsubst %.cpp, $(OBJ_DIR)/%.o, $(notdir $(ALL_SRCS)))
DEPS = $(patsubst %.o, $(DEP_DIR)/%.d, $(notdir $(ALL_OBJS)))
CC = g++
INCLUDES = -Iinclude \
-Itest \
-I.
LIBS = -lcurl -lpthread
CCFLAGS = -g -Wall -O0 -fPIC
OUTPUT = nacos-cli.out
OUTLIB1 = libnacos-cli.so
OUTLIB2 = libnacos-cli.a
vpath %.cpp $(ALL_SRCS_DIRS)
all :$(DEPS) $(OUTPUT) $(OUTLIB1) $(OUTLIB2)
$(OUTPUT) : $(ALL_OBJS)
$(info Linking $@ ...)
@$(CC) $^ -o $@ $(INCLUDES) $(LIBS) $(CCFLAGS)
$(OUTLIB1) : $(OBJS)
$(info Linking Dynamic $@ ...)
@$(CC) $^ -o $@ $(INCLUDES) $(LIBS) $(CCFLAGS) -shared
$(OUTLIB2) : $(OBJS)
$(info Linking Static $@ ...)
ar cru $(OUTLIB2) $(OBJS)
ranlib $(OUTLIB2)
$(ALL_OBJS) : $(OBJ_DIR)/%.o : %.cpp
$(info Building $@ ...)
@mkdir -p "$(OBJ_DIR)"
@$(CC) -c $< -o $@ $(CCFLAGS) $(INCLUDES)
-include $(DEPS)
$(DEPS) : $(DEP_DIR)/%.d : %.cpp
$(info Creating $< Dependencies file ...)
@mkdir -p "$(DEP_DIR)"
@$(CC) $(CCFLAGS) $(INCLUDES) -MM -MT $(patsubst %.cpp, $(OBJ_DIR)/%.o, $(notdir $<)) -MF $@ $<
testcase : all
SRCS = $(SRCS:testcase/*.cpp)
clean:
rm -rf *.out
rm -rf *.so
rm -rf $(OBJ_DIR)
rm -rf $(DEP_DIR)
.PHONY:clean