#
#      $RCSfile: Makefile,v $
#      $Revision: 3.6 $
#      $Date: 1992/07/20 19:01:13 $
#      $Author: brown $
#      $State: Exp $
#      $Locker:  $
#
#      Copyright (C) 1989 J. Eliot B. Moss
#

# The following flag should be set according to the "endianness" of the
# machine on which you are compiling.  For instance, a MIPS machine, such
# as the DecStation, is typically little endian, while a Sun machine is
# typically big endian.  This flag affects how bit field types are declared.
# The default is little endian.
ENDIAN = -DLITTLE_ENDIAN=1
# ENDIAN = -DLITTLE_ENDIAN=0   # for big endian machine

# The following define flags control compilation:
#	PROFILE		Enable Mneme profiling operations
#	DEBUGGING	Enable tracing of function calls/returns, and printing
#			of debug messages (most users will disable this)
# Disabling the profiling operations results in a performance gain. Users
# who do not wish to use the profiling operations and wish for optimal
# performance should leave PROFILE undefined.
DEFINES = -DPROFILE

# Set as desired
CFLAGS = -g
CC=cc

AR=ar

# ranlib if available
RANLIB = ranlib
# RANLIB = echo

# install if available
INSTALL = install -c
# INSTALL = cp

# libMn.a destination
LIBDIR = /usr/local/lib

incs = mneme.h lang.h
mnincs = \
	mn_direct.h \
	mn_exception.h \
	mn_file.h \
	mn_general.h \
	mn_handle.h \
	mn_memory.h \
	mn_object.h \
	mn_pool.h \
	mn_profile.h \
	mn_rcode.h \
	mn_strat.h \
	mn_txn.h \
	mn_xtypes.h

# include files destination
IDIR = /usr/include/mneme

SHELL=/bin/sh

libMn.a: mnemeobjs serverobjs $(incs)
	rm -f libMn.a
	cd mneme; $(AR) r ../libMn.a *.o
	cd server; $(AR) r ../libMn.a *.o

mnemeobjs:
	cd mneme; $(MAKE) DEFINES="$(DEFINES)" ENDIAN="$(ENDIAN)" CC="$(CC)" CFLAGS="$(CFLAGS)"

serverobjs:
	cd server; $(MAKE) DEFINES="$(DEFINES)" CC="$(CC)" CFLAGS="$(CFLAGS)"

local: libMn.a
	$(RANLIB) libMn.a

install: libMn.a 
	$(INSTALL) libMn.a $(LIBDIR)
	$(RANLIB) $(LIBDIR)/libMn.a
	-mkdir $(IDIR)
	-mkdir $(IDIR)/mneme
	cd $(IDIR); rm -f $(incs)
	cd $(IDIR)/mneme; rm -f $(mnincs)
	cp $(incs) $(IDIR)
	cd mneme; cp $(mnincs) $(IDIR)/mneme
	cd $(IDIR); chmod 0444 $(incs)
	cd $(IDIR)/mneme; chmod 0444 $(mnincs)

clean:
	cd mneme; $(MAKE) clean
	cd server; $(MAKE) clean
	cd examples; $(MAKE) clean

srcs = README Makefile lang.h server.h mneme.h

realclean: clean
	-rm libMn.a

RELEASE = dist
mneme-dist: $(srcs)
	-rm -rf mneme-$(RELEASE)
	mkdir mneme-$(RELEASE)
	ln $(srcs) mneme-$(RELEASE)
	cd mneme; $(MAKE) RELEASE="$(RELEASE)" mneme-dist
	cd server; $(MAKE) RELEASE="$(RELEASE)" mneme-dist
	cd examples; $(MAKE) RELEASE="$(RELEASE)" mneme-dist
	cd doc; $(MAKE) RELEASE="$(RELEASE)" mneme-dist

file-dist: mneme-dist
	tar chvf mneme-$(RELEASE).tar mneme-$(RELEASE)
	compress < mneme-$(RELEASE).tar > mneme-$(RELEASE).tar.Z

tape-dist: mneme-dist
	tar chv mneme-$(RELEASE)
