-
Notifications
You must be signed in to change notification settings - Fork 32
/
Makefile
242 lines (195 loc) · 7.48 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
### toolchain
#
CC ?= gcc
PKG_CONFIG ?= pkg-config
XML2_CONFIG ?= xml2-config
LIBGCRYPT_CONFIG ?= libgcrypt-config
MKDIR = mkdir
MKDIR_P = mkdir -p
INSTALL = install
INSTALL_LIB = $(INSTALL) -m 755
INSTALL_DIR = $(INSTALL) -d -m 755
RM = rm
RM_RF = $(RM) -rf
CMAKE ?= cmake
CMAKE_FLAGS = -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS=-fPIC
### flags
#
GLIB_CFLAGS ?= $(shell $(PKG_CONFIG) --cflags glib-2.0)
GLIB_LDFLAGS ?= $(shell $(PKG_CONFIG) --libs glib-2.0)
LIBPURPLE_CFLAGS=$(shell $(PKG_CONFIG) --cflags purple)
PURPLE_DIR=$(shell $(PKG_CONFIG) --variable=plugindir purple)
LIBPURPLE_LDFLAGS=$(shell $(PKG_CONFIG) --cflags purple) \
-L$(PURPLE_DIR)
LIBOMEMO_CFLAGS = $(shell $(PKG_CONFIG) --cflags libomemo)
LIBOMEMO_LDFLAGS = $(shell $(PKG_CONFIG) --libs libomemo)
LIBAXC_CFLAGS = $(shell $(PKG_CONFIG) --cflags libaxc)
LIBAXC_LDFLAGS = $(shell $(PKG_CONFIG) --libs libaxc)
LIBSIGNAL_PROTOCOL_CFLAGS = $(shell $(PKG_CONFIG) --cflags libsignal-protocol-c)
LIBSIGNAL_PROTOCOL_LDFLAGS = $(shell $(PKG_CONFIG) --cflags libsignal-protocol-c)
XML2_CFLAGS ?= $(shell $(XML2_CONFIG) --cflags)
XML2_LDFLAGS ?= $(shell $(XML2_CONFIG) --libs)
LIBGCRYPT_LDFLAGS ?= $(shell $(LIBGCRYPT_CONFIG) --libs)
USE_DYNAMIC_LIBS=libsignal-protocol-c libaxc libomemo
USE_DYNAMIC_LIBS:=$(shell pkg-config --exists $(USE_DYNAMIC_LIBS) && \
echo '$(USE_DYNAMIC_LIBS)')
PKGCFG_C=$(GLIB_CFLAGS) \
$(LIBPURPLE_CFLAGS) \
$(XML2_CFLAGS)
ifneq ($(USE_DYNAMIC_LIBS),)
PKGCFG_C+=$(LIBOMEMO_CFLAGS) \
$(LIBAXC_CFLAGS) \
$(LIBSIGNAL_PROTOCOL_CFLAGS)
endif
PKGCFG_L=$(shell $(PKG_CONFIG) --libs sqlite3 mxml) \
$(GLIB_LDFLAGS) \
$(LIBPURPLE_LDFLAGS) \
$(XML2_LDFLAGS) \
$(LIBGCRYPT_LDFLAGS)
ifneq ($(USE_DYNAMIC_LIBS),)
PKGCFG_L+=$(LIBOMEMO_LDFLAGS) \
$(LIBAXC_LDFLAGS) \
$(LIBSIGNAL_PROTOCOL_LDFLAGS)
endif
ifneq ("$(wildcard /etc/redhat-release)","")
LJABBER= -lxmpp
else
ifneq ("$(wildcard /etc/SuSE-release)","")
LJABBER= -lxmpp
else
LJABBER= -ljabber
endif
endif
ifeq ($(USE_DYNAMIC_LIBS),)
HEADERS=-I$(HDIR)/jabber -I$(LOMEMO_SRC) -I$(AXC_SRC) -I$(AX_DIR)/src
else
HEADERS=-I$(HDIR)/jabber
endif
CFLAGS += -std=c11 -Wall -g -Wstrict-overflow $(PKGCFG_C) $(HEADERS)
PLUGIN_CPPFLAGS=-DPURPLE_PLUGINS
# -D_BSD_SOURCE can be removed once nobody uses glibc <= 2.18 any more
CPPFLAGS += -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -D_DEFAULT_SOURCE
LDFLAGS += -ldl -lm $(PKGCFG_L) $(LJABBER) -Wl,-rpath,$(PURPLE_PLUGIN_DIR)
LDFLAGS_T=$(LDFLAGS) -lpurple -lcmocka
### directories
#
PURPLE_HOME_PLUGIN_DIR=$(HOME)/.purple/plugins
PURPLE_PLUGIN_DIR = $(shell $(PKG_CONFIG) --variable=plugindir purple)
LDIR=./lib
BDIR=./build
SDIR=./src
HDIR=./headers
TDIR=./test
LOMEMO_DIR=$(LDIR)/libomemo
LOMEMO_SRC=$(LOMEMO_DIR)/src
LOMEMO_BUILD=$(LOMEMO_DIR)/build
LOMEMO_PATH=$(LOMEMO_BUILD)/libomemo-conversations.a
AXC_DIR=$(LDIR)/axc
AXC_SRC=$(AXC_DIR)/src
AXC_BUILD=$(AXC_DIR)/build
AXC_PATH=$(AXC_BUILD)/libaxc-nt.a
AX_DIR=$(AXC_DIR)/lib/libsignal-protocol-c
AX_PATH=$(AX_DIR)/build/src/libsignal-protocol-c.a
SOURCES := $(sort $(wildcard $(SDIR)/*.c))
OBJECTS := $(patsubst $(SDIR)/%.c, $(BDIR)/%.o, $(SOURCES))
OBJECTS_W_COVERAGE := $(patsubst $(SDIR)/%.c, $(BDIR)/%_w_coverage.o, $(SOURCES))
TEST_SOURCES := $(sort $(wildcard $(TDIR)/test_*.c))
TEST_OBJECTS := $(patsubst $(TDIR)/test_%.c, $(BDIR)/test_%.o, $(TEST_SOURCES))
TEST_TARGETS := $(patsubst $(TDIR)/test_%.c, $(BDIR)/test_%, $(TEST_SOURCES))
ifeq ($(USE_DYNAMIC_LIBS),)
VENDOR_LIBS=$(LOMEMO_PATH) $(AXC_PATH) $(AX_PATH)
endif
### make rules
#
all: $(BDIR)/lurch.so
$(BDIR):
$(MKDIR_P) build
$(AX_PATH):
cd $(AX_DIR)/ && \
$(MKDIR_P) build && \
cd build && \
$(CMAKE) $(CMAKE_FLAGS) .. \
&& $(MAKE)
$(AXC_PATH):
$(MAKE) -C "$(AXC_DIR)" build/libaxc-nt.a
$(LOMEMO_PATH):
$(MAKE) -C "$(LOMEMO_DIR)" build/libomemo-conversations.a
$(BDIR)/%.o: $(SDIR)/%.c | $(BDIR)
$(CC) -fPIC $(CFLAGS) $(CPPFLAGS) $(PLUGIN_CPPFLAGS) -c $(SDIR)/$*.c -o $@
$(BDIR)/%_w_coverage.o: $(SDIR)/%.c | $(BDIR)
$(CC) -O0 --coverage $(CFLAGS) $(CPPFLAGS) $(PLUGIN_CPPFLAGS) -c $(SDIR)/$*.c -o $@
$(BDIR)/test_%.o: $(TDIR)/test_%.c | $(BDIR)
$(CC) $(CFLAGS) -O0 -c $(TDIR)/test_$*.c -o $@
$(BDIR)/lurch.so: $(OBJECTS) $(VENDOR_LIBS)
$(CC) -fPIC -shared $(CFLAGS) $(CPPFLAGS) $(PLUGIN_CPPFLAGS) \
$^ \
-o $@ $(LDFLAGS)
$(BDIR)/lurch.a: $(BDIR)/lurch.o $(VENDOR_LIBS)
$(AR) rcs $@ $^
install: $(BDIR)/lurch.so
[ -e "$(DESTDIR)/$(PURPLE_PLUGIN_DIR)" ] || \
$(INSTALL_DIR) "$(DESTDIR)/$(PURPLE_PLUGIN_DIR)"
$(INSTALL_LIB) "$(BDIR)/lurch.so" "$(DESTDIR)/$(PURPLE_PLUGIN_DIR)/lurch.so"
install-home: $(BDIR)/lurch.so
[ -e "$(PURPLE_HOME_PLUGIN_DIR)" ] || \
$(INSTALL_DIR) "$(PURPLE_HOME_PLUGIN_DIR)"
$(INSTALL_LIB) "$(BDIR)/lurch.so" "$(PURPLE_HOME_PLUGIN_DIR)/lurch.so"
LURCH_VERSION ?= 0.0.0
TARBALL_DIR_NAME=lurch-$(LURCH_VERSION)
TARBALL_FILE_NAME=$(TARBALL_DIR_NAME)-src.tar.gz
tarball: | clean-all $(BDIR)
$(MKDIR) $(TARBALL_DIR_NAME)
rsync -av --progress . $(TARBALL_DIR_NAME)/ --exclude $(TARBALL_DIR_NAME)/ --exclude-from=.gitignore
-find $(TARBALL_DIR_NAME)/ -name "*.git*" -exec rm -rf "{}" \;
tar czf $(TARBALL_FILE_NAME) $(TARBALL_DIR_NAME)/
mv $(TARBALL_FILE_NAME) $(TARBALL_DIR_NAME)/
mv $(TARBALL_DIR_NAME) $(BDIR)/
$(BDIR)/test_lurch_util: $(OBJECTS_W_COVERAGE) $(VENDOR_LIBS) $(BDIR)/test_lurch_util.o
$(CC) $(CFLAGS) $(CPPFLAGS) -O0 --coverage $^ $(PURPLE_DIR)/libjabber.so.0 -o $@ $(LDFLAGS_T) \
-Wl,--wrap=purple_user_dir \
-Wl,--wrap=purple_prefs_get_bool \
-Wl,--wrap=purple_prefs_get_int \
-Wl,--wrap=purple_debug_error \
-Wl,--wrap=purple_debug_info \
-Wl,--wrap=purple_debug_misc \
-Wl,--wrap=purple_base16_encode_chunked
sh -c "set -o pipefail; $@ 2>&1 | grep -Ev ".*CRITICAL.*" | tr -s '\n'" # filter annoying and irrelevant glib output
$(BDIR)/test_lurch_api: $(OBJECTS_W_COVERAGE) $(VENDOR_LIBS) $(BDIR)/test_lurch_api.o
$(CC) $(CFLAGS) $(CPPFLAGS) -O0 --coverage $^ $(PURPLE_DIR)/libjabber.so.0 -o $@ $(LDFLAGS_T) \
-Wl,--wrap=purple_account_get_username \
-Wl,--wrap=purple_account_get_connection \
-Wl,--wrap=purple_connection_get_protocol_data \
-Wl,--wrap=purple_signal_register \
-Wl,--wrap=purple_signal_unregister \
-Wl,--wrap=purple_signal_connect \
-Wl,--wrap=purple_signal_disconnect \
-Wl,--wrap=purple_find_conversation_with_account \
-Wl,--wrap=jabber_pep_publish \
-Wl,--wrap=jabber_chat_find_by_conv \
-Wl,--wrap=jabber_iq_send \
-Wl,--wrap=axc_get_device_id \
-Wl,--wrap=axc_key_load_public_own \
-Wl,--wrap=axc_key_load_public_addr \
-Wl,--wrap=axc_session_exists_any \
-Wl,--wrap=omemo_storage_user_devicelist_retrieve \
-Wl,--wrap=omemo_storage_chatlist_delete \
-Wl,--wrap=omemo_storage_chatlist_save \
-Wl,--wrap=omemo_storage_chatlist_exists \
-Wl,--wrap=omemo_storage_user_devicelist_retrieve \
-Wl,--wrap=lurch_util_fp_get_printable
sh -c "set -o pipefail; $@ 2>&1 | grep -Ev ".*CRITICAL.*" | tr -s '\n'" # filter annoying and irrelevant glib output
$(BDIR)/test_lurch_crypto: $(OBJECTS_W_COVERAGE) $(VENDOR_LIBS) $(BDIR)/test_lurch_crypto.o
$(CC) $(CFLAGS) $(CPPFLAGS) -O0 --coverage $^ $(PURPLE_DIR)/libjabber.so.0 -o $@ $(LDFLAGS_T) \
-Wl,--wrap=axc_message_encrypt_and_serialize \
-Wl,--wrap=axc_session_exists_initiated
sh -c "set -o pipefail; $@ 2>&1 | grep -Ev ".*CRITICAL.*" | tr -s '\n'" # filter annoying and irrelevant glib output
test: $(OBJECTS_W_COVERAGE) $(VENDOR_LIBS) $(TEST_TARGETS)
coverage: test
gcovr -r . --html --html-details -o build/coverage.html
gcovr -r . -s
clean:
$(RM_RF) "$(BDIR)"
clean-all: clean
$(MAKE) -C "$(LOMEMO_DIR)" clean
$(MAKE) -C "$(AXC_DIR)" clean-all
.PHONY: clean clean-all install install-home tarball test coverage