타겟: 의존성(들) 타겟: 빌드 결과 파일명(보통 하나) 명령어: 실제 동작하는 쉘 스크립트(탭으로 시작) 의존성: 타겟이 빌드되기 전에 반드시 준비되어야 할 파일 목록 예시:
Makefile 튜토리얼 가이드 소개
시작하기
Makefile의 존재 목적
Make의 대안 빌드 시스템
Make의 버전과 종류
예제 실행 방법
Makefile 기본 구문
규칙(Rule)의 구조
Make의 본질
Hello World 예제
hello:
echo "Hello, World"
echo "This line will print if the file hello does not exist."
C 파일 컴파일 기본 예제
blah:
cc blah.c -o blah
의존성 추가 방식
blah: blah.c
cc blah.c -o blah
예제 추가
연결된 타겟 및 의존성 예제
blah: blah.o
cc blah.o -o blah
blah.o: blah.c
cc -c blah.c -o blah.o
blah.c:
echo "int main() { return 0; }" > blah.c
반드시 실행되는 타겟 예제
some_file: other_file
echo "This will always run, and runs second"
touch some_file
other_file:
echo "This will always run, and runs first"
Make clean
변수 처리
files := file1 file2
some_file: $(files)
echo "Look at this variable: " $(files)
touch some_file
file1:
touch file1
file2:
touch file2
clean:
rm -f file1 file2 some_file
타겟 관리
all 타겟
all: one two three
one:
touch one
two:
touch two
three:
touch three
clean:
rm -f one two three
다중 타겟 및 자동 변수
all: f1.o f2.o
f1.o f2.o:
echo $@
자동 변수와 와일드카드
* 와일드카드
print: $(wildcard *.c)
ls -la $?
thing_wrong := *.o
thing_right := $(wildcard *.o)
% 와일드카드
Fancy Rules
암시적(Implicit) 규칙
CC = gcc
CFLAGS = -g
blah: blah.o
blah.c:
echo "int main() { return 0; }" > blah.c
clean:
rm -f blah*
Static Pattern Rules
objects = foo.o bar.o all.o
all: $(objects)
$(CC) $^ -o all
$(objects): %.o: %.c
$(CC) -c $^ -o $@
all.c:
echo "int main() { return 0; }" > all.c
%.c:
touch $@
clean:
rm -f *.c *.o all
Static Pattern Rules + filter 함수
obj_files = foo.result bar.o lose.o
src_files = foo.raw bar.c lose.c
all: $(obj_files)
.PHONY: all
$(filter %.o,$(obj_files)): %.o: %.c
echo "target: $@ prereq: $