Makefile cheatlist (assembled by Veselin Georgiev) for GNU make only! ----------------------------------------------------------------------------- 1. SOMEVAR = SOMETHING vs SOMEVAR := SOMETHING X = Y is recursive. Every time X is met during parsing, it is reevaluated. Useful if it contains other references. X := Y is simply-evaluated. Computed only once. Useful for getting shell values like OS := $(shell uname -s) ----------------------------------------------------------------------------- 2. Automatic variables: $@ vs $< $@ is the target. $< is the source. As in: foo.o: foo.c $(CC) -o $@ $< which expands to "cc -o foo.o foo.c". ----------------------------------------------------------------------------- 3. Compile a bunch of .cpp's: %.o: %.cpp $(HEADERS) $(CXX) $(INCLUDES) -o $@ $< ----------------------------------------------------------------------------- 4. Conditional statements: ifeq ($(OS), Linux) CXX = g++ ... else CXX = cl endif note there's no quotes around the second argument. ----------------------------------------------------------------------------- 5. SUFFIXES .SUFFIXES: .pdf .bat will add .pdf and .bat to the list of default suffixes. To empty the list use .SUFFIXES: .SUFFIXES: .pdf .bat This way, ONLY .pdf and .bat will be present in the suffix list. ----------------------------------------------------------------------------- 6. Doing compilation quietly (not showing which commands are executed): .SILENT: Alternatively, add `@' before commands. ----------------------------------------------------------------------------- 7. PHONY all targets, which do not produce a real output file (all, clean, etc...) are listed in phony: .PHONY: all clean I have yet to wait seeing an example where this line was somehow useful, but nevertheless, here you have it.