Makefile to build client, server and generate api go code
authorJulien Andrieux <julien@pantomath.io>
Wed, 4 Oct 2017 23:15:59 +0000 (01:15 +0200)
committerJulien Andrieux <julien@pantomath.io>
Thu, 5 Oct 2017 12:49:08 +0000 (14:49 +0200)
.gitignore
Makefile [new file with mode: 0644]

index fbedee5..c0edc89 100644 (file)
@@ -84,4 +84,7 @@ GitHub.sublime-settings
 # Compiled protobuf files
 *.pb.go
 *.pb.gw.go
-*.swagger.json
\ No newline at end of file
+*.swagger.json
+
+# Binaries generated by Makefile
+bin/*
\ No newline at end of file
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..df9f6a6
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,34 @@
+SERVER_OUT := "bin/server"
+CLIENT_OUT := "bin/client"
+API_OUT := "api/api.pb.go"
+PKG := "gitlab.com/pantomath-io/demo-grpc"
+SERVER_PKG_BUILD := "${PKG}/server"
+CLIENT_PKG_BUILD := "${PKG}/client"
+PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)
+
+.PHONY: all api server client
+
+all: server client
+
+api/api.pb.go: api/api.proto
+       @protoc -I api/ \
+               -I${GOPATH}/src \
+               --go_out=plugins=grpc:api \
+               api/api.proto
+
+api: api/api.pb.go ## Auto-generate grpc go sources
+
+dep: ## Get the dependencies
+       @go get -v -d ./...
+
+server: dep api ## Build the binary file for server
+       @go build -i -v -o $(SERVER_OUT) $(SERVER_PKG_BUILD)
+
+client: dep api ## Build the binary file for client
+       @go build -i -v -o $(CLIENT_OUT) $(CLIENT_PKG_BUILD)
+
+clean: ## Remove previous builds
+       @rm $(SERVER_OUT) $(CLIENT_OUT) $(API_OUT)
+
+help: ## Display this help screen
+       @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'