All it takes is five rules and 42 lines
Rule #1: Use GNU Make(http://www.gnu.org/software/make)
The following is the top-level Makefile stored in src/:
MODULES=library executable
include $(addsuffix /Makefile,$(MODULES))
Typing make in src/ builds all the object files, library, and executable. The MODULES variable is a list of the directories containing components that must be built. include $(addsuffix /Makefile,$(MODULES)) turns into include library/ Makefile executable/Makefile and includes the Makefiles that describe each of the separate components.
Rule #2: No Spaces in Filenames, No Drive Letters
Rule #3: Decide What Platform the Make is Running On
The simplest way to determine your platform is the uname command,like
X_ARCH := $(shell uname -ms | sed -e s"/ /_/g" )
on CYGWIN, X_ARCH will be CYGWIN_NT-5.0_i686; on Solaris, SunOS_sun-4u; and on Linux, Linux_i686.
Rule #4: Separate Output on a Per-Platform Basis
Rule #5: Override Built-In Rules