Created
September 22, 2020 14:15
-
-
Save devlights/5c8b452ce365833f015e2a8ca654fc20 to your computer and use it in GitHub Desktop.
Protocol Buffers (protobuf) と Go のプログラム作るときに使える Makefile
This file contains 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
usage: | |
@echo '-----------------------------------------------------------------------------' | |
@echo '以下のどれかのタスクを指定します.' | |
@echo ' - install-requirements -- Protocol Buffers を実行するのに必要なものをインストールします.' | |
@echo ' - protoc は プロジェクトディレクトリ直下の bin にインストールされます.' | |
@echo ' - protoc-gen-go は $(go env GOPATH)/bin にインストールされます.' | |
@echo ' - protoc-gen-doc は $(go env GOPATH)/bin にインストールされます.' | |
@echo ' - protoc -- protocを実行します.' | |
@echo ' - protoファイルは protoディレクトリ の下に存在しているとします.' | |
@echo ' - 生成されたgoファイルは internal ディレクトリの下に配置されます.' | |
@echo ' - 生成されたdocファイルは doc ディレクトリの下に配置されます.' | |
@echo ' - run -- サンプルを実行します.' | |
@echo ' - サンプル は、 cmd/example/main.go に存在しているとします.' | |
@echo '-----------------------------------------------------------------------------' | |
@echo '[REFERENCES]' | |
@echo ' - https://developers.google.com/protocol-buffers/docs/gotutorial' | |
@echo ' - https://devlights.hatenablog.com/entry/2020/08/26/130037' | |
@echo ' - https://qiita.com/marnie_ms4/items/4582a1a0db363fe246f3' | |
@echo '-----------------------------------------------------------------------------' | |
install-requirements: _download-protoc _unzip-protoc _locate-protoc _cleanup-tmp _goget-protoc | |
_download-protoc: | |
mkdir -p tmp && \ | |
cd tmp && \ | |
curl -L https://github.com/protocolbuffers/protobuf/releases/download/v3.13.0/protoc-3.13.0-linux-aarch_64.zip --output protoc.zip | |
_unzip-protoc: | |
cd tmp && \ | |
unzip ./protoc.zip -d protoc | |
_locate-protoc: | |
mkdir -p bin && \ | |
rm -rf bin/protoc && \ | |
cd tmp && \ | |
mv -f ./protoc/ ../bin | |
_cleanup-tmp: | |
rm -rf ./tmp | |
_goget-protoc: | |
go get -u github.com/golang/protobuf/protoc-gen-go | |
go get -u github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc | |
protoc: _gen-go-out _gen-proto-doc | |
_gen-go-out: | |
mkdir -p internal | |
bin/protoc/bin/protoc -I=proto --go_out=. proto/*.proto | |
_gen-proto-doc: | |
mkdir -p doc/proto | |
bin/protoc/bin/protoc --doc_out=html,index.html:./doc/proto proto/*.proto | |
run: | |
go run cmd/example/main.go |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment