Here's an example of a makefile. We want to create a program out of two source files, p1.cpp and p2.cpp, linking the object files to two of our own libraries libaudio.a and libmidi.a that reside in /usr/local/myownlibraries.
CC = g++ CFLAGS = -I../include -I$(PARSERDIR)/include -g -Wall LDFLAGS = -L /usr/local/myownlibraries -laudio -lmidi program: p1.o p2.o $(CC) -o $@ p1.o p2.o .cpp.o: $(CC) -c $< $(CFLAGS)
Note the blue bars, indicating you should type a TAB-character, NOT a number of spaces.
$@ | The current target |
$* | Base name of the current target |
$< | The first prerequisite (the left-most file in the line) |
$? | All prerequisites that are newer than the target |
$^ | All prerequisites, with spaces between them. |