LoginSignup
6
5

More than 3 years have passed since last update.

Makefile is 何?

  • GitHubとか見てるとよくMakefileとかいうのが置いてある
  • → これが何なのか知らなかったので調べてみた

Makefileとは

  • makeコマンドで自動化したい作業内容を記載するファイル
  • make hogeでコンパイルしたり、shell叩いたりできる

基本的な書き方

Makefile
# コメントはbashと同じ
<タスク名A>: <依存ターゲット>
    <実行するコマンドA>

<タスク名B>:
    <実行するコマンドB>
  • コメントは#で書ける
  • タスク名をつけると、make <タスク名>で<実行するコマンド>を呼ぶことができる
  • タスク名と実行するコマンドの合わせて「ルール」と呼ぶ
  • <実行するコマンド>の左はタブ1つ
  • <依存ターゲット>を指定すると、<タスク名A>の前に<タスク名B>を実行してから<タスク名A>を実行できる
  • allは最終的に実行されるものを指す?

具体例

  • Goをコンパイルして実行するを定義してみる
Makefile
# コンパイルを行ってから実行する
all: compile
    ./main

# コンパイルを行う
compile:
    go build -o main main.go

コンパイルと実行を行う

MacBook-Pro:captainblue captain-blue$ make
go build -o main main.go
./main

コンパイルのみ行う

MacBook-Pro:captainblue captain-blue$ make compile
go build -o conv main.go

参考

自動化のためのGNU Make入門講座
コマンド「make」初心者向けメモ(Hishidama's make-command Memo)

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