##
# First, define some variables
##

# Sometimes the C compiler will vary based on system
CC=cc

# Compile flags are also useful. 
# For example, -g for debugging info and -Wall for (almost all) warnings
FLAGS=-g -Wall

# It's also common to add include directories to search for header
# files if you have some that appear in atypical places
INCLUDES=/opt/local/include

# Sometimes library files (like .so) live in atypical places, too
LIBRARIES=/opt/local/lib

# The main format for a "useful" line in a makefile has the format:
target: dependency1 dependency2 # ... dependencyN
	command

# Calling "make target" would execute the command anytime a dependency
# is out of date. What does that mean? If dependency is a file, it is
# out of date if it has been changed since the last make. If
# dependency is some OTHER target, it is (recursively) out of date if
# any of its dependencies are out of date. And so on.

# Let's try this on a real file.

myex: myprog.c
	$(CC) $(FLAGS) -I$(INCLUDES) -L$(LIBRARIES) myprog.c -o myex


# In short, this can save you a lot of typing at compile time. It can
# also help target your compiles/debugging by creating different
# targets and dependencies

# make can also do many other neat things using "macros" and "suffix
# rules".  You can learn more by browsing the manual:
# http://www.gnu.org/software/make/manual/ 
# (Perhaps better resources are the plethora of tutorials on the web,
# or an O'Reilly book, "Managing projects with make")