0
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 5 years have passed since last update.

Makefile: help 自動生成に快適な生活ライフを送る

Posted at

Makefile: help 自動生成に快適な生活ライフを送る

目的

今までMakefileのhelpをちまちま書いていたのだが、
コマンドと離れているため可読性に欠けていた。

この章では、コマンドに対してhelpの内容を記述してhelpに反映させることを実現します

実践

今回 make2helpというCLIを使用します。

インストール方法

go get github.com/Songmu/make2help/cmd/make2help

Makefileをスキャンし、ドキュメントとともにルールを表示します。
ルールがドキュメントとして記述される直前に、ダブルハッシュ(##)で始まるコメント行を考慮します。

以下がサンプルのMakefile です。

Makefile
SHELL := /bin/bash
.DEFAULT_GOAL := help

help:
	@make2help $(MAKEFILE_LIST)

## Note that the API server must
## also be running.
start:
	@gopherjs -m -v serve --http :3000 github.com/tj/docs/client

## Start the API server.
api:
	@go run server/cmd/api/api.go

## Display dependency graph.
deps:
	@godepgraph github.com/tj/docs/client | dot -Tsvg | browser

## Display size of dependencies.
## - Any comment preceded by a dash is omitted.
size:
	@gopherjs build client/*.go -m -o /tmp/out.js
	@du -h /tmp/out.js
	@gopher-count /tmp/out.js | sort -nr

.PHONY: start api deps size help

Makefileでヘルプターゲットを定義し、.DEFAULT_GOALに設定すると、makeと入力するだけでヘルプメッセージを表示できます。

以下が結果となります

api: Start the API server.
deps: Display dependency graph.
start: Note that the API server must
also be running.

まとめ

いかがでしたでしょうか?

今回のサンプルはこちらに載せておきます。
https://github.com/locona/make2help

これからも便利なツールをご紹介していくので、他にも良いツールがありましたらコメントで教えていただけると嬉しいです。

0
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
0
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?