CC=g++
CFLAGS=-c -Wall
LDFLAGS=
SOURCES=main.cpp hello.cpp factorial.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=hello

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
    $(CC) $(LDFLAGS) $(OBJECTS) -o $@

.cpp.o:
    $(CC) $(CFLAGS) $< -o $@

윈도우즈 환경에서 Visual Studio 로 개발하다 보니 makefile 쓰는 법을 다 까먹었다. : 기준으로 왼쪽이 target 오른쪽이 source 인 건 알겠는데 $@, $< 같은 변수는 처음 봤다.

https://stackoverflow.com/questions/3220277/what-do-the-makefile-symbols-and-mean

 

What do the makefile symbols $@ and $< mean?

CC=g++ CFLAGS=-c -Wall LDFLAGS= SOURCES=main.cpp hello.cpp factorial.cpp OBJECTS=$(SOURCES:.cpp=.o) EXECUTABLE=hello all: $(SOURCES) $(EXECUTABLE) $(EXECUTABLE): $(OBJECTS) $(CC) $(LDFLAGS) $(

stackoverflow.com

$@ 은 왼쪽, $<은 오른쪽 첫번째, $^ 은 오른쪽 전부를 나타낸다고 한다.

all : library.cpp main.cpp

위와 같은 경우 아래와 같은 값이 된다고 한다.

$@ 은 all
$< 은 library.cpp
$^ 은 library.cpp main.cpp 

https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html#Automatic-Variables

 

Automatic Variables (GNU make)

10.5.3 Automatic Variables Suppose you are writing a pattern rule to compile a ‘.c’ file into a ‘.o’ file: how do you write the ‘cc’ command so that it operates on the right source file name? You cannot write the name in the recipe, because the

www.gnu.org

 

728x90

+ Recent posts