-
Notifications
You must be signed in to change notification settings - Fork 16
/
Makefile
144 lines (117 loc) · 3.22 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
.PNONY: all clean cleanall testall fmt
INCLUDE :=
#---------
TARGET ?= silly
TLS ?= ON
TEST ?= OFF
MALLOC ?= jemalloc
SRC_PATH = silly-src
LIB_PATH = lualib-src
#-----------platform
include Platform.mk
all:
#-----------library
#####lua
LUA_DIR=deps/lua
LUA_INC=$(LUA_DIR)
LUA_STATICLIB=$(LUA_DIR)/liblua.a
$(LUA_STATICLIB):
make -C $(LUA_DIR) $(LUA_PLAT) MYCFLAGS=-g
#####malloc lib select
ifeq ($(MALLOC), jemalloc)
JEMALLOC_DIR=deps/jemalloc
JEMALLOC_INC=$(JEMALLOC_DIR)/include
MALLOC_LIB:=$(JEMALLOC_DIR)/lib/$(LIBPREFIX)jemalloc.$(A)
$(MALLOC_LIB):$(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
INCLUDE += -I $(JEMALLOC_INC)
all:$(MALLOC_LIB)
else
CFLAGS += -DDISABLE_JEMALLOC
MALLOC_LIB :=
endif
#tls disable
ifeq ($(TLS), ON)
TLSFLAG := -DUSE_OPENSSL -lssl -lcrypto
endif
#-----------project
LUACLIB_PATH ?= luaclib
INCLUDE += -I $(LUA_INC) -I $(SRC_PATH)
SRC_FILE = \
main.c \
silly_socket.c \
silly_queue.c \
silly_worker.c \
silly_timer.c \
silly_signal.c \
silly_run.c \
silly_daemon.c \
silly_malloc.c \
silly_log.c \
silly_trace.c \
silly_monitor.c \
pipe.c \
event.c \
SRC = $(addprefix $(SRC_PATH)/, $(SRC_FILE))
OBJS = $(patsubst %.c,%.o,$(SRC))
LIB_SRC = lualib-core.c \
lualib-env.c \
lualib-time.c \
lualib-metrics.c \
lualib-logger.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: \
fmt \
$(TARGET) \
$(LUACLIB_PATH)/core.$(SO) \
$(LUACLIB_PATH)/zproto.$(SO) \
$(LUACLIB_PATH)/http2.$(SO) \
$(LUACLIB_PATH)/pb.$(SO) \
$(LUACLIB_PATH)/test.$(SO) \
$(TARGET):$(OBJS) $(LUA_STATICLIB) $(MALLOC_LIB)
$(LD) -o $@ $^ $(LDFLAGS)
$(LUACLIB_PATH):
mkdir $(LUACLIB_PATH)
$(LUACLIB_PATH)/core.$(SO): $(addprefix $(LIB_PATH)/, $(LIB_SRC)) | $(LUACLIB_PATH)
$(CC) $(CFLAGS) $(INCLUDE) -o $@ $^ $(SHARED) $(TLSFLAG)
$(LUACLIB_PATH)/zproto.$(SO): $(LIB_PATH)/zproto/lzproto.c $(LIB_PATH)/zproto/zproto.c | $(LUACLIB_PATH)
$(CC) $(CFLAGS) $(INCLUDE) -o $@ $^ $(SHARED)
$(LUACLIB_PATH)/http2.$(SO): $(LIB_PATH)/lualib-http2.c | $(LUACLIB_PATH)
$(CC) $(CFLAGS) $(INCLUDE) -o $@ $^ $(SHARED)
$(LUACLIB_PATH)/pb.$(SO): $(LIB_PATH)/pb.c | $(LUACLIB_PATH)
$(CC) $(CFLAGS) $(INCLUDE) -DPB_IMPLEMENTATION -o $@ $^ $(SHARED)
$(LUACLIB_PATH)/test.$(SO): $(LIB_PATH)/lualib-test.c | $(LUACLIB_PATH)
$(CC) $(CFLAGS) $(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) $(CFLAGS) $(INCLUDE) -c -o $@ $<
testall:
make TEST=ON all
./$(TARGET) test/test.lua --lualib_path="test/?.lua"
clean:
-rm $(SRC:.c=.o) *.so $(TARGET)
-rm -rf $(LUACLIB_PATH)
-rm .depend
-rm $(SRC_PATH)/*.lib
cleanall: clean
make -C $(LUA_DIR) clean
ifneq (,$(wildcard $(JEMALLOC_DIR)/Makefile))
make -C $(JEMALLOC_DIR) clean rm $(JEMALLOC_DIR)/Makefile
endif
fmt:
-clang-format -i silly-src/*.h
-clang-format -i silly-src/*.c
-clang-format -i lualib-src/lua*.c