확장자 규칙은 이렇게 사용합니다.

%.타겟확장자: %.소스확장자


Makefile
SOURCES=sun.txt moon.txt
OBJECTS=$(SOURCES:.txt=.o)

all: target

%.o: %.txt
    @echo '[SUFFIXES]'
    @echo -n '$$? : '
    @echo $?
    @echo -n '$$^ : '
    @echo $^
    @echo -n '$$@ : '
    @echo $@
    @echo -n '$$< : '
    @echo $<
    @echo -n '$$* : '
    @echo $*

target: $(OBJECTS)
    @echo -n '[target] $$? : '
    @echo $?
    @echo -n '[target] $$^ : '
    @echo $^


이와 동일한 방법은 Makefile에 내장된 .SUFFIXES 를 사용하는 방법인데 .txt 확장자를 .SUFFIXES에 추가하고 타겟을 이렇게 스크립팅 합니다.

.소스확장자.타겟확장자:

%를 사용한 방식과는 순서가 반대이니 주의해야 합니다.


SOURCES=sun.txt moon.txt
OBJECTS=$(SOURCES:.txt=.o)

## 내장된 .SUFFIXES ##
#.out .a .ln .o .c .cc .C .cpp .p .f .F .r .y .l .s .S .mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo .w .ch .web .sh .elc .el

.SUFFIXES: .txt

all: target

.txt.o:
    @echo '[SUFFIXES]'
    @echo -n '$$? : '
    @echo $?
    @echo -n '$$^ : '
    @echo $^
    @echo -n '$$@ : '
    @echo $@
    @echo -n '$$< : '
    @echo $<
    @echo -n '$$* : '
    @echo $*

target: $(OBJECTS)
    @echo -n '[target] $$? : '
    @echo $?
    @echo -n '[target] $$^ : '
    @echo $^


과연 둘 다 같은 결과를 출력합니다.
이왕 같은 결과를 출력하는 거라면 %를 사용한 방법이 더 쉬울 것 같습니다.
심플하기 때문이죠.

결과
$ make
[SUFFIXES]
$? : sun.txt
$^ : sun.txt
$@ : sun.o
$< : sun.txt
$* : sun
[SUFFIXES]
$? : moon.txt
$^ : moon.txt
$@ : moon.o
$< : moon.txt
$* : moon
[target] $? : sun.o moon.o
[target] $^ : sun.o moon.o

+ Recent posts