-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathMakefile
More file actions
115 lines (91 loc) · 3.72 KB
/
Copy pathMakefile
File metadata and controls
115 lines (91 loc) · 3.72 KB
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
OUT=webdis
HIREDIS_OBJ?=src/hiredis/hiredis.o src/hiredis/sds.o src/hiredis/net.o src/hiredis/async.o src/hiredis/read.o src/hiredis/dict.o src/hiredis/alloc.o src/hiredis/sockcompat.o
JANSSON_OBJ?=src/jansson/src/dump.o src/jansson/src/error.o src/jansson/src/hashtable.o src/jansson/src/hashtable_seed.o src/jansson/src/load.o src/jansson/src/memory.o src/jansson/src/pack_unpack.o src/jansson/src/strbuffer.o src/jansson/src/strconv.o src/jansson/src/utf.o src/jansson/src/value.o
B64_OBJS?=src/b64/cencode.o
FORMAT_OBJS?=src/formats/json.o src/formats/raw.o src/formats/common.o src/formats/custom-type.o
HTTP_PARSER_OBJS?=src/http-parser/http_parser.o
CFLAGS ?= -std=c99 -Wall -Wextra -Isrc -Isrc/jansson/src -Isrc/http-parser -MD -D_POSIX_C_SOURCE=200809L -Wno-pragmas
LDFLAGS ?= -levent -pthread
# Pass preprocessor macros to the compile invocation
CFLAGS += $(CPPFLAGS)
# check for MessagePack via pkg-config (msgpack-c on newer releases, msgpack on older)
PKG_CONFIG ?= pkg-config
ifneq ($(MSGPACK),0)
MSGPACK_PC := $(shell command -v $(PKG_CONFIG) >/dev/null 2>&1 && \
(($(PKG_CONFIG) --exists msgpack-c 2>/dev/null && echo msgpack-c) || \
(($(PKG_CONFIG) --exists msgpack 2>/dev/null && echo msgpack))))
ifneq ($(strip $(MSGPACK_PC)),)
MSGPACK_DETECTED_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(MSGPACK_PC))
MSGPACK_DETECTED_LIBS := $(shell $(PKG_CONFIG) --libs $(MSGPACK_PC))
MSGPACK_ENABLED := 1
endif
endif
ifeq ($(MSGPACK),1)
ifeq ($(strip $(MSGPACK_PC)$(MSGPACK_LIBS)),)
$(error MSGPACK=1 requires msgpack to be found by pkg-config, or MSGPACK_LIBS to be set)
endif
MSGPACK_ENABLED := 1
endif
ifeq ($(MSGPACK_ENABLED),1)
FORMAT_OBJS += src/formats/msgpack.o
CFLAGS += -DMSGPACK=1 $(MSGPACK_DETECTED_CFLAGS) $(MSGPACK_CFLAGS)
LDFLAGS += $(MSGPACK_DETECTED_LIBS) $(MSGPACK_LIBS)
endif
# if `make` is run with DEBUG=1, include debug symbols
DEBUG_FLAGS=
ifeq ($(DEBUG),1)
DEBUG_FLAGS += -O0
ifeq ($(shell cc -v 2>&1 | grep -cw 'gcc version'),1) # GCC used: add GDB debugging symbols
DEBUG_FLAGS += -ggdb3
else ifeq ($(shell gcc -v 2>&1 | grep -cw 'clang version'),1) # Clang used: add LLDB debugging symbols
DEBUG_FLAGS += -g3 -glldb
endif
else
DEBUG_FLAGS += -O3
endif
CFLAGS += $(DEBUG_FLAGS)
# if `make` is run with SSL=1, include hiredis SSL support
ifeq ($(SSL),1)
HIREDIS_OBJ += src/hiredis/ssl.o
CFLAGS += -DHAVE_SSL=1
LDFLAGS += -lssl -lcrypto
ifneq (, $(shell which brew)) # Homebrew
CFLAGS += -I$(shell brew --prefix)/opt/openssl/include
LDFLAGS += -L$(shell brew --prefix)/opt/openssl/lib
endif
# On Ubuntu and Alpine, LDFLAGS are enough since the SSL headers are under /usr/include/openssl
endif
OBJS_DEPS=$(wildcard *.d)
DEPS=$(FORMAT_OBJS) $(HIREDIS_OBJ) $(JANSSON_OBJ) $(HTTP_PARSER_OBJS) $(B64_OBJS)
OBJS=src/webdis.o src/cmd.o src/worker.o src/slog.o src/server.o src/acl.o src/md5/md5.o src/sha1/sha1.o src/http.o src/client.o src/websocket.o src/pool.o src/conf.o $(DEPS)
PREFIX ?= /usr/local
CONFDIR ?= $(DESTDIR)/etc
SELF_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
INSTALL_DIRS = $(DESTDIR)$(PREFIX) \
$(DESTDIR)$(PREFIX)/bin \
$(CONFDIR)
all: $(OUT) Makefile
$(OUT): $(OBJS) Makefile
$(CC) -o $(OUT) $(OBJS) $(LDFLAGS)
%.o: %.c %.h Makefile
$(CC) -c $(CFLAGS) -o $@ $<
%.o: %.c Makefile
$(CC) -c $(CFLAGS) -o $@ $<
$(INSTALL_DIRS):
mkdir -p $@
clean:
rm -f $(OBJS) $(OUT) $(OBJS_DEPS)
find "$(SELF_DIR)" -name '*.d' -delete
install: $(OUT) $(INSTALL_DIRS)
cp $(OUT) $(DESTDIR)$(PREFIX)/bin
cp webdis.prod.json $(CONFDIR)
WEBDIS_PORT ?= 7379
test_all: test perftest
test:
python3 tests/basic.py
python3 tests/limits.py
./tests/pubsub -p $(WEBDIS_PORT)
perftest:
# This is a performance test that requires apache2-utils and curl
./tests/bench.sh
-include $(OBJS:.o=.d)