한번에 여러 개의 target 을 동시에 make 하고 싶다면 all target 을 만들면 된다. all 이 가장 첫 번째로 등장하는 rule 로 설정한다면 make 는 default 로 all target 에 해당하는 rule 을 수행한다:
all: one two three
one:
touch one
two:
touch two
three:
touch three
clean
rm -f one two three
만일 하나의 rule 에 여러 target 이 존재한다면, command 는 각각의 target 에 대해서 수행된다:
all: f1.o f2.o
f1.o f2.o:
echo $@
$@ 와 관련된 내용은 곧바로 더 자세하게 기술할 것이지만 간단하게 설명하면 target name 을 포함하는 automatic variable 중 하나이다. 위 예제는 아래와 동일하다:
f1.o:
echo f1.o
f2.o:
echo f2.o
* Wildcard * wildcard 는 파일시스템 내에서 일치하는 이름의 파일들을 찾는다. 그러나 가급적이면 * wildcard 는 wildcard 함수 내에서 사용하는 것이 좋다. 그 이유는 아래에 후술한다:
print: $(wildcard *.c)
ls -la $?
* 은 target, prerequisite, 혹은 wildcard 함수 내에서 사용되어질 수 있다. 그러나 * wildcard wildcard 함수 내에서 사용하지 않으면 다음과 같은 문제가 발생할 수 있다:
*를 변수 정의(variable definition) 에 직접 사용할 수 없다.- 만일 일치하는 파일이 존재하지 않는다면, 공백이 아닌 * wildcard 자체가 그 자리에 남는다.
thing_wrong := *.o # Don't do this! '*' will not get expanded
thing_right := $(wildcard *.o)
all: one two three four
# Fails, because $(thing_wrong) is the string "*.o"
one: $(thing_wrong)
# Stays as *.o if there are no files that match this pattern :(
two: *.o
# Works as you would expect! In this case, it does nothing.
three: $(thing_right)
# Same as rule three
four: $(wildcard *.o)
% Wildcard% 은 매우 유용하지만 다양한 상황에서 쓰이기 때문에 다소 혼란스러울 수 있다:
stem 을 받아서 이를 통해 문자열을 치환한다.% 는 대부분의 경우 rule 정의 그리고 일부 특정한 함수에서 사용된다.% 와 관련된 더 자세한 사항은 Pattern Rules 에서 더 자세하게 다룰 것이다.
make 에는 다양한 종류의 automatic variable 이 있지만 가장 자주 사용하는 세 가지 변수만 추리면 다음과 같다:
hey: one two
# Outputs "hey", since this is the target name
echo $@
# Outputs all prerequisites newer than the target
echo $?
# Outputs all prerequisites
echo $^
touch hey
one:
touch one
two:
touch two
clean:
rm -f hey one two