-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
171 lines (135 loc) · 4.53 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# ------------------------------------------------------------------------------
OS = $(shell uname)
APP = libevlite
VERSION = 9.9.9
PREFIX = /usr/local
# 主版本号
MAJORVER = $(firstword $(subst ., ,$(VERSION)))
# ------------------------------------------------------------------------------
# FreeBSD采用clang做为编译器
ifeq ($(OS),FreeBSD)
CC = clang
CXX = clang++
else
CC = gcc
CXX = g++
endif
#
# 编译选项
#
# USE_ATOMIC - 使用原子操作
# USE_REUSESESSION - 重用会话(提高效率)
#
# 默认选项
LFLAGS = -ggdb -lpthread
CFLAGS = -Wall -Wformat=0 -Iinclude/ -Isrc/ -Itest/ -ggdb -fPIC -O2 -DNDEBUG -D__EVENT_VERSION__=\"$(REALNAME)\" -DUSE_ATOMIC #-DUSE_REUSESESSION
CXXFLAGS = -Wall -Wformat=0 -Iinclude/ -Isrc/ -Itest/ -ggdb -fPIC -O2 -DNDEBUG -D__EVENT_VERSION__=\"$(REALNAME)\" -DUSE_ATOMIC #-DUSE_REUSESESSION
# 动态库编译选项
ifeq ($(OS),Darwin)
LIBNAME = $(APP).dylib
SONAME = $(APP).$(MAJORVER).dylib
REALNAME= $(APP).$(VERSION).dylib
SOFLAGS = -dynamiclib -Wl,-install_name,$(SONAME) -compatibility_version $(MAJORVER) -current_version $(VERSION)
else
LIBNAME = $(APP).so
SONAME = $(LIBNAME).$(MAJORVER)
REALNAME= $(LIBNAME).$(VERSION)
SOFLAGS = -shared -Wl,-soname,$(SONAME)
endif
# Linux定制参数
ifeq ($(OS),Linux)
LFLAGS = -ggdb -pthread -lrt
CFLAGS += -finline-limit=1000
CXXFLAGS+= -finline-limit=1000
endif
# ------------------------------------------------------------------------------
# 安装目录lib, include
LIBPATH = $(PREFIX)/lib
INCLUDEPATH = $(PREFIX)/include
#
# 利用git tag发布软件版本
#
#APPNAME=`git describe | awk -F- '{print $$1}'`
#VERSION=`git describe | awk -F- '{print $$2}'`
#MAJORVER=`git describe | awk -F- '{print $$2}' | awk -F. '{print $$1}'`
#
#LIBNAME=$(APPNAME).so
#SONAME=$(APPNAME).so.$(MAJORVER)
#REALNAME=$(APPNAME).so.$(VERSION)
#
# ------------------------------------------------------------------------------
OBJS = ikcp.o driver.o utils.o ephashtable.o \
epoll.o kqueue.o timer.o \
event.o \
threads.o \
message.o channel.o session.o \
network.o
# ------------------------------------------------------------------------------
all : $(REALNAME)
install : all
rm -rf $(INCLUDEPATH)/evlite
cp -a include $(INCLUDEPATH)/evlite
rm -rf $(LIBPATH)/$(REALNAME); cp $(REALNAME) $(LIBPATH)
rm -rf $(LIBPATH)/$(SONAME); ln -s $(REALNAME) $(LIBPATH)/$(SONAME)
rm -rf $(LIBPATH)/$(LIBNAME); ln -s $(REALNAME) $(LIBPATH)/$(LIBNAME)
$(REALNAME) : $(OBJS)
$(CC) $(SOFLAGS) $(LFLAGS) $^ -o $@
rm -rf $(SONAME); ln -s $@ $(SONAME)
rm -rf $(LIBNAME); ln -s $@ $(LIBNAME)
test : test_multicurl pingpong_client test_events test_addtimer test_queue test_sidlist echoserver-lock echoserver iothreads_dispatcher
test_events : test_events.o $(OBJS)
$(CC) $^ -o $@ $(LFLAGS)
test_addtimer : test_addtimer.o $(OBJS)
$(CC) $^ -o $@ $(LFLAGS)
test_queue : test_queue.o
$(CC) $^ -o $@ $(LFLAGS)
test_sidlist : test_sidlist.o utils.o
$(CC) $^ -o $@ $(LFLAGS)
echoserver-lock : accept-lock-echoserver.o $(OBJS)
$(CC) $^ -o $@ $(LFLAGS)
echoclient : io.o echoclient.o $(OBJS)
$(CXX) $^ -o $@ $(LFLAGS)
echoserver : io.o echoserver.o $(OBJS)
$(CXX) $^ -o $@ $(LFLAGS)
raw_echoserver : raw_echoserver.o $(OBJS)
$(CC) $^ -o $@ $(LFLAGS)
pingpong : pingpong.o $(OBJS)
$(CC) $^ -o $@ $(LFLAGS)
echostress :
$(CC) test/echostress.c -o $@ -I/usr/local/include -L/usr/local/lib -levent
iothreads_dispatcher : test_iothreads.o $(OBJS)
$(CC) $(LFLAGS) $^ -o $@
chatroom : chatroom_server chatroom_client
chatroom_server: io.o chatroom_server.o $(OBJS)
$(CXX) $^ -o $@ $(LFLAGS)
chatroom_client: io.o chatroom_client.o $(OBJS)
$(CXX) $^ -o $@ $(LFLAGS)
redis_client : io.o redis.o helper.o $(OBJS)
$(CXX) $^ -o $@ $(LFLAGS) -lhiredis
pingpong_client : pingpongclient.o $(OBJS)
$(CXX) $^ -o $@ $(LFLAGS)
test_multicurl : xcurl.o test_multicurl.o $(OBJS)
$(CXX) $^ -o $@ $(LFLAGS) -lcurl
clean :
rm -rf *.o
rm -rf *.log
rm -rf core
rm -rf *.core
rm -rf core.*
rm -rf vgcore.*
rm -rf $(SONAME)
rm -rf $(LIBNAME)
rm -rf $(REALNAME)
rm -rf test_events event.fifo
rm -rf test_queue test_sidlist
rm -rf chatroom_client chatroom_server
rm -rf test_multicurl test_addtimer echoclient echostress raw_echoserver echoserver pingpong echoserver-lock iothreads_dispatcher redis_client pingpong_client
# --------------------------------------------------------
#
# gmake的规则
#
%.o : %.c
$(CC) $(CFLAGS) -Wno-unused-function -c $^ -o $@
%.o : %.cpp
$(CXX) $(CXXFLAGS) -std=c++11 -Wno-unused-function -Itest/ -Iexamples/ -c $^ -o $@
VPATH = src:include:test:examples