Make Quick Reference

This page contains a minimal GNU Make reference, adapted for my use from

*Automatic Variables:*

Here is a summary of the automatic variables. See Automatic Variables, for full information.

$@    The file name of the target.
$%    The target member name, when the target is an archive member.
$<    The name of the first prerequisite.
$?    The names of all the prerequisites that are newer than the target, with spaces between them.
$+
$^    The names of all the prerequisites, with spaces between them.

The value of $^ omits duplicate prerequisites, while $+ retains them and preserves their order.

Automatic Rules:

  • Compiling C programs

n.o is made automatically from n.c with a recipe of the form $(CC) $(CPPFLAGS) $(CFLAGS) -c

  • Compiling C++ programs

n.o is made automatically from n.c with a recipe of the form $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c

Example:

all: test libtest.so

libtest.so: libtest.o
    $(CC) -shared -o $@ $< -lc

test: test_main.c libtest.o
    $(CC) -o $@ $?

Defining Rules:

%.pdf: %.svg inkscape -Cz --export-pdf=$@ --file=$<

objects = foo.o bar.o

$(objects): %.o: %.c $(CC) -c $(CFLAGS) $< -o $@