# IR toolkit for tcl/tk
# (c) Index Data 1995-2004
# See the file LICENSE for details.
# $Id: Makefile.in,v 1.65 2005/03/10 14:10:54 adam Exp $
SHELL=/bin/sh

# IrTcl Version
VERSION=1.4.3

# Directory prefix with machine independent files (scripts, setup files, etc.)
prefix = /usr

# Directory prefix with machine dependent files (executables, libraries)
exec_prefix = ${prefix}

DESTDIR=

# Install directories
BINDIR=$(exec_prefix)/bin
LIBDIR=$(exec_prefix)/lib
MANDIR=$(prefix)/man
INCDIR=$(prefix)/include
IRTCLDIR=$(prefix)/lib/irtcl

CC=gcc

# Tcl libraries and include files
TCLLIB=
TCLINC=

# Tk & X11 libraries and include files
TKLIB=
TKINC=

# Shared libraries definitions
SHLIB_CFLAGS = 
SHLIB_LD = 
SHLIB_SUFFIX = 
SHLIB_VERSION = 

# Where are YAZ libraries located?
YAZLIB=-lyaz -lexslt -lxslt -lxml2 -lpthread -lssl -lcrypto -lwrap -lnsl
# Where are YAZ header files located?
YAZINC=-pthread -DYAZ_POSIX_THREADS=1 -DYAZ_HAVE_XML2=1 -DYAZ_HAVE_XSLT=1 -DYAZ_HAVE_EXSLT=1 -I/usr/include/libxml2

# All include paths
INCLUDE=-I. $(YAZINC) $(TKINC) $(TCLINC) 

# All command line options except CFLAGS
DEFS=-DCCL2RPN=0 -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DIRTCLDIR=\"$(IRTCLDIR)\" \
	$(INCLUDE) -DIR_TCL_VERSION=\"$(VERSION)\"

INSTALL = /usr/bin/install -c
INSTALL_PROGRAM = ${INSTALL}
INSTALL_DATA = ${INSTALL} -m 644

RANLIB = ranlib

O=ir-tcl.o marc.o queue.o mem.o grs.o explain.o select.o

all: ir-tcl

ir-tcl: libirtcl.a tclmain.o
	$(CC) $(CFLAGS) tclmain.o -o ir-tcl libirtcl.a $(YAZLIB) $(TCLLIB) 

libirtcl.a: $(O)
	rm -f libirtcl.a
	ar qc libirtcl.a $(O)
	$(RANLIB) libirtcl.a

irtcl-shared: $(O)
	rm -f irtcl-shared
	${SHLIB_LD} -o irtcl-shared $(O) $(YAZLIB)

WAISDIR=../freeWAIS-sf-2.0

wais-tcl: libirtcl.a wais-tcl.o waismain.o
	$(CC) $(CFLAGS) wais-tcl.o waismain.o -o wais-tcl libirtcl.a \
		$(YAZLIB)  $(WAISDIR)/ir/libwais.a $(TCLLIB)

waismain.o: tclmain.c
	$(CC) -c $(CFLAGS) -DUSE_WAIS=1 $(DEFS) tclmain.c -o waismain.o

wais-tcl.o: wais-tcl.c
	$(CC) -c $(CFLAGS) -I$(WAISDIR)/ir $(DEFS) wais-tcl.c

install.man:
	$(INSTALL) -d $(DESTDIR)$(MANDIR)/mann
	@cd doc; if [ -d $(DESTDIR)$(MANDIR)/mann ]; then \
		for p in *.n; do \
			$(INSTALL_DATA) $$p $(DESTDIR)$(MANDIR)/mann; \
		done; \
	fi

install: ir-tcl
	$(INSTALL) -d $(DESTDIR)$(IRTCLDIR)/formats
	$(INSTALL) -d $(DESTDIR)$(IRTCLDIR)/bitmaps
	$(INSTALL) -d $(DESTDIR)$(IRTCLDIR)/doc
	$(INSTALL) -d $(DESTDIR)$(BINDIR)
	@if [ -f ir-tcl ]; then \
		$(INSTALL_PROGRAM) ir-tcl $(DESTDIR)$(BINDIR); \
	fi
	@if [ -f irtcl-shared ]; then \
		$(INSTALL_PROGRAM) irtcl-shared $(DESTDIR)$(IRTCLDIR); \
	fi
	$(INSTALL_DATA) libirtcl.a $(DESTDIR)$(LIBDIR)
	$(INSTALL_DATA) ir-tcl.h $(DESTDIR)$(INCDIR)
	@if [ -f ir-tk ]; then \
		$(INSTALL_PROGRAM) ir-tk $(DESTDIR)$(BINDIR); \
	fi
	@echo "#! /usr/bin/wish -f" >head.bak; \
	cat head.bak client.tcl| sed "s,^set libdir LIBDIR,set libdir $(IRTCLDIR)," >client.bak; \
	$(INSTALL_PROGRAM) client.bak $(DESTDIR)$(BINDIR)/irclient; \
	if [ -f $(DESTDIR)$(IRTCLDIR)/irtdb.tcl ]; then \
		echo "irtdb.tcl already exists"; \
		echo "Installing irtdb.tcl.n"; \
		cp irtdb.tcl irtdb.tcl.n; \
		$(INSTALL_DATA) irtdb.tcl.n $(DESTDIR)$(IRTCLDIR); \
		rm irtdb.tcl.n; \
	else \
		echo "Installing irtdb.tcl"; \
		$(INSTALL_DATA) irtdb.tcl $(DESTDIR)$(IRTCLDIR); \
	fi
	@for f in *.tcl; do \
		$(INSTALL_DATA) $$f $(DESTDIR)$(IRTCLDIR); \
	done
	@for b in formats/*.tcl; do \
		if [ -f $$b ]; then \
			$(INSTALL_DATA) $$b $(DESTDIR)$(IRTCLDIR)/formats; \
		fi; \
	done
	@for b in bitmaps/*; do \
		if [ -f $$b ]; then \
			$(INSTALL_DATA) $$b $(DESTDIR)$(IRTCLDIR)/bitmaps; \
		fi; \
	done
	@for b in doc/*; do \
		if [ -f $$b ]; then \
			$(INSTALL_DATA) $$b $(DESTDIR)$(IRTCLDIR)/doc; \
		fi; \
	done

clean:
	rm -f *.[oa] ir-tk ir-tcl wais-tcl core 
	rm -f *mon.out *.bak config.cache irtcl-shared

autoconf:
	-rm config.cache
	autoconf
	configure

.c.o:
	$(CC) -c $(CFLAGS) $(SHLIB_CFLAGS) $(DEFS) $<

$(O) tkmain.o tclmain.o wais-tcl.o waismain.o: ir-tcl.h ir-tclp.h
