UNAME:=	$(shell uname)
include ./template.$(UNAME)

# ---------------------------------------------------------------------
# RCSID     :   $Id: Makefile,v 1.22 2005/02/01 01:37:58 bjorn Exp $
# Project   :   synth
# Filename  :   Makefile
# Desc      :   Makefile for synth library
# ---------------------------------------------------------------------

DEFINES = $(WORDS) $(OS) $(EXTRA) $(TEST)
INCLUDES = $(NRINC)

DIR = $(shell basename `pwd`)

VERSION = 1.0.20
RELEASE = 1

# Increment INTERFACE if the library interface has 
# changed since last update, and then set REVISION to 0
INTERFACE = 1
# Increment REVISION if the library code has 
# changed since last update, but the interface has not
REVISION = 1
# Increment AGE if interfaces have been added since last public release
# Set AGE to 0 if interfaces have been removed since last public release
AGE = 0

#-------------------------------------------------------------------------

OBJS = \
	synth.lo \
	calib.lo \
	cache.lo \
	stimarray.lo \
	misc.lo

INCFILES = 	\
	synth.h \
	calib.h \
	cache.h \
	stimarray.h \
	misc.h 

#-------------------------------------------------------------------------

LIBNAME = libsynth.la 
ARCHOBJS = $(addprefix $(UNAME)/,$(OBJS))
ARCHLIB = $(UNAME)/libsynth.la
RPMFILE = $(DIR)-$(VERSION)-$(RELEASE).
SRPMFILE = $(DIR)-$(VERSION)-$(RELEASE).

#-------------------------------------------------------------------------
# Targets
#-------------------------------------------------------------------------
all: do-it-all

ifeq (.depend.$(UNAME),$(wildcard .depend.$(UNAME)))
include .depend.$(UNAME)
do-it-all:	$(LIBNAME)
else
do-it-all:	depend $(LIBNAME)
endif

depend: 
	$(RM) -f .depend.$(UNAME)
	$(AWK) -v UNAME=$(UNAME) -f depend.awk *.[ch]  > .depend.$(UNAME)
	chmod g+w .depend.$(UNAME)

$(LIBNAME): $(ARCHLIB)
.PHONY: $(LIBNAME)

syntest: syntest.c
	$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) \
		-L./$(UNAME)/.libs -lsynth\
		-L$(NRLIB) -l$(NRVER) \
		-lm \
		syntest.c -o syntest

matlab: 
	(cd matlab; $(MAKE) -e)
.PHONY: matlab

$(ARCHLIB):  $(ARCHOBJS)
	$(LIBTOOL) $(CC) $(DEFINES) $(CFLAGS) -o $(ARCHLIB) \
		-rpath $(INSTALL_LIBDIR) \
		-version-info $(INTERFACE):$(REVISION):$(AGE) \
		$(ARCHOBJS)

install: $(ARCHLIB)
	$(INSTALL) -d -m 0755 $(INSTALL_INCDIR)
	for x in $(INCFILES); \
		do \
			$(INSTALL) -m 0444 $$x $(INSTALL_INCDIR); \
		done;
	$(INSTALL) -d -m 0755 $(INSTALL_LIBDIR)
	$(LIBTOOL) $(INSTALL) -m 0444 $(ARCHLIB) $(INSTALL_LIBDIR)


clean:
	$(RM) -rf $(UNAME)/*.l[oa] $(UNAME)/.libs
	$(RM) -rf syntest
	(cd matlab; $(MAKE) -e clean)

distclean: clean
	$(RM) -rf $(UNAME)/*.l[oa] $(UNAME)/.libs
	(cd matlab; $(MAKE) -e clean)
	$(RM) *~ \#*
	$(RM) *.rpm
	$(RM) *.tar.gz

dist: 
	(cd ..; tar zcv -X $(DIR)/.exclude -f $(DIR)-$(VERSION).tar.gz $(DIR); mv $(DIR)-$(VERSION).tar.gz $(DIR))

rpm: 
	rm -f /usr/src/redhat/SOURCES/$(DIR)-*.tar.gz 
	cp $(DIR)-$(VERSION).tar.gz /usr/src/redhat/SOURCES
	rpm -ba --clean $(DIR).spec
	mv /usr/src/redhat/SRPMS/$(SRPMFILE)*rpm .
	mv /usr/src/redhat/RPMS/i386/$(RPMFILE)*rpm .


# ----------------------------------------------------------------------
# Implicit rules
# ----------------------------------------------------------------------
$(UNAME)/%.lo: %.c
	$(LIBTOOL) $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -c $< -o $@
