Makefile Tutorial - Main Makefile Example

Source_Code Makefile

#...........................................................................................................................................
#:
#: Makefile for Client Server Course Initial Assignment Programs
#:
#: by: MBSpring
#: and rjy
#: additional bugs by: J. Kabara
#:
#: creation date: 1 January 1996
#: last modification date:
#: version: 2.1
#...........................................................................................................................................
#
# ignore errors and keep compiling therefor make will attempt to compile
# other programs even if one fails
.IGNORE:
#: keep information on how the last compile attempt went
.KEEP_STATE:
#: the line below uses default options for files with these suffixes
.SUFFIXES: .o .c
# Construct a .o file from a .c file with the same name.
.c.o:
[TAB] ${CC} $(CCFLAGS) $(UDEFINES) $(DEFINES) $(INCLUDES) -o $@ -c $<
# Construct an executable from a .c file with the same name.
.c:
[TAB] ${CC} $(CCFLAGS) $(UDEFINES) $(DEFINES) ${LDFLAGS} ${LIBDIRS} -o $@ $<

DESTDIR = $(HOME)
SOURCEDIR = $(PWD)
RANLIB = ranlib
#CC = gcc
CC = cc
INSTALL = /usr/sbin/install
MV = mv
RM = rm
INSFLAGS =
CCFLAGS = -g -xF -R$(HOME)/lib
#CCFLAGS = -fast
#for nova use:
#PARALLEL = 9
#CFLAGS = -fast -mr -S -xparallel -xtarget=???
#multithreading flags
# -mt
INCLUDES = -I$(DESTDIR)/include
LIBDIRS = -L$(DESTDIR)/lib
LDLIBS = -lutil -lsocket -lnsl
UDEFINES = -DDEFHOST=\"nnet.sis.pitt.edu\" -DANSI

SUBDIRS = people_tcp_client \
[TABTABTAB]people_tcp_i_server

help :
[TAB]@ echo "The following make targets are available"
[TAB]@ echo " help - print this message"
[TAB]@ echo " all - make everything"
[TAB]@ echo " install - install everything"
[TAB]@ echo " remove - remove everything"
[TAB]@ echo " clean - remove any temporary files"

library : $(DESTDIR)/lib/libutil.a
[TAB]cd $(SOURCE)/libutil; $(MAKE) libutil

all install remove clean : $(SUBDIRS)
[TAB]for subdir in $(SUBDIRS); do (cd $${subdir}; $(MAKE) $@1); done

all1 : $(PROGRAM)

install1 : $(PROGRAM)
[TAB]$(INSTALL) $(INSFLAGS) -c $(DESTDIR)/bin $(PROGRAM)

remove1 :
[TAB]$(RM) -f $(DESTDIR)/bin/$(PROGRAM)

clean1 :
[TAB]$(RM) -f *.o *.out $(PROGRAM) core

$(PROGRAM) : $(OBJECTS)
[TAB]${CC} $(CCFLAGS) $(UDEFINES) $(DEFINES) ${LDFLAGS} $(OBJECTS) ${LIBDIRS}


S. M. Garver,Spring 1998