forked from gkdr/libomemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
148 lines (117 loc) · 5.17 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
### toolchain
#
CC ?= gcc
AR ?= ar
LIBTOOL ?= libtool
MKDIR = mkdir
MKDIR_P = mkdir -p
ARCH = $(shell gcc -print-multiarch)
VER_MAJ = 0
VERSION = 0.7.1
PKG_CONFIG ?= pkg-config
GLIB_CFLAGS ?= $(shell $(PKG_CONFIG) --cflags glib-2.0)
GLIB_LDFLAGS ?= $(shell $(PKG_CONFIG) --libs glib-2.0)
SQLITE3_CFLAGS ?= $(shell $(PKG_CONFIG) --cflags sqlite3)
SQLITE3_LDFLAGS ?= $(shell $(PKG_CONFIG) --libs sqlite3)
MXML_CFLAGS ?= $(shell $(PKG_CONFIG) --cflags mxml)
MXML_LDFLAGS ?= $(shell $(PKG_CONFIG) --libs mxml)
LIBGCRYPT_CONFIG ?= libgcrypt-config
LIBGCRYPT_LDFLAGS ?= $(shell $(LIBGCRYPT_CONFIG) --libs)
SDIR = src
BDIR = build
TDIR = test
LDIR = lib
# according to https://sourceware.org/bugzilla/show_bug.cgi?id=17879
# -fno-builtin-memset is enough to make gcc not optimize it away
FILES =
PKGCFG_C=$(GLIB_CFLAGS) \
$(MXML_CFLAGS) \
$(SQLITE3_CFLAGS) \
$(LIBGCRYPT_CFLAGS)
PKGCFG_L=$(GLIB_LDFLAGS) \
$(MXML_LDFLAGS) \
$(SQLITE3_LDFLAGS) \
$(LIBGCRYPT_LDFLAGS)
CFLAGS += -std=c11 -Wall -Wextra -Wpedantic -Wstrict-overflow \
-fno-strict-aliasing -funsigned-char \
-fno-builtin-memset -g $(PKGCFG_C)
CPPFLAGS += -D_XOPEN_SOURCE=700 -D_DEFAULT_SOURCE
CFLAGS_CONVERSATIONS=$(CFLAGS) -DOMEMO_XMLNS='"eu.siacs.conversations.axolotl"' -DOMEMO_NS_SEPARATOR='"."' -DOMEMO_NS_NOVERSION
COVFLAGS = --coverage -O0 -g $(CFLAGS)
LDFLAGS += -pthread -ldl -lm $(PKGCFG_L)
TESTFLAGS = -lcmocka $(LDFLAGS)
all: $(BDIR)/libomemo-conversations.a shared
$(BDIR):
$(MKDIR_P) $@
libomemo: $(SDIR)/libomemo.c libomemo_crypto libomemo_storage $(BDIR)
$(LIBTOOL) --mode=compile $(CC) -c $(SDIR)/[email protected] $(CFLAGS) $(CPPFLAGS) -o $(BDIR)/[email protected]
$(LIBTOOL) --mode=link $(CC) -o $(BDIR)/[email protected] $(BDIR)/[email protected] $(BDIR)/$@_crypto.lo $(BDIR)/$@_storage.lo
libomemo-conversations: $(SDIR)/libomemo.c libomemo_crypto libomemo_storage $(BDIR)
$(LIBTOOL) --mode=compile $(CC) -c $(SDIR)/libomemo.c $(CFLAGS_CONVERSATIONS) -o $(BDIR)/libomemo.lo $(CPPFLAGS)
$(LIBTOOL) --mode=link $(CC) -o $(BDIR)/libomemo.la $(BDIR)/libomemo.lo $(BDIR)/libomemo_crypto.lo $(BDIR)/libomemo_storage.lo
libomemo_crypto: $(SDIR)/libomemo_crypto.c build
$(LIBTOOL) --mode=compile $(CC) -c $(SDIR)/[email protected] $(CFLAGS) $(CPPFLAGS) -o $(BDIR)/[email protected]
libomemo_storage: $(SDIR)/libomemo_storage.c build
$(LIBTOOL) --mode=compile $(CC) -c $(SDIR)/[email protected] $(CFLAGS) $(CPPFLAGS) -o $(BDIR)/[email protected]
$(BDIR)/libomemo.o: $(BDIR) $(SDIR)/libomemo.c $(SDIR)/libomemo.h
$(CC) -c $(CFLAGS) $(CPPFLAGS) $(SDIR)/libomemo.c -o $@
$(BDIR)/libomemo-conversations.o: $(SDIR)/libomemo.c $(BDIR)
$(CC) -c $(SDIR)/libomemo.c $(CFLAGS_CONVERSATIONS) $(CPPFLAGS) -fPIC -o $@
$(BDIR)/libomemo_crypto.o: $(SDIR)/libomemo_crypto.c $(BDIR)
$(CC) -c $(SDIR)/libomemo_crypto.c $(CFLAGS) $(CPPFLAGS) -fPIC -o $@
$(BDIR)/libomemo_storage.o: $(SDIR)/libomemo_storage.c $(BDIR)
$(CC) -c $(SDIR)/libomemo_storage.c $(CFLAGS) $(CPPFLAGS) -fPIC -o $@
$(BDIR)/libomemo-conversations.a: $(BDIR)/libomemo-conversations.o $(BDIR)/libomemo_crypto.o $(BDIR)/libomemo_storage.o
$(AR) rcs $@ $^
$(BDIR)/libomemo.so: $(BDIR)
$(CC) -shared $(SDIR)/libomemo.c -Wl,-soname,libomemo.so.$(VER_MAJ) \
$(SDIR)/libomemo_crypto.c $(SDIR)/libomemo_storage.c \
$(LDFLAGS) $(CPPFLAGS) -fPIC -o $@ $(CFLAGS_CONVERSATIONS)
$(BDIR)/libomemo.pc: $(BDIR)
echo 'prefix='$(PREFIX) > $@
echo 'exec_prefix=$${prefix}' >> $@
echo 'libdir=$${prefix}/lib/$(ARCH)' >> $@
echo 'includedir=$${prefix}/include' >> $@
echo 'Name: libomemo' >> $@
echo 'Version: ${VERSION}' >> $@
echo 'Description: OMEMO library for C' >> $@
echo 'Requires.private: glib-2.0' >> $@
echo 'Cflags: -I$${includedir}/libomemo' >> $@
echo 'Libs: -L$${libdir} -lomemo' >> $@
shared: $(BDIR)/libomemo.so $(BDIR)/libomemo.pc
install: $(BDIR)
install -d $(DESTDIR)/$(PREFIX)/lib/$(ARCH)/pkgconfig/
install -m 644 $(BDIR)/libomemo-conversations.a $(DESTDIR)/$(PREFIX)/lib/$(ARCH)/libomemo.a
install -m 644 $(BDIR)/libomemo.so $(DESTDIR)/$(PREFIX)/lib/$(ARCH)/libomemo.so.$(VERSION)
install -m 644 $(BDIR)/libomemo.pc $(DESTDIR)/$(PREFIX)/lib/$(ARCH)/pkgconfig/
install -d $(DESTDIR)/$(PREFIX)/include/libomemo/
install -m 644 $(SDIR)/libomemo_crypto.h $(DESTDIR)/$(PREFIX)/include/libomemo/
install -m 644 $(SDIR)/libomemo_storage.h $(DESTDIR)/$(PREFIX)/include/libomemo/
install -m 644 $(SDIR)/libomemo.h $(DESTDIR)/$(PREFIX)/include/libomemo/
.PHONY = test_libomemo.o
test_libomemo: $(TDIR)/test_libomemo.c $(SDIR)/libomemo.c
$(CC) $(COVFLAGS) $< $(FILES) -o $(TDIR)/[email protected] $(TESTFLAGS)
-$(TDIR)/[email protected]
find . -maxdepth 1 -iname 'test*.g*' -exec mv {} $(TDIR) \;
.PHONY: test_crypto
test_crypto: $(TDIR)/test_crypto.c $(SDIR)/libomemo_crypto.c
$(CC) $(COVFLAGS) $< $(FILES) -o $(TDIR)/[email protected] $(TESTFLAGS)
-$(TDIR)/[email protected]
find . -maxdepth 1 -iname 'test*.g*' -exec mv {} $(TDIR) \;
.PHONY: test_storage
test_storage: $(TDIR)/test_storage.c $(SDIR)/libomemo_storage.c
$(CC) $(COVFLAGS) $< $(FILES) -o $(TDIR)/[email protected] $(TESTFLAGS)
-$(TDIR)/[email protected]
find . -maxdepth 1 -iname 'test*.g*' -exec mv {} $(TDIR) \;
.PHONY: test
test : test_libomemo test_crypto test_storage
.PHONY: coverage
coverage: test
gcovr -r . --html --html-details -o [email protected]
gcovr -r . -s
$(MKDIR_P) $@
mv $@.* $@
.PHONY: clean
clean:
rm -rf build coverage
rm -f $(TDIR)/*.sqlite $(TDIR)/*.o $(TDIR)/*.gcno $(TDIR)/*.gcda