5
2

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 1 year has passed since last update.

Makefileで独自コマンドを作成するときは.PHONYを書く

Posted at

PHONYとは何?

英単語の意味は「偽物」です。
Makefileで独自コマンドを作成するときは、.PHONYにも同じコマンドを書きましょう。

具体例

.PHONY: up lint format
up:
	docker-compose up

lint:
	docker-compose run --rm next npm run lint:fix

format:
	docker-compose run --rm next npm run format

なぜ.PHONYが必要なのか?

これがないと、もしディレクトリにコマンドと同じ名前のファイルが存在した場合に困る。
今回の例だと、lintというファイル名が存在して、$ make lintを実行すると失敗する。

$ make lint
make: `lint` is up to date.

結論

独自コマンドの数だけ、PHONYにも同じコマンド名を書く。
これにより、予期せぬエラーを防ぎます!

5
2
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
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?