-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
129 lines (99 loc) · 3.21 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# @copyright MbientLab License
.PHONY: build clean doc publish install
VERSION_MK=version.mk
ifndef SKIP_VERSION
$(shell ./bin/generate_version.sh $(VERSION_MK))
endif
include config.mk
include $(VERSION_MK)
CXXFLAGS:=-std=c++14 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Werror -DWARBLE_DLL -DWARBLE_DLL_EXPORT -Isrc
DEPS_BLEPP:=deps/libblepp
MODULES_SRC_DIR= $(addsuffix /cpp, $(addprefix src/, $(MODULES)))
GEN:=
SRCS:=$(foreach src_dir, $(MODULES_SRC_DIR), $(shell find $(src_dir) -name \*.cpp))
EXPORT_HEADERS:=$(foreach module, $(addprefix src/, $(MODULES)), $(shell find $(module) -maxdepth 1 -name \*.h))
ifeq ($(CONFIG),debug)
CXXFLAGS+=-g
LD_FLAGS:=-g
else ifeq ($(CONFIG),release)
CXXFLAGS+=-O3
LD_FLAGS:=-s
else
$(error Invalid value for "CONFIG", must be 'release' or 'debug')
endif
LD_FLAGS+=-shared -Wl,
ifneq ($(KERNEL),Darwin)
EXTENSION:=so
LIB_SO_NAME:=lib$(APP_NAME).so
LD_FLAGS:=$(LD_FLAGS)--soname
CXXFLAGS+= -DAPI_BLEPP -I$(DEPS_BLEPP)
else
EXTENSION:=dylib
LD_FLAGS:=-dynamiclib $(LD_FLAGS)-install_name
endif
ifeq ($(MACHINE),x86)
ARCH=-m32
INSTALL_LIB?=lib
else ifeq ($(MACHINE),x64)
ARCH=-m64
INSTALL_LIB?=lib64
else ifeq ($(MACHINE),arm)
ARCH=-marm
INSTALL_LIB?=lib
else
$(error Unrecognized "MACHINE" value, use 'x86', 'x64', or 'arm')
endif
ifndef NO_MULTILIB
CXXFLAGS+=$(ARCH)
else
ARCH=
endif
LIB_SO_NAME:=lib$(APP_NAME).$(EXTENSION)
LIB_SHORT_NAME:=$(LIB_SO_NAME).$(VERSION_MAJOR)
LIB_NAME:=$(LIB_SO_NAME).$(VERSION)
LD_FLAGS:=$(LD_FLAGS),$(LIB_SHORT_NAME) $(ARCH)
REAL_DIST_DIR:=$(DIST_DIR)/$(CONFIG)/lib/$(MACHINE)
REAL_BUILD_DIR:=$(BUILD_DIR)/$(MACHINE)/$(CONFIG)
MODULES_BUILD_DIR:=$(addprefix $(REAL_BUILD_DIR)/, $(MODULES_SRC_DIR))
OBJS:=$(addprefix $(REAL_BUILD_DIR)/,$(SRCS:%.cpp=%.o))
DEPS:=$(OBJS:%.o=%.d)
APP_OUTPUT:=$(REAL_DIST_DIR)/$(LIB_NAME)
build: $(APP_OUTPUT)
install: $(APP_OUTPUT)
cp -P $(REAL_DIST_DIR)/* $(INSTALL_PATH)/$(INSTALL_LIB)
install -d $(INSTALL_PATH)/include/$(APP_NAME)
install -m644 -D $(EXPORT_HEADERS) $(INSTALL_PATH)/include/$(APP_NAME)
$(REAL_BUILD_DIR)/%.o: %.cpp
$(CXX) -MMD -MP -MF "$(@:%.o=%.d)" -c -o $@ $(CXXFLAGS) $<
include $(addsuffix /config.mk, $(MODULES_SRC_DIR))
-include $(DEPS)
$(MODULES_BUILD_DIR):
mkdir -p $@
$(REAL_DIST_DIR):
mkdir -p $@
$(OBJS): | $(MODULES_BUILD_DIR)
$(APP_OUTPUT): $(OBJS) $(DEPS_BLEPP)/libble++.a | $(REAL_DIST_DIR)
$(CXX) -o $@ $(LD_FLAGS) $^ -lbluetooth -lpthread
ln -sf $(LIB_NAME) $(REAL_DIST_DIR)/$(LIB_SHORT_NAME)
ln -sf $(LIB_SHORT_NAME) $(REAL_DIST_DIR)/$(LIB_SO_NAME)
PUBLISH_NAME:=$(APP_NAME)-$(VERSION).tar
PUBLISH_NAME_ZIP:=$(PUBLISH_NAME).gz
publish: $(DIST_DIR)/$(PUBLISH_NAME_ZIP)
$(DIST_DIR)/$(PUBLISH_NAME_ZIP): $(BUILD_DIR)/$(PUBLISH_NAME)
gzip --stdout $< > $@
$(BUILD_DIR)/$(PUBLISH_NAME): build
tar -cf $@ --transform 's,src,include,' $(EXPORT_HEADERS)
tar -rf $@ -C $(DIST_DIR) .
clean:
rm -Rf $(BUILD_DIR) $(DIST_DIR) $(GEN)
cleanest: clean
make clean -C $(DEPS_BLEPP)
rm $(DEPS_BLEPP)/Makefile
doc:
rm -Rf $(DOC_DIR)
mkdir $(DOC_DIR)
doxygen Doxyfile
$(DEPS_BLEPP)/libble++.a: $(DEPS_BLEPP)/Makefile
make -C $(DEPS_BLEPP) -j
$(DEPS_BLEPP)/Makefile:
cd $(DEPS_BLEPP); LDFLAGS=$(ARCH) ./configure