forked from alliedtelesis/apteryx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
101 lines (86 loc) · 3.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
# Makefile for Apteryx
#
# Unit Tests (make test FILTER): e.g make test Performance
# Requires GLib and CUnit for Unit Testing.
# sudo apt-get install libglib2.0-dev libcunit1-dev liblua5.2-dev
#
# TEST_WRAPPER="G_SLICE=always-malloc valgrind --leak-check=full" make test
# TEST_WRAPPER="gdb" make test
#
ifneq ($(V),1)
Q=@
endif
DESTDIR?=./
PREFIX?=/usr/
LIBDIR?=lib
CC:=$(CROSS_COMPILE)gcc
LD:=$(CROSS_COMPILE)ld
PKG_CONFIG ?= pkg-config
ABI_VERSION=4
CFLAGS := $(CFLAGS) -g -O2
EXTRA_CFLAGS += -Wall -Wno-comment -std=c99 -D_GNU_SOURCE -fPIC
EXTRA_CFLAGS += -I. $(shell $(PKG_CONFIG) --cflags glib-2.0)
EXTRA_LDFLAGS := $(shell $(PKG_CONFIG) --libs glib-2.0) -lpthread
ifneq ($(HAVE_LUA),no)
LUAVERSION := $(shell $(PKG_CONFIG) --exists lua5.3 && echo lua5.3 ||\
($(PKG_CONFIG) --exists lua5.2 && echo lua5.2 ||\
($(PKG_CONFIG) --exists lua && echo lua ||\
echo none)))
ifneq ($(LUAVERSION),none)
EXTRA_CFLAGS += -DHAVE_LUA $(shell $(PKG_CONFIG) --cflags $(LUAVERSION))
EXTRA_LDFLAGS += $(shell $(PKG_CONFIG) --libs $(LUAVERSION)) -ldl
endif
endif
ifneq ($(HAVE_TESTS),no)
EXTRA_CSRC += test.c
EXTRA_CFLAGS += -DTEST
EXTRA_LDFLAGS += -lcunit
endif
all: libapteryx.so apteryx apteryxd
libapteryx.so.$(ABI_VERSION): rpc.o rpc_transport.o rpc_socket.o apteryx.o lua.o
@echo "Creating library "$@""
$(Q)$(CC) -shared $(LDFLAGS) -o $@ $^ $(EXTRA_LDFLAGS) -Wl,-soname,$@
libapteryx.so: libapteryx.so.$(ABI_VERSION)
@ln -s -f $@.$(ABI_VERSION) $@
@ln -s -f $@ apteryx.so
%.o: %.c
@echo "Compiling "$<""
$(Q)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
apteryxd: apteryxd.c hashtree.c database.c rpc.o rpc_transport.o rpc_socket.o config.o callbacks.o
@echo "Building $@"
$(Q)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -o $@ $^ $(EXTRA_LDFLAGS)
apteryx: apteryxc.c hashtree.c database.c callbacks.c libapteryx.so $(EXTRA_CSRC)
@echo "Building $@"
$(Q)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -o $@ $^ -L. -lapteryx $(EXTRA_LDFLAGS)
apteryxd = \
if test -e /tmp/apteryxd.pid; then \
kill -TERM `cat /tmp/apteryxd.pid` && sleep 0.1; \
fi; \
rm -f /tmp/apteryxd.pid; \
rm -f /tmp/apteryxd.run; \
LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):./ ./apteryxd -b -p /tmp/apteryxd.pid -r /tmp/apteryxd.run && sleep 0.1; \
LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):./ $(TEST_WRAPPER) ./$(1); \
kill -TERM `cat /tmp/apteryxd.pid`;
ifeq (test,$(firstword $(MAKECMDGOALS)))
TEST_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(TEST_ARGS):;@:)
endif
test: apteryxd apteryx
@echo "Running apteryx unit test: $<"
$(Q)$(call apteryxd,apteryx -u$(TEST_ARGS))
@echo "Tests have been run!"
install: all
@install -d $(DESTDIR)/$(PREFIX)/$(LIBDIR)
@install -D libapteryx.so.$(ABI_VERSION) $(DESTDIR)/$(PREFIX)/$(LIBDIR)/
@ln -sf libapteryx.so.$(ABI_VERSION) $(DESTDIR)/$(PREFIX)/$(LIBDIR)/libapteryx.so
@install -d $(DESTDIR)/$(PREFIX)/include
@install -D apteryx.h $(DESTDIR)/$(PREFIX)/include
@install -d $(DESTDIR)/$(PREFIX)/bin
@install -D apteryxd $(DESTDIR)/$(PREFIX)/bin/
@install -D apteryx $(DESTDIR)/$(PREFIX)/bin/
@install -d $(DESTDIR)/$(PREFIX)/lib/pkgconfig
@install -D apteryx.pc $(DESTDIR)/$(PREFIX)/lib/pkgconfig/
clean:
@echo "Cleaning..."
@rm -f libapteryx.so* apteryx.so apteryx apteryxd *.o
.PHONY: all clean