Makefile
Makefile はビルドプロセスを自動化 するためのツールで、C/C++ プロジェクトでよく使用 されます。
CLI
version
make --versionGlossary
@ 記号
@ はコマンドの出力
を抑制
できます:
target:
@echo "This command will be echoed"
@echo "This command will also be echoed"
echo "This command will be displayed"
出力 :
This command will be echoed
This command will also be echoed
echo "This command will be displayed"
This command will be displayedExample
C/C++ プロジェクト
# specify the compiler
CC=gcc
# specify options for the compiler
CFLAGS=-c -Wall
all: hello
hello: main.o hello.o
$(CC) main.o hello.o -o hello
main.o: main.cpp
$(CC) $(CFLAGS) main.cpp
hello.o: hello.cpp
$(CC) $(CFLAGS) hello.cpp
clean:
rm -rf *o hello
別の例
output: main.o message.o
g++ main.o message.o -o output
main.o: main.cpp
g++ -c main.cpp
message.o: message.cpp message.h
g++ -c message.cpp
clean:
rm *.o output
基本構造
target: dependencies
command
| 要素 | 説明 |
|---|---|
target | ビルドする対象 |
dependencies | 対象 をビルドするために必要 な依存 関係 |
command | 対象 をビルドするコマンド(Tab で始 まる必要 がある) |
よく使う変数
| 変数 | 説明 |
|---|---|
$@ | ターゲット名 |
$< | 最初 の依存 関係 |
$^ | すべての依存 関係 |
$(CC) | コンパイラ |
$(CFLAGS) | コンパイルオプション |