1# Copyright 2022 Meta
2# SPDX-License-Identifier: Apache-2.0
3
4.PHONY: all clean
5
6OS = $(shell uname -s)
7
8CXXFLAGS :=
9CXXFLAGS += -std=c++17
10
11GEN_DIR = gen-cpp
12GENSRC = $(GEN_DIR)/Hello.cpp $(GEN_DIR)/Hello.h $(GEN_DIR)/hello_types.h
13GENHDR = $(filter %.h, $(GENSRC))
14GENOBJ = $(filter-out %.h, $(GENSRC:.cpp=.o))
15
16THRIFT_FLAGS :=
17THRIFT_FLAGS += $(shell pkg-config --cflags thrift)
18THRIFT_FLAGS += -I$(GEN_DIR)
19ifeq ($(OS),Darwin)
20# get Homebrew prefix
21HOMEBREW_PREFIX := $(shell brew --prefix)
22# get boost include path (no pkgconfig file)
23BOOST_INCLUDE := $(shell find $(HOMEBREW_PREFIX) -path '*/Cellar/boost/*/include' -type d | head -n 1)
24THRIFT_FLAGS += -I$(BOOST_INCLUDE)
25THRIFT_FLAGS += $(shell pkg-config --cflags openssl)
26endif
27THRIFT_LIBS = $(shell pkg-config --libs thrift)
28
29all: hello_client hello_client_compact hello_client_ssl hello_client_py.stamp
30
31hello_client.stamp: ../hello.thrift
32	thrift --gen cpp:no_skeleton $<
33
34$(GENSRC): hello_client.stamp
35	touch $@
36
37%.o: %.cpp $(GENHDR)
38	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(THRIFT_FLAGS) -o $@ -c $<
39
40hello_client: src/main.cpp  $(GENOBJ) $(GENHDR)
41	$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(THRIFT_FLAGS) -o $@ $< $(GENOBJ) $(THRIFT_LIBS)
42
43hello_client_compact: src/main.cpp  $(GENOBJ) $(GENHDR)
44	$(CXX) -DCONFIG_THRIFT_COMPACT_PROTOCOL=1  $(CPPFLAGS) $(CXXFLAGS) $(THRIFT_FLAGS) -o $@ $< $(GENOBJ) $(THRIFT_LIBS)
45
46hello_client_ssl: src/main.cpp  $(GENOBJ) $(GENHDR)
47	$(CXX) -DCONFIG_THRIFT_SSL_SOCKET=1 $(CPPFLAGS) $(CXXFLAGS) $(THRIFT_FLAGS) -o $@ $< $(GENOBJ) $(THRIFT_LIBS)
48
49hello_client_py.stamp: ../hello.thrift
50	thrift --gen py $<
51	touch $@
52
53clean:
54	rm -Rf hello_client hello_client_compact hello_client_ssl $(GEN_DIR) gen-py *.stamp
55