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

Makefileのtarget・phony targetとは

0
Posted at

targetとは

  • makeコマンドによって作成されるファイルのこと

記述の仕方

作成するファイル(=ターゲット): ターゲット作成処理が依存するファイル
    ファイル作成のためのコマンド

具体例

app.exe: main.o
    gcc main.o -o app.exe

phony targetとは

  • 成果物を持たない偽のターゲットのこと
  • phony:「偽の」という意味

記述の仕方

.PHONY: phony target名

phony target名:
    実行したいコマンド

具体例

.PHONY: clean

clean:
    rm app.exe main.o

何が嬉しいの?

  • 成果物が無いコマンドも、まとめられる
  • 通常のターゲットは「makeコマンド実行によって作成される成果物」を指す
    • ※ターゲットを作成するときの挙動
      • ターゲット(app.exe)がすでに存在するかチェック
      • 存在したら、ターゲットが「依存するファイル(main.o)」より新しいかチェック
      • 新しかったら、makeコマンドは処理を実行しない
        • ※最新の依存関係でmake処理を実行済みということなので、処理が不要
  • 成果物が無いけど、makeコマンドでまとめたい処理がある場合
    • phony targetを使える
    • 「ターゲット(app.exe)が実際のファイルじゃなく、処理をまとめたシンボルを指している」とmakeコマンドに教えることができる

参考文献

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?