#
#  Copyright (C) 1993 Tito Flagella.
#
#  This file is part of the POSSO Customizable Memory Manager (CMM).
#
#  Permission to use, copy, and modify this software and its documentation is
#  hereby granted only under the following terms and conditions.  Both the
#  above copyright notice and this permission notice must appear in all copies
#  of the software, derivative works or modified versions, and any portions
#  thereof, and both notices must appear in supporting documentation.
# 
#  Users of this software agree to the terms and conditions set forth herein,
#  and agree to license at no charge to all parties under these terms and
#  conditions any derivative works or modified versions of this software.
#  
#  This software may be distributed (but not offered for sale or transferred
#  for compensation) to third parties, provided such third parties agree to
#  abide by the terms and conditions of this notice.  
#  
#  THE SOFTWARE IS PROVIDED "AS IS" AND THE COPYRIGHT HOLDERS DISCLAIM ALL
#  WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL THE COPYRIGHT HOLDERS
#  BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR
#  ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
#  IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
#  OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
#
#  USER GUIDE
#  The most useful targets in this make file are:
#  "test"  compiles and runs all tests (listed in TESTS) reporting which
#        ones succeeded and which failed.
#  "clean"  removes all object code from this directory.
#  "demo1", "demo2" etc. run various demonstration programs.
#
#  2006/Dec/22
#
#  On Solaris, the value of PWD does not change when make is invoked
#  recursively.  Consequently, it is necessary to explicitly set it
#  at the start of the makefile.
#
PWD = $(shell pwd)

SHELL	= /bin/sh
AR	= ar rv
CP	= cp -p
LN	= ln
RM	= rm -f

CXXFLAGS = -O3 -DNDEBUG
CXXFLAGS = -DNDEBUG
CFLAGS   = -g -O -DNDEBUG
CC  = unicl
CXX = dog++
IncDir	 = $(ALDORROOT)/include
LibDir   = $(ALDORROOT)/lib
DocDir   = $(ALDORROOT)/share/doc
PossoDir = ../posso

CCFILES = cmm.cc tempheap.cc msw.cc 
CFILES = memory.c
HFILES = machine.h cmm.h tempheap.h msw.h
LibCmm = $(LibDir)/libcmm.a

O = (
C = )
OBJS = $(CCFILES:%.cc=$(LibCmm)$(O)%.o$(C)) $(CFILES:%.c=$(LibCmm)$(O)%.o$(C))

TESTS = test2    test3    test5    test6       testp5 

TSRC  = test2.cc test3.cc test5.cc test6.cc  \
	testp5.cc

MISCS = ChangeLog Copyright FileList Makefile Makefile.auto Makefile.dist \
	Makefile.schema Makefile.schema.orig README doc

OKFILES = $(CCFILES) $(CFILES) $(HFILES) $(TSRC) $(MISCS)


all: $(LibCmm)

junk:
	@ ls -d $(OKFILES) * | sort | grep -v CVS | uniq -u

clean:
	/bin/rm -rf *.o $(TESTS) libCmm.a

test : ${TESTS}
	 @ rm -f tests.out
	 @for i in ${TESTS}; do  \
	   ( echo "Running " $$i "..."; \
	     $$i >> tests.out 2>&1 ;  \
	   )                    \
	done

demo: demo1 demo2

samples:
	-(cd doc ; $(MAKE) samples)
	cp Copyright $(DocDir)/cmm/Copyright

$(LibCmm): $(OBJS)
	doranlib $(LibCmm)

$(LibCmm)(cmm.o): cmm.cc $(HFILES)
	@(SRC=`pwd` ; cd $(LibDir) ; \
	  echo "$(CXX) $(CXXFLAGS) -c -I$(IncDir) $$SRC/cmm.cc" ; \
	  $(CXX) $(CXXFLAGS) -c -I$(IncDir) $$SRC/cmm.cc ;  \
	  $(AR) $(LibCmm) cmm.o ; \
	  $(RM) cmm.o)

$(LibCmm)(tempheap.o): tempheap.cc tempheap.h $(HFILES)
	@(SRC=`pwd` ; cd $(LibDir) ; \
	  echo "$(CXX) $(CXXFLAGS) -c -I$(IncDir) $$SRC/tempheap.cc" ; \
	  $(CXX) $(CXXFLAGS) -c -I$(IncDir) $$SRC/tempheap.cc ;  \
	  $(AR) $(LibCmm) tempheap.o ; \
	  $(RM) tempheap.o)

$(LibCmm)(msw.o): msw.cc msw.h $(HFILES)
	@(SRC=`pwd` ; cd $(LibDir) ; \
	  echo "$(CXX) $(CXXFLAGS) -c -I$(IncDir) $$SRC/msw.cc" ; \
	  $(CXX) $(CXXFLAGS) -c -I$(IncDir) $$SRC/msw.cc ;  \
	  $(AR) $(LibCmm) msw.o ; \
	  $(RM) msw.o)

$(LibCmm)(memory.o): memory.c machine.h 
	(SRC=`pwd` ; cd $(LibDir) ; \
	  echo "$(CC) $(CFLAGS) -c -I$(IncDir) $$SRC/memory.c" ; \
	  $(CC) $(CFLAGS) -c -I$(IncDir) $$SRC/memory.c ;  \
	  $(AR) $(LibCmm) memory.o ; \
	  $(RM) memory.o)

test2:	test2.cc $(LibCmm)
	$(CXX) $(CXXFLAGS) -o test2 test2.cc $(LibCmm)
test3:	test3.cc $(LibCmm)
	$(CXX) $(CXXFLAGS) -o test3 test3.cc $(LibCmm)
test5:	test5.cc  $(LibCmm)
	$(CXX) $(CXXFLAGS) -o test5 test5.cc $(LibCmm) 
test6:	test6.cc  $(LibCmm)
	$(CXX) $(CXXFLAGS) -o test6 test6.cc $(LibCmm)
testp2: testp2.c $(LibCmm)
	${CC} ${CFLAGS} -g -o testp2 testp2.c $(LibCmm)
testp3: testp3.c $(LibCmm)
	${CC} ${CFLAGS} -g -o testp3 testp3.c $(LibCmm)
testp5: testp5.cc $(LibCmm)
	${CXX} ${OPTS} -o testp5 ${CXXFLAGS} testp5.cc  $(LibCmm)
demo1:	demo1.cc  $(LibCmm)
	$(CXX) $(CXXFLAGS) -o demo1 demo1.cc  $(LibCmm)
demo2:	demo2.cc  $(LibCmm)
	$(CXX) $(CXXFLAGS) -o demo2 demo2.cc  $(LibCmm)

