What is the difference between .cpp.o:
, .o:
and %.o: %.c
?
Here's a simple Makefile example:
CC=g++
CFLAGS=-c -Wall
SOURCES=file1.cpp file2.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=program
$(EXECUTABLE): $(OBJECTS)
$(CC) $(OBJECTS) -o $@
#.o:
#.cpp.o:
%.o: %.c
$(CC) $(CFLAGS) $< -o $@
all: $(SOURCES) $(EXECUTABLE)
clean:
rm -rf $(OBJECTS) $(EXECUTABLE)
I have noticed that the output is same, but I guess they are interpreted on a different way internally. Is there a preferred way of doing this?
Both work but the new style is more powerful because it allows you to write more complicated constructions thanks to pattern matching: