#-----------------------------------------------------------------------------
# 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	= ..
OUTDIR  = $(LDAPSRC)/unix
PGPPFLDIR = $(LDAPSRC)/../../pfl
PGPPFLINCLUDES = -I$(PGPPFLDIR)/common -I$(PGPPFLDIR)/unix

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 regex.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 regex.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	= $(LDAPSRC)/include

INCLUDES= -I$(HDIR) $(PGPPFLINCLUDES)

DEFINES	= $(DEFS) -DFILTERFILE="\"$(RUNTIMEETCDIR)/ldapfilter.conf\"" \
	  -DTEMPLATEFILE="\"$(RUNTIMEETCDIR)/ldaptemplates.conf\""

CFLAGS	= $(INCLUDES) $(DEFINES) $(ACFLAGS)
LDFLAGS = -L$(OUTDIR)
LIBS	= -lldap -llber

all:	$(OUTDIR)/libldap.a DONE

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

DONE:
	@set -x; echo $(OBJS) > $@

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

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

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 $(LIBDIR)
	$(INSTALL) $(INSTALLFLAGS) -m 644 libldap.a $(LIBDIR)
	@if [ ! -z "$(RANLIB)" ]; then \
		(cd /tmp; $(RANLIB) $(LIBDIR)/libldap.a) \
	fi
	-$(MKDIR) -p $(ETCDIR)
	-$(MV) $(ETCDIR)/ldapfriendly $(ETCDIR)/ldapfriendly-
	$(INSTALL) $(INSTALLFLAGS) -m 644 ldapfriendly $(ETCDIR)
	-$(MV) $(ETCDIR)/ldapfilter.conf $(ETCDIR)/ldapfilter.conf-
	$(INSTALL) $(INSTALLFLAGS) -m 644 ldapfilter.conf $(ETCDIR)
	-$(MV) $(ETCDIR)/ldaptemplates.conf $(ETCDIR)/ldaptemplates.conf-
	$(INSTALL) $(INSTALLFLAGS) -m 644 ldaptemplates.conf $(ETCDIR)
	-$(MV) $(ETCDIR)/ldapsearchprefs.conf $(ETCDIR)/ldapsearchprefs.conf-
	$(INSTALL) $(INSTALLFLAGS) -m 644 ldapsearchprefs.conf $(ETCDIR)

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

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

clean:	FORCE
	$(RM) $(OUTDIR)/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 .

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

bind.o: bind.c ../include/lber.h ../include/proto-ldap.h
open.o: open.c ../include/lber.h ../include/proto-ldap.h
result.o: result.c ../include/proto-lber.h ldap-int.h
error.o: error.c ../include/lber.h ../include/proto-ldap.h
compare.o: compare.c ../include/lber.h ../include/proto-ldap.h
search.o: search.c ../include/lber.h ../include/proto-ldap.h
modify.o: modify.c ../include/lber.h ../include/proto-ldap.h
add.o: add.c ../include/lber.h ../include/proto-ldap.h
modrdn.o: modrdn.c ../include/lber.h ../include/proto-ldap.h
delete.o: delete.c ../include/lber.h ../include/proto-ldap.h
abandon.o: abandon.c ../include/lber.h ../include/proto-ldap.h
ufn.o: ufn.c ../include/lber.h ../include/proto-ldap.h
cache.o: cache.c ../include/lber.h ../include/proto-ldap.h
getfilter.o: getfilter.c ../include/lber.h ../include/proto-ldap.h
regex.o: regex.c
sbind.o: sbind.c ../include/lber.h ../include/proto-ldap.h
kbind.o: kbind.c
unbind.o: unbind.c ../include/lber.h ../include/proto-ldap.h
friendly.o: friendly.c ../include/lber.h ../include/proto-ldap.h
cldap.o: cldap.c
free.o: free.c ../include/lber.h ../include/proto-ldap.h
disptmpl.o: disptmpl.c ../include/lber.h ../include/proto-ldap.h
srchpref.o: srchpref.c ../include/lber.h ../include/proto-ldap.h
dsparse.o: dsparse.c ../include/lber.h ../include/proto-ldap.h
tmplout.o: tmplout.c ../include/lber.h ../include/proto-ldap.h
sort.o: sort.c ../include/lber.h ../include/proto-ldap.h
getdn.o: getdn.c ../include/lber.h ../include/proto-ldap.h
getentry.o: getentry.c ../include/lber.h ../include/proto-ldap.h
getattr.o: getattr.c ../include/lber.h ../include/proto-ldap.h
getvalues.o: getvalues.c ../include/lber.h ../include/proto-ldap.h
addentry.o: addentry.c ../include/lber.h ../include/proto-ldap.h
request.o: request.c ../include/proto-lber.h ldap-int.h
getdxbyname.o: getdxbyname.c
os-ip.o: os-ip.c ../include/proto-lber.h
url.o: url.c ../include/lber.h ../include/proto-ldap.h
charset.o: charset.c

# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
