LoginSignup
0
2

More than 5 years have passed since last update.

Makefileでエコーをオフにする

Posted at

Makefileにてデフォルトでは実行するレシピのコマンドが表示される.
これをエコー(echoing)と呼ぶ.

$ cat Makefile
help: ## show this help.
    echo "Please use 'make <target>' where <target> is one of\n"
    awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

$ make
echo "Please use 'make <target>' where <target> is one of\n"
Please use 'make <target>' where <target> is one of

awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $2);printf "\033[36m%-20s\033[0m %s\n", $1, $2}'  Makefile
help                 show this help.

上記実行例では,echoコマンドやawkコマンドの結果だけ出力されて欲しく,
エコーされて欲しくない.
これを解決するためにはレシピの各コマンドの前に@を付与する.

$ cat Makefile
help: ## show this help.
    @echo "Please use 'make <target>' where <target> is one of\n"
    @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

$ make
Please use 'make <target>' where <target> is one of

help                 show this help.

こういったコマンドが大量にある場合で,
実行時にて実行するコマンド全てに適用したい場合は
-s/--silent/--quiet オプションを付与して実行する

$ cat Makefile
help: ## show this help.
    echo "Please use 'make <target>' where <target> is one of\n"
    awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

$ make -s
Please use 'make <target>' where <target> is one of

help                 show this help.

特定ターゲットに対してエコーをオフにしたい場合は
.SILENTターゲットにて対象ターゲットを指定するとよい.

$ cat Makefile
.SILENT: help
help: ## show this help.
    echo "Please use 'make <target>' where <target> is one of\n"
    awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

$ make
Please use 'make <target>' where <target> is one of

help                 show this help.
0
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
0
2