TARGET... : DEPENDENCIES... [; COMMAND] COMMAND ... ...
.PHONY : clean clean : rm $(OBJS)
foo: cd foodir ; doitor
foo: cd foodir ; \ doit
foo: -rm -f *~ *.o
foo bar baz: blah doit and foo: blah doit bar: blah doit baz: blah doitare equivalent
FILES = foo bar baz foo: bar doit bar baz: blah dothat $(FILES): gag # no commands allowed herewill add dependency on gag to $(FILES) (ie, if gag changes, files will get rebuild)
TARGET-PATTERN: DEP-PATTERN COMMANDS eg %.o: %.c $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
TARGETS ...: TARGET-PATTERN: DEP-PATTERNS ... COMMANDS ...
OBJS = foo.o bar.o $(OBJS): %.o: %.c $(CC) -c $(CFLAGS) $< -o $@
foo.c: foo.h bar.h quux.cto the makefile
dep: makedepend $(CPPFLAGS) *.cwill remake all dependencies when make dep is called, and write them to the end of the current makefile
include *.d %.d: %.c $(SHELL) -ec '$(CC) -M \ $(CPPFLAGS) $< | \ sed '\''s/$*.o/& $@/g'\'' \ > $@'(gmake considers all included makefiles as targets, and, if any needed to be recreated, reruns itself with the updated makefiles.)
subsystem: cd subdir; $(MAKE)
ARCHIVE(MEMBERS)eg
libfoo.a(foo.o bar.o): foo.o bar.o ar -r libfoo.a foo.o bar.o