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にも同じコマンド名を書く。
これにより、予期せぬエラーを防ぎます!