Created
February 4, 2019 05:55
-
-
Save freman/185b64079852ad170a86e2fd9c54b211 to your computer and use it in GitHub Desktop.
Gogo proto makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EMPTY := | |
SPACE := $(EMPTY) # | |
COMMA := , | |
GOPATH:=$(shell go env GOPATH) | |
GOBIN:=${GOPATH}/bin | |
PROTO_PATH := ${GOPATH}/src:. | |
PROTO_PATH := ${PROTO_PATH}:${GOPATH}/src/github.com/gogo/protobuf/protobuf | |
PROTO_PATH := ${PROTO_PATH}:${GOPATH}/src/github.com/gogo/protobuf/gogoproto | |
GOOGLE_PROTOS := timestamp duration empty | |
PROTO_SUBS := $(subst $(SPACE),$(COMMA),$(strip $(foreach gp,$(GOOGLE_PROTOS),Mgoogle/protobuf/$(gp).proto=github.com/gogo/protobuf/types))) | |
GOGOBINARY := gogo | |
GENGOGO := $(GOBIN)/protoc-gen-${GOGOBINARY} | |
DIRECTORIES := $(sort $(dir $(wildcard proto/*/))) | |
PROTO_SRC := $(foreach sdir,$(DIRECTORIES),$(wildcard $(sdir)*.proto)) | |
PROTO_PB := $(patsubst %.proto,%.pb.go,$(PROTO_SRC)) | |
PROTO_OTHER := $(patsubst %.proto,%.micro.go,$(PROTO_SRC)) $(patsubst %.proto,%pb_test.go,$(PROTO_SRC)) | |
.PHONY: all clean | |
all: $(GENGOGO) $(PROTO_PB) | |
clean: | |
rm $(PROTO_PB) $(PROTO_OTHER) | |
$(GENGOGO): | |
go get github.com/gogo/protobuf/protoc-gen-${GOGOBINARY} | |
$(PROTO_PB): $(PROTO_SRC) | |
protoc --proto_path=${PROTO_PATH} --${GOGOBINARY}_out=${PROTO_SUBS}:. --micro_out=${PROTO_SUBS}:. $< | |
perl -i -p0e 's/(\t+type\s+)(\w+)(\s+interface.+?struct \{\s+)(\2)/\1I\2\3I\2/s' $(patsubst %.proto,%.micro.go,$(<)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment