-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
130 lines (103 loc) · 2.9 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
.PNONY:all
INCLUDE :=
#---------
TARGET ?= silly
TLS ?= ON
#-----------platform
include Platform.mk
linux macosx: all
#-----------library
#lua
LUA_DIR=deps/lua
LUA_INC=$(LUA_DIR)
LUA_STATICLIB=$(LUA_DIR)/liblua.a
$(LUA_STATICLIB):
make -C $(LUA_DIR) $(PLAT) MYCFLAGS=-g
#malloc lib select
MALLOC_NAME=jemalloc
ifeq ($(MALLOC_NAME), jemalloc)
JEMALLOC_DIR=deps/jemalloc
JEMALLOC_INC=$(JEMALLOC_DIR)/include
JEMALLOC_STATICLIB=$(JEMALLOC_DIR)/lib/libjemalloc.a
$(JEMALLOC_STATICLIB):$(JEMALLOC_DIR)/Makefile
make -C $(JEMALLOC_DIR)
$(JEMALLOC_DIR)/Makefile:$(JEMALLOC_DIR)/autogen.sh
cd $(JEMALLOC_DIR)&&\
./autogen.sh --with-jemalloc-prefix=je_
$(JEMALLOC_DIR)/autogen.sh:
git submodule update --init
jemalloc:$(JEMALLOC_STATICLIB)
INCLUDE += -I $(JEMALLOC_INC)
MALLOC_STATICLIB := $(JEMALLOC_STATICLIB)
all:jemalloc
else
CCFLAG += -DDISABLE_JEMALLOC
MALLOC_STATICLIB :=
endif
#tls disable
ifeq ($(TLS), ON)
TLSFLAG := -DUSE_OPENSSL -lssl -lcrypto
endif
#-----------project
LUACLIB_PATH ?= luaclib
SRC_PATH = silly-src
LIB_PATH = lualib-src
INCLUDE += -I $(LUA_INC) -I $(SRC_PATH)
SRC_FILE = \
main.c \
silly_socket.c \
silly_queue.c \
silly_worker.c \
silly_timer.c \
silly_run.c \
silly_daemon.c \
silly_env.c \
silly_malloc.c \
silly_log.c \
silly_monitor.c \
SRC = $(addprefix $(SRC_PATH)/, $(SRC_FILE))
OBJS = $(patsubst %.c,%.o,$(SRC))
LIB_SRC = lualib-silly.c \
lualib-profiler.c \
lualib-netstream.c \
lualib-netpacket.c \
lualib-tls.c \
lualib-crypto.c lsha1.c aes.c sha256.c md5.c\
lualib-debugger.c\
all: \
$(TARGET) \
$(LUACLIB_PATH)/sys.so \
$(LUACLIB_PATH)/zproto.so \
$(LUACLIB_PATH)/http2.so \
$(LUACLIB_PATH)/test.so \
$(TARGET):$(OBJS) $(LUA_STATICLIB) $(MALLOC_STATICLIB)
$(LD) -o $@ $^ $(LDFLAG)
$(LUACLIB_PATH):
mkdir $(LUACLIB_PATH)
$(LUACLIB_PATH)/sys.so: $(addprefix $(LIB_PATH)/, $(LIB_SRC)) | $(LUACLIB_PATH)
$(CC) $(CCFLAG) $(INCLUDE) -o $@ $^ $(SHARED) $(TLSFLAG)
$(LUACLIB_PATH)/zproto.so: $(LIB_PATH)/zproto/lzproto.c $(LIB_PATH)/zproto/zproto.c | $(LUACLIB_PATH)
$(CC) $(CCFLAG) $(INCLUDE) -o $@ $^ $(SHARED)
$(LUACLIB_PATH)/http2.so: $(LIB_PATH)/lualib-http2.c | $(LUACLIB_PATH)
$(CC) $(CCFLAG) $(INCLUDE) -o $@ $^ $(SHARED)
$(LUACLIB_PATH)/test.so: $(LIB_PATH)/lualib-test.c | $(LUACLIB_PATH)
$(CC) $(CCFLAG) $(INCLUDE) -o $@ $^ $(SHARED)
.depend:
@$(CC) $(INCLUDE) -MM $(SRC) 2>/dev/null |\
sed 's/\([^.]*\).o[: ]/$(SRC_PATH)\/\1.o $@: /g' > $@ || true
-include .depend
%.o:%.c
$(CC) $(CCFLAG) $(INCLUDE) -c -o $@ $<
test: CCFLAG += -fsanitize=address -fno-omit-frame-pointer -DSILLY_TEST
test: LDFLAG += -fsanitize=address -fno-omit-frame-pointer
test: $(PLATS)
./$(TARGET) test/test.conf
clean:
-rm $(SRC:.c=.o) *.so $(TARGET)
-rm -rf $(LUACLIB_PATH)
-rm .depend
cleanall: clean
make -C $(LUA_DIR) clean
ifneq (,$(wildcard $(JEMALLOC_DIR)/Makefile))
cd $(JEMALLOC_DIR)&&make clean&&rm Makefile
endif