#
# This file is a Makefile for Neo, the NeoSoft extensions to Tcl.
# If it has the name "Makefile.in" then it is a template for a
# Makefile;  to generate the actual Makefile, run "./configure",
# which is a configuration script generated by the "autoconf" program
# (constructs like "@foo@" will get replaced in the actual Makefile.
#

VERSION = @NEO_VERSION@
LIBNAME = @NEO_SHARED_LIB_FILE@

# Default top-level directories in which to install architecture-
# specific files (exec_prefix) and machine-independent files such
# as scripts (prefix).  The values specified here may be overridden
# at configure-time with the --exec-prefix and --prefix options
# to the "configure" script.

prefix =        @prefix@
exec_prefix =       @exec_prefix@

# The following definition can be set to non-null for special systems
# like AFS with replication.  It allows the pathnames used for installation
# to be different than those used for actually reference files at
# run-time.  INSTALL_ROOT is prepended to $prefix and $exec_prefix
# when installing files.
INSTALL_ROOT =

# Directory in which to search for tcl libraries
NEO_LIBRARY	= $(exec_prefix)/lib/neo$(VERSION)

# Directory in which to install the neotcl binary:
BIN_INSTALL_DIR = $(INSTALL_ROOT)$(exec_prefix)/bin

# Directory in which to install the .a or .so binary for the Neo library:
LIB_INSTALL_DIR = $(INSTALL_ROOT)$(exec_prefix)/lib

# Path to use at runtime to refer to LIB_INSTALL_DIR:
LIB_RUNTIME_DIR =	$(exec_prefix)/lib

# Top-level directory for html entries:
HTML_INSTALL_DIR =	$(INSTALL_ROOT)$(prefix)/html


# The symbols below provide support for dynamic loading and shared
# libraries.  The values of the symbols are normally set by the
# configure script.  You shouldn't normally need to modify any of
# these definitions by hand.

SHLIB_CFLAGS = @NEO_SHLIB_CFLAGS@

NEO_LIB_FILE = @NEO_LIB_FILE@

NEO_SHARED_LIB_FILE = @NEO_SHARED_LIB_FILE@

# The directory containing the Tcl sources and headers appropriate
# for this version of Neo ("srcdir" will be replaced or has already
# been replaced by the configure script):
TCL_GENERIC_DIR =   @TCL_SRC_DIR@/generic

# The top of the TclX directory tree
TCLX_TOP_DIR	=	@TCLX_TOP_DIR@

# The directory where tclExtend.h will be:
TCLX_TCL_GEN_DIR =	${TCLX_TOP_DIR}/tcl/generic

# The directory where tclXunixPort.h will be:
TCLX_TCL_UNIX_DIR =	${TCLX_TOP_DIR}/tcl/unix

# The path to tclX the runtcl script:
TCLX_RUNTCL	=	${TCLX_TOP_DIR}/unix/runtcl

# The directory containing the Tcl library archive file appropriate
# for this version of Neo:
TCL_BIN_DIR =       @TCL_BIN_DIR@


# The symbol below provides support for dynamic loading and shared
# libraries.  See configure.in for a description of what it means.
# The values of the symbolis normally set by the configure script.

SHLIB_LD = @SHLIB_LD@

# Set to the options to include libdb.a (eg. -L../tools/blah -ldb)

DB_LDFLAGS	= @dblibflags@
DB_CFLAGS	= @dbinclude@
DB_BUILD	= @dbbuild@
DB_DIR		= @dbdir@

# Set to the options to include libldap.a and liblber.a 
# (eg. -L../tools/blah -lldap -llber)

LDAP_LDFLAGS	= @ldaplibflags@
LDAP_CFLAGS	= @ldapinclude@
LDAP_BUILD	= @ldapbuild@
LDAP_DIR	= @ldapdir@


#----------------------------------------------------------------
# The information below is modified by the configure script when
# Makefile is generated from Makefile.in.  You shouldn't normally
# modify any of this stuff by hand.
#----------------------------------------------------------------

AC_FLAGS =      @DEFS@
INSTALL=	@INSTALL@
INSTALL_PROGRAM =   @INSTALL_PROGRAM@
INSTALL_DATA =      @INSTALL_DATA@
RANLIB =        @RANLIB@
SRC_DIR =       @srcdir@/..
TOP_DIR =       @srcdir@/..
GENERIC_DIR =       $(TOP_DIR)/generic

#----------------------------------------------------------------
# The information below should be usable as is.  The configure
# script won't modify it and you shouldn't need to modify it
# either.
#----------------------------------------------------------------


OBJS= neoXcrypt.o neoPkgInit.o neoXwww.o neoXgeneral.o neoXcomma.o \
	neoXmd5.o md5c.o util_md5.o neoXkdebug.o neoCbuf.o @pkg_optobj@

LIBDIR=$(exec_prefix)/lib
INCDIR=$(prefix)/include

LIBS= @pkg_ldflags@ @LIBS@ @TCLX_BUILD_LIB_SPEC@ @ITCL_BUILD_LIB_SPEC@ @TCL_BUILD_LIB_SPEC@ @pkg_libs@ @TCL_LIBS@ $(DB_LDFLAGS) $(LDAP_LDFLAGS) -lc @BSDLIB@
TK_LIBS=@TKX_BUILD_LIB_SPEC@ @TK_BUILD_LIB_SPEC@
TK_VERSION=@TK_VERSION@

