# ---------------------------------------------------------------------
# RCSID		: 	$Id: Makefile,v 1.7 1999/07/15 15:04:49 bjarthur Exp $
# Project	:	sanal
# Filename	:	Makefile
# Desc		:	Makefile for sanal library
# ---------------------------------------------------------------------
UNAME	:=	$(shell uname)
DIR	:= $(shell basename `pwd`)

VERSION = 1.1.2

# 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 = 0
# 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

# ------------------------------------------------------------
# Useful programs
# ------------------------------------------------------------
CC			= gcc
CPP			= gcc - -E -P
LD			= gcc 
CDEBUG		= -g
LDEBUG		= -g
INSTALL		= install -c
RM			= /bin/rm -f
AR			= ar
RANLIB		= ranlib
AWK			= gawk
LIBTOOL		= libtool

# set STRIP to 
# STRIP =  
# to not strip executables during install;
# set STRIP to 
# STRIP = -s
# to strip executables during install;
STRIP		= 

LIBNAME = libsanal.la

# ------------------------------------------------------------
# Install stuff
# ------------------------------------------------------------
INSTALL_ROOT = /usr/local
INSTALL_LIBDIR = $(INSTALL_ROOT)/lib
INSTALL_INCDIR	= $(INSTALL_ROOT)/include/sanal
LIBC6RPMDIR	= /usr/local/Archives/dist/RPMS/libc6
LIBC5RPMDIR	= /usr/local/Archives/dist/RPMS/libc5
SRPMDIR	= /usr/local/Archives/dist/SRPMS

# ------------------------------------------------------------
# CFLAGS for different operating systems
#-------------------------------------------------------------
ifeq "$(UNAME)" "Linux"
CFLAGS  = 	-Wall -m486 -D_GNU_SOURCE $(CDEBUG)
else
ifeq "$(UNAME)" "SunOS"
CFLAGS     = $(CDEBUG) -D_GNU_SOURCE
endif
endif

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

OBJS = 	srl.lo \
		sahist.lo \
		density.lo \
		correl.lo \
		psth.lo \
		isih.lo 
INCFILES = 	correl.h \
			density.h \
			isih.h \
			psth.h \
			sahist.h \
			srl.h 

ARCHOBJS = $(addprefix $(UNAME)/,$(OBJS)) 
ARCHLIB = $(addprefix $(UNAME)/,$(LIBNAME)) 
RPMFILE = $(DIR)-$(VERSION)-1.i386.rpm
SRPMFILE = $(DIR)-$(VERSION)-1.src.rpm


# ------------------------------------------------------------
# Targets
# ------------------------------------------------------------

all: $(LIBNAME)

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

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

install:
	@mkdirhier $(INSTALL_INCDIR)
	@echo "Installing include files ..."
	@for x in $(INCFILES);\
		do\
			$(INSTALL) $(STRIP) -m 0444 $$x $(INSTALL_INCDIR);\
			echo "  $$x.";\
		done
	@mkdirhier $(INSTALL_LIBDIR)
	$(LIBTOOL) $(INSTALL) -m 0644 $(ARCHLIB) $(INSTALL_LIBDIR)
	@echo "Done."

clean:
	$(RM) $(UNAME)/*.l[oa] core $(UNAME)/.libs/*

distclean: clean
	$(RM) core
	$(RM) tags
	$(RM) *~
	$(RM) \#*

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

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

update6:
	mv $(SRPMFILE) $(SRPMDIR)
	mv $(RPMFILE) $(LIBC6RPMDIR)
	ln -sf $(SRPMDIR)/$(SRPMFILE) $(SRPMDIR)/$(DIR)-current.src.rpm
	ln -sf $(LIBC6RPMDIR)/$(RPMFILE) $(LIBC6RPMDIR)/$(DIR)-current.i386.rpm

update5:
	mv $(SRPMFILE) $(SRPMDIR)
	mv $(RPMFILE) $(LIBC5RPMDIR)
	ln -sf $(SRPMDIR)/$(SRPMFILE) $(SRPMDIR)/$(DIR)-current.src.rpm
	ln -sf $(LIBC5RPMDIR)/$(RPMFILE) $(LIBC5RPMDIR)/$(DIR)-current.i386.rpm

tags:
	ctags -idefgstuvx *.[ch]

# ------------------------------------------------------------
# Dependencies
# ------------------------------------------------------------
srl.o:	srl.c srl.h
sahist.o:	sahist.c sahist.h
density.o:	density.c density.h
correl.o:	correl.c correl.h
psth.o:	psth.c psth.h
isih.o:	isih.c isih.h

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