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 $@
What do the $@ and $< do exactly?
$@is the name of the target being generated, and$<the first prerequisite (usually a source file). You can find a list of all these special variables in the GNU Make manual.For example, consider the following declaration:
In this case:
$@evaluates toall$<evaluates tolibrary.cpp$^evaluates tolibrary.cpp main.cpp