CC =        @CC@
CC_SWITCHES =   ${CFLAGS} @NEO_SHLIB_CFLAGS@ -I. @pkg_cflags@ \
-I${TCL_GENERIC_DIR} -I${TCLX_TCL_GEN_DIR} ${AC_FLAGS} ${PROTO_FLAGS} \
${SECURITY_FLAGS} ${MEM_DEBUG_FLAGS} ${KEYSYM_FLAGS} \
-DNEO_LIBRARY=\"${NEO_LIBRARY}\"

TK_SWITCHES = ${CC_SWITCHES} -I@TK_SRC_DIR@/generic @TK_XINCLUDES@


.c.o:
	$(CC) -c $(CC_SWITCHES) $<

all:	@NEO_LIB_FILE@ neotcl @NEOWISH@

@NEO_LIB_FILE@:	$(OBJS)
	rm -f @NEO_LIB_FILE@
	@MAKE_LIB@
	$(RANLIB) @NEO_LIB_FILE@

neoXdb.o: neoXdb.c @dbtarget@
	$(CC) -c $(DB_CFLAGS) $(CC_SWITCHES) $<

neoXldap.o: neoXldap.c
	$(CC) -c $(LDAP_CFLAGS) $(CC_SWITCHES) $<

clean: clean_db_$(DB_BUILD)
	-rm -f neotcl neowish
	-rm -f *.o *.a *.so*
	-rm -rf library
	cd ../neolibs; make clean

distclean: clean distclean_db_$(DB_BUILD)
	rm -f Makefile config.cache config.log config.status
	rm -f neoConfig.sh pkgIndex.tcl neoXconfig.h

install: install-binaries install-libraries install-man

install-binaries: @NEO_LIB_FILE@ neotcl @NEOWISH@ install_db_$(DB_BUILD)
	@-mkdir -p $(BIN_INSTALL_DIR)
	$(INSTALL_PROGRAM) neotcl $(BIN_INSTALL_DIR)/neotcl$(VERSION)
	@DBLINK@
	@if [ -n "@NEOWISH@" ] ; then \
	    echo $(INSTALL_PROGRAM) neowish $(BIN_INSTALL_DIR)/neowish$(TK_VERSION); \
	    $(INSTALL_PROGRAM) neowish $(BIN_INSTALL_DIR)/neowish$(TK_VERSION); \
	fi
	$(INSTALL_DATA) @NEO_LIB_FILE@ $(LIB_INSTALL_DIR)
	@if [ "$(NEO_LIB_FILE)" = "$(NEO_SHARED_LIB_FILE)" ] ; then \
		echo Installing pkgIndex.tcl in $(NEO_LIBRARY); \
		mkdir -p $(NEO_LIBRARY); \
		$(INSTALL_DATA) pkgIndex.tcl $(NEO_LIBRARY); \
	fi
	@echo "Installing neoConfig.sh"
	@$(INSTALL_DATA) neoConfig.sh $(LIB_INSTALL_DIR)/neoConfig.sh

install-libraries:
	@-mkdir -p $(NEO_LIBRARY)
	cd ../neolibs; make
	for i in ../neolibs/*.tcl; do \
		echo Installing $$i; \
		$(INSTALL_DATA) $$i $(NEO_LIBRARY); \
	done
	@echo Creating tclIndex for library
	echo "cd $(NEO_LIBRARY); auto_mkindex . *.tcl" | \
	LD_LIBRARY_PATH=.:$(LIB_INSTALL_DIR):$(LIB_INSTALL_DIR)/../BerkeleyDB/lib:$$LD_LIBRARY_PATH ./neotcl

install-man:
	@for i in $(HTML_INSTALL_DIR) $(HTML_INSTALL_DIR)/neo$(VERSION); \
	    do \
	    if [ ! -d $$i ] ; then \
		echo "Making directory $$i"; \
		mkdir $$i; \
		chmod 755 $$i; \
		else true; \
		fi; \
	    done;
	@for i in ../doc/*.html; \
	    do \
	    echo "Installing $$i"; \
	    $(INSTALL_DATA) $$i $(HTML_INSTALL_DIR)/neo$(VERSION); \
	    done;


TCLOFILES= tclAppInit.o

neotcl:	$(TCLOFILES) @NEO_LIB_FILE@ @dbtarget@
	$(CC) @LD_FLAGS@ $(TCLOFILES) @NEO_BUILD_LIB_SPEC@ $(LIBS) \
	@TCL_LD_SEARCH_FLAGS@ -o neotcl

tkAppInit.o: tkAppInit.c
	$(CC) -c ${TK_SWITCHES} tkAppInit.c

neowish:tkAppInit.o @NEO_LIB_FILE@ @dbtarget@
	$(CC) @LD_FLAGS@ tkAppInit.o @NEO_BUILD_LIB_SPEC@ $(TK_LIBS) $(LIBS) \
	@TCL_LD_SEARCH_FLAGS@ -o neowish

$(DB_DIR)/@dblibname@: $(DB_DIR)/Makefile
	@echo Building @dblibname@
	cd $(DB_DIR); make

install_db_no:

install_db_yes: $(DB_DIR)/@dblibname@
	@echo Installing @dblibname@
	cd $(DB_DIR); make install

$(DB_DIR)/Makefile:
	@echo Running configure for @dblibname@ using parameters from config.status
	sed -n -e'1,/^$$/p' config.status | sed -e's:^# \./:./:' | \
	(cd $(DB_DIR); $(SHELL))

clean_db_no:

clean_db_yes:
	-cd $(DB_DIR); make clean

distclean_db_no:

distclean_db_yes:
	-cd $(DB_DIR); make distclean
