1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Go 1.16用Makefile

Last updated at Posted at 2021-05-14

『改訂2版 みんなのGo言語』のMakefileがGo 1.16では動かなかったので、動くように書き換えました。

フォルダ構成

cmd/myapp/main.goにメインアプリのソースコードが入っている。internalは内部でしか使わないパッケージ、pkgは外部から参照可能なパッケージ。

myproj/
├── Makefile
├── README.md
├── go.mod
├── bin/
│   └── myapp(ビルド後に生成)
├── cmd/
│   └── myapp/
│       └── main.go
├── internal/
└── pkg/

Makefile

# メタ情報
NAME := myproj
VERSION := $(gobump show -r)
REVISION := $(shell git rev-parse --short HEAD)
LDFLAGS := -X 'main.revision=$(REVISION)'

export GO111MODULE=on

.PHONY: deps
deps:
	go mod tidy

# 必要なツール類をセットアップする
.PHONY: devel-deps
devel-deps: deps
	go install \
		golang.org/x/lint/golint@latest
	go install \
		github.com/x-motemen/gobump/cmd/gobump@latest
	go install \
		github.com/Songmu/make2help/cmd/make2help@latest

# テストを実行する
## Run tests
.PHONY: test
test: deps
	go test ./...

## Lint
.PHONY: lint
lint: devel-deps
	go vet ./...
	golint --set_exit_status./...

## build binaries ex. make bin/myapp
bin/%: cmd/%/main.go deps
	go build -ldflags "$(LDFLAGS)" -o $@ $<

.PHONY: build
build: bin/myapp

## Show help
.PHONY: help
help:
	@make2help $(MAKEFILE_LIST)

実行手順

# makeで用いるツールのグローバルインストール
make devel-deps
# バイナリのビルド
make build
# 実行
./bin/myapp
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?