-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
121 lines (99 loc) · 3.7 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
APACHECTL=apachectl
PROTOSRC = $(shell find ./src -name '*.proto')
PROTOHEADERS = $(PROTOSRC:.proto=.grpc.pb.h) $(PROTOSRC:.proto=.pb.h)
PROTOGEN = $(PROTOHEADERS:.h=.cc)
SRC = $(shell find ./src -name '*.cpp') $(shell find ./src -name '*.c') $(shell find ./src -name '*.cc') $(PROTOSRC:.proto=.grpc.pb.cc) $(PROTOSRC:.proto=.pb.cc)
EXCLUDE_SRC =
FSRC = $(filter-out $(EXCLUDE_SRC), $(SRC))
OBJ = $(FSRC:=.o)
DEP_DIR = .deps
FLAGS = -fPIC -DPIC -Wall -Wno-unknown-pragmas -fstack-protector-strong -flto `pkg-config --cflags apr-1` -I`apxs -q INCLUDEDIR` -I.
CXXFLAGS = -std=c++14
CFLAGS =
LINKFLAGS = -lprotobuf -lgrpc++ -Wl,--version-script=mod_grpcbackend.version
OUTNAME = libapache2-mod-grpcbackend
OUTFILE = mod_grpcbackend.so
ARCH := $(shell getconf LONG_BIT)
DEBVERSION = $(shell git describe --tags --long | cut -d- -f1,2 | cut -c2-)
DEBFOLDER = $(OUTNAME)_$(DEBVERSION)
.PHONY: clean debug release test reload install start restart stop run-apache package
.PRECIOUS: $(PROTOGEN) $(PROTOHEADERS)
release: FLAGS += -O2
release: $(OUTFILE)
debug: FLAGS += -g -O0
debug: $(OUTFILE)
$(OUTFILE): $(OBJ)
@echo Generating shared library
@$(CXX) -shared -o $@ $^ $(LINKFLAGS)
@echo Build done
%.cpp.o: %.cpp $(PROTOHEADERS)
@echo Building $<
@$(CXX) -c $(FLAGS) $(CXXFLAGS) $< -o $@
@mkdir -p `dirname $(DEP_DIR)/[email protected]`
@$(CXX) -c $(FLAGS) $(CXXFLAGS) -MT '$@' -MM $< > $(DEP_DIR)/[email protected]
%.cc.o: %.cc $(PROTOHEADERS)
@echo Building $<
@$(CXX) -c $(FLAGS) $(CXXFLAGS) $< -o $@
@mkdir -p `dirname $(DEP_DIR)/[email protected]`
@$(CXX) -c $(FLAGS) $(CXXFLAGS) -MT '$@' -MM $< > $(DEP_DIR)/[email protected]
%.c.o: %.c $(PROTOHEADERS)
@echo Building $<
@$(CC) -c $(FLAGS) $(CFLAGS) $< -o $@
@mkdir -p `dirname $(DEP_DIR)/[email protected]`
@$(CC) -c $(FLAGS) $(CFLAGS) -MT '$@' -MM $< > $(DEP_DIR)/[email protected]
clean:
@echo Removing shared library
@rm -f $(OUTFILE)
@echo Removing objects
@rm -f $(OBJ)
@echo Removing dependency files
@rm -rf $(DEP_DIR)
@echo Removing Protobuf generated files
@rm -rf $(PROTOHEADERS) $(PROTOGEN)
@echo Removing debian packages
@rm -rf $(DEBFOLDER)
@rm -f $(DEBFOLDER).deb
%.grpc.pb.cc %.grpc.pb.h: %.proto
protoc -I . --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` $<
%.pb.cc %.pb.h: %.proto
protoc -I . --cpp_out=. $<
-include $(OBJ:%=$(DEP_DIR)/%.d)
# simple test
test: reload
google-chrome http://localhost/grpcbackend
# install and activate shared object by reloading Apache to
# force a reload of the shared object file
reload: install run-apache
install: debug
apxs -i -n grpcbackend mod_grpcbackend.so
# the general Apache start/restart/stop
# procedures
start:
$(APACHECTL) start
restart:
$(APACHECTL) restart
stop:
$(APACHECTL) stop
run-apache:
$(APACHECTL) -d . -f httpd.conf -e info -DFOREGROUND
package: release
@rm -r -f $(DEBFOLDER)
@echo Creating package
@mkdir -p $(DEBFOLDER)/DEBIAN
@mkdir -p $(DEBFOLDER)/etc/apache2/mods-available/
@mkdir -p $(DEBFOLDER)/usr/lib/apache2/modules/
@echo "Package: $(OUTNAME)" >> $(DEBFOLDER)/DEBIAN/control
@echo "Version: $(DEBVERSION)" >> $(DEBFOLDER)/DEBIAN/control
@echo "Section: httpd" >> $(DEBFOLDER)/DEBIAN/control
@echo "Priority: optional" >> $(DEBFOLDER)/DEBIAN/control
ifeq ($(ARCH),64)
@echo "Architecture: amd64" >> $(DEBFOLDER)/DEBIAN/control
else
@echo "Architecture: i386" >> $(DEBFOLDER)/DEBIAN/control
endif
@echo "Depends: " >> $(DEBFOLDER)/DEBIAN/control
@echo "Maintainer: Dominik Thalhammer <[email protected]>" >> $(DEBFOLDER)/DEBIAN/control
@echo "Description: Apache module to forward requests to a grpc backend" >> $(DEBFOLDER)/DEBIAN/control
@cp $(OUTFILE) $(DEBFOLDER)/usr/lib/apache2/modules/$(OUTFILE)
@cp mod_grpcbackend.load $(DEBFOLDER)/etc/apache2/mods-available/grpcbackend.load
@fakeroot dpkg-deb --build $(DEBFOLDER)