Let's start by looking at a sample makefile:
#-----Macros---------------------------------
# for cs machines
#BASEDIR = /usr/project/courses/cps008/lib
# for acpub machines
BASEDIR = /afs/acpub.duke.edu/users8/ola/courses/lib
TLIB = $(BASEDIR)/libtapestry.a
INCLUDES = -I. -I$(BASEDIR)
# set up compiler and options
CXX = g++
CXXFLAGS = -g $(INCLUDES)
#-----Suffix Rules---------------------------
# set up C++ suffixes and relationship between .cc and .o files
.SUFFIXES: .cc
.cc.o:
-> $(CXX) $(CXXFLAGS) -c $<
.cc :
-> $(CXX) $(CXXFLAGS) $< -o $@ -lm $(TLIB) -lg++
#-----File Dependencies----------------------
SRC = application.cc menu.cc menuitem.cc pixmap.cc usepix.cc \
readcommand.cc quitcommand.cc filelister.cc templateapp.cc \
displaycommand.cc
OBJ = $(addsuffix .o, $(basename $(SRC)))
usepix: $(OBJ)
-> $(CXX) $(CXXFLAGS) -o $@ $(OBJ) -lm $(TLIB) -lg++
#-----Other stuff----------------------------
depend:
-> makedepend $(CXXFLAGS) -Y $(SRC)
clean:
-> rm -f $(OBJ)
Note that the arrows -> represent places where you should put
tab characters, not eights spaces. It hath been decreed that this
shalt be a tab character. Emacs does have a makefile mode, which you
can get into by typing M-x makefile-mode. In that mode,
pressing the tab key inserts a real tab. Alternatively, the
keystrokes C-q C-i or C-q tab will enter a tab
character in any mode.
You should name your makefile `Makefile' with that capitalization. Make looks for that file automatically. If you don't name it that, you'll have to tell make specifically which file to use (as in gmake -f somethingelse ...).