#-----------------------------------------------------------------------------
# Copyright (c) 1994 Regents of the University of Michigan.
# All rights reserved.
#
# Redistribution and use in source and binary forms are permitted
# provided that this notice is preserved and that due credit is given
# to the University of Michigan at Ann Arbor. The name of the University
# may not be used to endorse or promote products derived from this
# software without specific prior written permission. This software
# is provided ``as is'' without express or implied warranty.
#
#       LDAP library makefile
#
#-----------------------------------------------------------------------------

LDAPSRC	= ../..

SRCS	= bind.c open.c result.c error.c compare.c search.c \
	modify.c add.c modrdn.c delete.c abandon.c ufn.c cache.c \
	getfilter.c sbind.c kbind.c unbind.c friendly.c cldap.c \
	free.c disptmpl.c srchpref.c dsparse.c tmplout.c sort.c \
	getdn.c getentry.c getattr.c getvalues.c addentry.c \
	request.c getdxbyname.c os-ip.c url.c charset.c
OBJS	= bind.o open.o result.o error.o compare.o search.o \
	modify.o add.o modrdn.o delete.o abandon.o ufn.o cache.o \
	getfilter.o sbind.o kbind.o unbind.o friendly.o cldap.o \
	free.o disptmpl.o srchpref.o dsparse.o tmplout.o sort.o \
	getdn.o getentry.o getattr.o getvalues.o addentry.o \
	request.o getdxbyname.o os-ip.o url.o charset.o

HDIR	= ../../include

INCLUDES= -I$(HDIR) $(KRBINCLUDEFLAG)
DEFINES	= $(DEFS)

CFLAGS	= $(INCLUDES) $(DEFINES) $(ACFLAGS)
LIBS	= -L. -L../liblber -lldap -llber $(KRBLIBFLAG) $(KRBLIBS) $(ALIBS)

all:	libldap.a ltest ttest

libldap.a:	version.o
	$(AR) ruv $@ $(OBJS) version.o
	@if [ ! -z "$(RANLIB)" ]; then \
		$(RANLIB) $@; \
	fi; \
	$(RM) ../$@; \
	$(LN) libldap/$@ ../$@

ltest:	libldap.a test.o ../liblber/liblber.a
	$(CC) $(ALDFLAGS) -o $@ test.o $(LIBS)

ttest:	libldap.a tmpltest.o ../liblber/liblber.a
	$(CC) $(ALDFLAGS) -o $@ tmpltest.o $(LIBS)

version.c:	$(OBJS)
	$(RM) $@
	(u=$${USER-root} v=`$(CAT) ../../build/version` d=`$(PWD)` \
	h=`$(HOSTNAME)` t=`$(DATE)`; $(SED) -e "s|%WHEN%|$${t}|" \
	-e "s|%WHOANDWHERE%|$${u}@$${h}:$${d}|" \
	-e "s|%VERSION%|$${v}|" \
	< Version.c > $@)

install:	libldap.a ldapfilter.conf ldapfriendly ldaptemplates.conf ldapsearchprefs.conf FORCE
	-$(MKDIR) -p $(LDAP_LIBDIR) $(LDAP_ETCDIR)
	$(INSTALL) $(INSTALLFLAGS) -m 644 libldap.a $(LDAP_LIBDIR)
	@if [ ! -z "$(RANLIB)" ]; then \
		(cd /tmp; $(RANLIB) $(LDAP_LIBDIR)/libldap.a) \
	fi
	-$(MKDIR) -p $(LDAP_ETCDIR)
	-$(MV) $(LDAP_ETCDIR)/ldapfriendly $(LDAP_ETCDIR)/ldapfriendly-
	$(INSTALL) $(INSTALLFLAGS) -m 644 ldapfriendly $(LDAP_ETCDIR)
	-$(MV) $(LDAP_ETCDIR)/ldapfilter.conf $(LDAP_ETCDIR)/ldapfilter.conf-
	$(INSTALL) $(INSTALLFLAGS) -m 644 ldapfilter.conf $(LDAP_ETCDIR)
	-$(MV) $(LDAP_ETCDIR)/ldaptemplates.conf $(LDAP_ETCDIR)/ldaptemplates.conf-
	$(INSTALL) $(INSTALLFLAGS) -m 644 ldaptemplates.conf $(LDAP_ETCDIR)
	-$(MV) $(LDAP_ETCDIR)/ldapsearchprefs.conf $(LDAP_ETCDIR)/ldapsearchprefs.conf-
	$(INSTALL) $(INSTALLFLAGS) -m 644 ldapsearchprefs.conf $(LDAP_ETCDIR)

lint:	FORCE
	$(LINT) $(INCLUDES) $(DEFINES) $(SRCS)

5lint:	FORCE
	$(5LINT) $(INCLUDES) $(DEFINES) $(SRCS)

clean:	FORCE
	$(RM) libldap.a ../libldap.a ltest ttest *.o core a.out *.log version.c

depend:	FORCE
	$(MKDEP) $(INCLUDES) $(DEFINES) $(SRCS)

links:
	@$(LN) .src/*.[ch] .src/ldapfriendly .src/ldapfilter.conf \
		.src/ldaptemplates.conf .src/ldapsearchprefs.conf .

