next up previous
Next: Comments Up: A short guide to Previous: A short guide to

A sample makefile and how it works

Let's start by looking at a sample makefile:


# for cs machines
#BASEDIR = /usr/project/courses/cps008/lib
# for acpub machines
BASEDIR = /afs/

TLIB = $(BASEDIR)/libtapestry.a

# set up compiler and options
CXX = g++

#-----Suffix Rules---------------------------
# set up C++ suffixes and relationship between .cc and .o files


   ->   $(CXX) $(CXXFLAGS) -c $<

.cc :
   ->   $(CXX) $(CXXFLAGS) $< -o $@ -lm $(TLIB) -lg++

#-----File Dependencies----------------------

SRC = \ \

OBJ = $(addsuffix .o, $(basename $(SRC)))

usepix: $(OBJ)
   ->   $(CXX) $(CXXFLAGS) -o $@ $(OBJ) -lm $(TLIB) -lg++

#-----Other stuff----------------------------
   ->   makedepend $(CXXFLAGS) -Y $(SRC)

   ->   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 ...).

Fri Jan 24 17:04:25 EST 1997