# *****************************************************************
# *                                                               *
# *  Makefile for                                                 *
# *                                                               *
# *  			CV                                        *
# *  			==                                        *
# *                                                               *
# *****************************************************************

### TYPE OF INSTALLATION 
INSTALLATION = savetime
# comment previous line and uncomment next line if you are short of space:
#INSTALLATION = savespace

### DIRECTORIES

# The directory where the distribution is installed
DIRECTORY = $(PWD)
# The place to install the binaries
INSTALLBIN = $(HOME)/bin
# The place to install the libraries
INSTALLLIB = $(HOME)/lib
# The place to install the includes
INSTALLINC = $(HOME)/include
# Directory for man pages
INSTALLMAN = $(HOME)/man

### COMPILATION

# ANSI C compiler
CC	= gcc
# Create archive file
AR	= ar rcu
# Creates index to the contents of an archive file
RANLIB	= ranlib

### FILE MANIPULATION

# Removes a file without prompt
RM	= /bin/rm -fr
# Copies a file and removes existing destination file without prompt
CP	= /bin/cp -p
# Moves a file and removes existing destination file without prompt
MV	= /bin/cp -p
# Wild cards selecting unnecessary files
JUNK	= core *~ *.orig

# ************** DO NOT EDIT BELOW THIS LINE *********************

# Choose compilation flags for the C compiler
OPT	= -ggdb -O2 \
          -I$(TMPINCLUDES) -I$(INSTALLINC) \
          -L$(TMPLIBRARIES) -L$(INSTALLLIB)

# BSD needs this
MAKE	= make

# The libraries go there
TMPLIBRARIES = $(DIRECTORY)/tmp/lib

# Where to put include files for reuse
TMPINCLUDES = $(DIRECTORY)/tmp/include

# make flags to pass recursively to subdirectories
MFLAGS = \
  "INSTALLATION = $(INSTALLATION)" \
  "CC = $(CC) $(OPT)" \
  "AR = $(AR)" \
  "RANLIB = $(RANLIB)" \
  "RM = $(RM)" \
  "CP = $(CP)" \
  "MV = $(MV)" \
  "JUNK = $(JUNK)" \
  "INSTALLBIN = $(INSTALLBIN)" \
  "INSTALLLIB = $(INSTALLLIB)" \
  "INSTALLINC = $(INSTALLINC)" \
  "INSTALLMAN = $(INSTALLMAN)" \
  "INSTALLDOC = $(INSTALLDOC)" \
  "TMPLIBRARIES = $(TMPLIBRARIES)" \
  "TMPINCLUDES = $(TMPINCLUDES)"

# ****************************************************************
COMPONENTS = \
   mem \
   fn \
   reuse \
   cv \
   label \
   graph \
   cache \
   timer \
   bdd \
   bdd+ \
   ant \
   img \
   ctl \
   spec \
   model
TOPLEVEL = \
   cva \
   cvc

# ****************************************************************

all : cva cvc libcv

libcv: reuse mem cv
	$(CP) $(TMPLIBRARIES)/libcv.a $(INSTALLLIB)
	$(CP) $(TMPINCLUDES)/cv.h $(INSTALLINC)

cva: reuse mem cv
	(cd cva; $(MAKE) $(MFLAGS))

cvc: reuse mem fn cv bdd bdd+ label graph cache timer ctl spec ant img model
	(cd cvc; $(MAKE) $(MFLAGS))

reuse: 
	(cd libreuse; $(MAKE) $(MFLAGS))

mem: 
	(cd libmem; $(MAKE) $(MFLAGS))

fn: 
	(cd libfn; $(MAKE) $(MFLAGS))

cv: reuse mem
	(cd libcv; $(MAKE) $(MFLAGS))

bdd: mem
	(cd libbdd; $(MAKE) $(MFLAGS))

bdd+: mem bdd
	(cd libbdd+; $(MAKE) $(MFLAGS))

label: 
	(cd liblabel; $(MAKE) $(MFLAGS))

graph: 
	(cd libgraph; $(MAKE) $(MFLAGS))

cache: 
	(cd libcache; $(MAKE) $(MFLAGS))

timer: 
	(cd libtimer; $(MAKE) $(MFLAGS))

ctl: 
	(cd libctl; $(MAKE) $(MFLAGS))

spec: 
	(cd libspec; $(MAKE) $(MFLAGS))

ant: 
	(cd libant; $(MAKE) $(MFLAGS))

img: mem fn
	(cd libimg; $(MAKE) $(MFLAGS))

model: 
	(cd libmodel; $(MAKE) $(MFLAGS))

clobber:
	for COMPONENT in $(COMPONENTS) ; do \
	  (cd lib$$COMPONENT ; $(MAKE) $(MFLAGS) clobber) ; \
	done
	for COMPONENT in $(TOPLEVEL) ; do \
	  (cd $$COMPONENT ; $(MAKE) $(MFLAGS) clobber) \
	done
	$(RM) tmp/lib/* tmp/include/* tmp/cv/* 
	$(RM) $(JUNK)

