:: [cs485] Creating a Makefile. ::
HOME


[Date Prev][Date Next][Date Index]

[cs485] Creating a Makefile.


Most of this is taken from the bool
Programming with GNU software -- Loukides and oram.. and published by
0'reilly

I have made it a point to use the following makefile..

An example Makefile
----------------------

#usually 'make' will look for soucre files in the current directory..
#In order to tell make to look for source files in other
# directories, use VPATH=dir1:dir2:dir3
VPATH=.

#You can use macros in make as given below..
#Macaros required to be defined as in the example below
CC= g++
#which defines the macro CC.. In order to use the macro
#you will have to use $(CC)... Same is for other macros..
#Here are some more.....
SRCTOP=.
#INCLUDEDIR = -I$(SRCTOP)/include
INCLUDEDIR =
DEFINES=
COPTS = -g  #-O

CFLAGS= $(COPTS) $(DEFINES) $(INCLUDEDIR)

#LIBS=  -lnsl
LIBS=

all: prog1 prog2
prog1:
        $(CC) $(CFLAGS) -o $@ $@.cpp $(LIBS)
#The target in the above example is "prog1"... Since there are no
dependencies on any other files to
#compile this program, we do include any dependencies after the ":"
#The variable $@  = prog1 and $*=NULL in this example
#If the target was something like "test.o" then the variable $@ = test.o and
$* = test

# If prog2 depended on other programs, those targets would be listed here..
If  i ever do such kind of example, i will surely
# update this mail.
prog2:
        $(CC) $(CFLAGS) -o $@ $@.cpp $(LIBS)

clean:
        rm *.o *~ prog1 prog2

#The *~ in the above example removes any *~ files created by emacs. The rest
is quite clear

******************************************************************