#----------------------------------------------------------------------------
# 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 tools makefile
#
#-----------------------------------------------------------------------------
LDAPSRC	= ../..
HDIR	= $(LDAPSRC)/include
LDIR	= $(LDAPSRC)/libraries
VERSIONFILE = $(LDAPSRC)/build/version

SRCS	= ldapsearch.c ldapmodify.c ldapdelete.c ldapmodrdn.c
OBJS	= ldapsearch.o ldapmodify.o ldapdelete.o ldapmodrdn.o

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

CFLAGS	= $(INCLUDES) $(DEFINES) $(ACFLAGS)
LIBS	= -lldap -llber -lldif $(KRBLIBFLAG) $(KRBLIBS) $(ALIBS)

all:	ldapsearch ldapmodify ldapdelete ldapmodrdn ldapadd

ldapsearch:	ldsversion.o
	$(CC) $(ALDFLAGS) -o $@ ldapsearch.o ldsversion.o \
		-L$(LDIR) $(LIBS)

ldapmodify:	ldmversion.o
	$(CC) $(ALDFLAGS) -o $@ ldapmodify.o ldmversion.o \
		-L$(LDIR) $(LIBS)

ldapdelete:	lddversion.o
	$(CC) $(ALDFLAGS) -o $@ ldapdelete.o lddversion.o -L$(LDIR) $(LIBS)

ldapmodrdn:	ldrversion.o
	$(CC) $(ALDFLAGS) -o $@ ldapmodrdn.o ldrversion.o -L$(LDIR) $(LIBS)

ldapadd:	ldapmodify
	$(RM) $@
	$(HARDLN) ldapmodify ldapadd

ldsversion.c: ldapsearch.o
	$(RM) $@
	(u=$${USER-root} v=`$(CAT) $(VERSIONFILE)` d=`$(PWD)` h=`$(HOSTNAME)` \
	t=`$(DATE)`; $(SED) -e "s|%WHEN%|$${t}|" \
	-e "s|%WHOANDWHERE%|$${u}@$${h}:$${d}|" \
	-e "s|%VERSION%|$${v}|" \
	< Versionlds.c > $@)

ldmversion.c: ldapmodify.o
	$(RM) $@
	(u=$${USER-root} v=`$(CAT) $(VERSIONFILE)` d=`$(PWD)` h=`$(HOSTNAME)` \
	t=`$(DATE)`; $(SED) -e "s|%WHEN%|$${t}|" \
	-e "s|%WHOANDWHERE%|$${u}@$${h}:$${d}|" \
	-e "s|%VERSION%|$${v}|" \
	< Versionldm.c > $@)

lddversion.c: ldapdelete.o
	$(RM) $@
	(u=$${USER-root} v=`$(CAT) $(VERSIONFILE)` d=`$(PWD)` h=`$(HOSTNAME)` \
	t=`$(DATE)`; $(SED) -e "s|%WHEN%|$${t}|" \
	-e "s|%WHOANDWHERE%|$${u}@$${h}:$${d}|" \
	-e "s|%VERSION%|$${v}|" \
	< Versionldd.c > $@)

ldrversion.c: ldapmodrdn.o
	$(RM) $@
	(u=$${USER-root} v=`$(CAT) $(VERSIONFILE)` d=`$(PWD)` h=`$(HOSTNAME)` \
	t=`$(DATE)`; $(SED) -e "s|%WHEN%|$${t}|" \
	-e "s|%WHOANDWHERE%|$${u}@$${h}:$${d}|" \
	-e "s|%VERSION%|$${v}|" \
	< Versionldr.c > $@)

install:	ldapsearch ldapmodify ldapdelete ldapmodrdn ldapadd FORCE
	-$(MKDIR) -p $(BINDIR)
	$(INSTALL) $(INSTALLFLAGS) -m 755 ldapsearch $(BINDIR)
	$(INSTALL) $(INSTALLFLAGS) -m 755 ldapmodify $(BINDIR)
	$(INSTALL) $(INSTALLFLAGS) -m 755 ldapdelete $(BINDIR)
	$(INSTALL) $(INSTALLFLAGS) -m 755 ldapmodrdn $(BINDIR)
	$(RM) $(BINDIR)/ldapadd
	$(HARDLN) $(BINDIR)/ldapmodify $(BINDIR)/ldapadd

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

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

clean:	FORCE
	$(RM) *.o core a.out ld*version.c ldapsearch ldapmodify ldapdelete \
		ldapmodrdn ldapadd

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

links:
	@$(LN) .src/*.[ch] .

# DO NOT DELETE THIS LINE -- mkdep uses it.
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.

ldapsearch.o: ldapsearch.c ../../include/lber.h ../../include/ldap.h
ldapsearch.o: ../../include/ldif.h ../../include/ldapconfig.h
ldapmodify.o: ldapmodify.c ../../include/lber.h ../../include/ldap.h
ldapmodify.o: ../../include/ldif.h ../../include/ldapconfig.h
ldapdelete.o: ldapdelete.c ../../include/lber.h ../../include/ldap.h
ldapdelete.o: ../../include/ldapconfig.h
ldapmodrdn.o: ldapmodrdn.c ../../include/lber.h ../../include/ldap.h
ldapmodrdn.o: ../../include/ldapconfig.h

# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
