Makefile 3.94 KB
Newer Older
zhujiashun's avatar
zhujiashun committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

Ge Jun's avatar
Ge Jun committed
18
NEED_GPERFTOOLS=1
19 20 21 22 23
BRPC_PATH = ../../
include $(BRPC_PATH)/config.mk
# Notes on the flags:
# 1. Added -fno-omit-frame-pointer: perf/tcmalloc-profiler use frame pointers by default
# 2. Added -D__const__= : Avoid over-optimizations of TLS variables by GCC>=4.8
24
CXXFLAGS = $(CPPFLAGS) -std=c++0x -g -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer
Ge Jun's avatar
Ge Jun committed
25 26 27
ifeq ($(NEED_GPERFTOOLS), 1)
	CXXFLAGS+=-DBRPC_ENABLE_CPU_PROFILER
endif
28 29
HDRS+=$(BRPC_PATH)/output/include
LIBS+=$(BRPC_PATH)/output/lib
Ge Jun's avatar
Ge Jun committed
30

31 32 33 34 35
HDRPATHS = $(addprefix -I, $(HDRS))
LIBPATHS = $(addprefix -L, $(LIBS))
COMMA=,
SOPATHS=$(addprefix -Wl$(COMMA)-rpath=, $(LIBS))

36
STATIC_LINKINGS += -lthrift -lgflags -lbrpc -levent
37

38
CLIENT_SOURCES = client.cpp
Ge Jun's avatar
Ge Jun committed
39
CLIENT2_SOURCES = client2.cpp
40
SERVER_SOURCES = server.cpp
41
SERVER2_SOURCES = server2.cpp
42 43 44 45
PROTOS = $(wildcard *.proto)

PROTO_OBJS = $(PROTOS:.proto=.pb.o)
PROTO_GENS = $(PROTOS:.proto=.pb.h) $(PROTOS:.proto=.pb.cc)
46
CLIENT_OBJS = $(addsuffix .o, $(basename $(CLIENT_SOURCES)))
Ge Jun's avatar
Ge Jun committed
47
CLIENT2_OBJS = $(addsuffix .o, $(basename $(CLIENT2_SOURCES)))
48 49
SERVER_OBJS = $(addsuffix .o, $(basename $(SERVER_SOURCES)))
SERVER2_OBJS = $(addsuffix .o, $(basename $(SERVER2_SOURCES)))
50 51

.PHONY:all
Ge Jun's avatar
Ge Jun committed
52
all: echo_client echo_client2 echo_server echo_server2 native_server native_client
53 54 55 56

.PHONY:clean
clean:
	@echo "Cleaning"
Ge Jun's avatar
Ge Jun committed
57
	@rm -rf echo_client echo_client2 echo_server echo_server2 $(PROTO_GENS) $(PROTO_OBJS) $(CLIENT_OBJS) $(CLIENT2_OBJS) $(SERVER_OBJS) $(SERVER2_OBJS) native_server native_client EchoService.o echo_types.o libechothrift.a gen-cpp gen-py
58 59 60

echo_client:$(PROTO_OBJS) $(CLIENT_OBJS) libechothrift.a
	@echo "Linking $@"
61
	@$(CXX) $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) -o $@
62

Ge Jun's avatar
Ge Jun committed
63 64 65 66
echo_client2:$(PROTO_OBJS) $(CLIENT2_OBJS) libechothrift.a
	@echo "Linking $@"
	@$(CXX) $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) -o $@

67 68
echo_server:$(PROTO_OBJS) $(SERVER_OBJS) libechothrift.a
	@echo "Linking $@"
69
	@$(CXX) $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ libechothrift.a -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) -o $@
70 71 72 73

echo_server2:$(PROTO_OBJS) $(SERVER2_OBJS) libechothrift.a
	@echo "Linking $@"
	@$(CXX) $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ libechothrift.a -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) -o $@
74

75
%.o:%.cpp libechothrift.a
76 77 78
	@echo "Compiling $@"
	@$(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@

79
%.o:%.cc libechothrift.a
80 81 82 83 84
	@echo "Compiling $@"
	@$(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@

libechothrift.a:
	@echo "Generating thrift files"
wangxuefeng's avatar
wangxuefeng committed
85
	@thrift --gen cpp echo.thrift
86
	@thrift --gen py echo.thrift
87 88
	@$(CXX) -c gen-cpp/echo_types.cpp -o echo_types.o
	@$(CXX) -c gen-cpp/EchoService.cpp -o EchoService.o
89 90
	@ar -crv libechothrift.a EchoService.o echo_types.o

91
native_server: libechothrift.a
92
	@$(CXX) native_server.cpp gen-cpp/echo_types.cpp gen-cpp/EchoService.cpp $(HDRPATHS) $(LIBPATHS) $(SOPATHS) $(CXXFLAGS) -lthriftnb -lthrift -levent -lpthread -lgflags -lbrpc -o native_server
93

94
native_client: libechothrift.a
95
	@$(CXX) native_client.cpp gen-cpp/echo_types.cpp gen-cpp/EchoService.cpp $(HDRPATHS) $(LIBPATHS) $(SOPATHS) $(CXXFLAGS) -lthriftnb -lthrift -levent -lpthread -lgflags -lbrpc -o native_client