#-----------------------------------------------------------------------------
# Copyright (c) 1990 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 lightweight X.500 Directory access top level makefile
#
#-----------------------------------------------------------------------------

#
# Edit the following variables to have appropriate values for your system
#

#
# where to install the ldap stuff
#
ETCDIR		= /usr/local/etc	# where to put servers
INCLUDEDIR	= /usr/include		# where to put ldap.h & lber.h
LIBDIR		= /usr/lib		# where to put libraries
MANDIR		= /usr/man		# where to put man pages
BINDIR		= /usr/local/bin	# where to put clients

#
# flags telling where to find isode stuff
#
ISODEINCLUDEFLAG= -I/usr/include/isode		# includes
ISODELIBFLAG	= -L/usr/local/lib		# libraries
ISODELIBS	= -ldsap -lisode -lm # -lgdbm 	# uncomment gdbm if TURBO_DISK

#
# flags telling where to find kerberos stuff - not necessary unless
# you add -DKERBEROS to ACFLAGS below
#
KRBINCLUDEFLAG	= # -I/usr/local/kerberos/usr/include	 # includes
KRBLIBFLAG	= # -L/usr/local/kerberos/usr/athena/lib # libraries
KRBLIBS		= # -lkrb -ldes				 # kerberos libraries

#
# You may want to change some of these things too
#
# two kinds of things go in ACFLAGS, global compiler flags (like -g to
# generate symbol table info), and global defines (like -DKERBEROS to enable
# kerberos version 4 authentication, or -DLDAP_DEBUG to compile in some
# debugging info you can then turn on by setting ldap_debug)
#
ACFLAGS		= -g -DLDAP_DEBUG	# added to every $(CFLAGS)
ALDFLAGS	= -g			# always passed to ld
UDDEFINES	= # -DUOFM		# particular to ud

#
# you probably don't need to edit these things, but if you want to use
# a different make or c compiler, change it here.
#
MAKE	= make
CC	= cc

############################################################################
#                                                                          #
# You should not have to edit anything below this point                    #
#                                                                          #
############################################################################

LDIRS	= libldap liblber		# library directories
SDIRS	= ldapd				# server directories
CDIRS	= finger gopher ud		# client directories
ALLDIRS	= $(CDIRS) $(SDIRS) $(LDIRS)

VERSION	= 2.0	# set this to be the same as what's in ./version

#
# rules to make the software
#

all: lber-library ldap-server ldap-library

lib-only: lber-library ldap-library

others: ldap-finger ldap-gopher ldap-ud

lber-library:
	@echo "cd liblber; $(MAKE) all"
	@(cd liblber; $(MAKE) ACFLAGS="$(ACFLAGS)" ALDFLAGS="$(ALDFLAGS)" \
		LIBDIR=$(LIBDIR) CC=$(CC) all)

ldap-server:
	@echo "cd ldapd; $(MAKE) all"
	@(cd ldapd; $(MAKE) ISODEINCLUDEFLAG="$(ISODEINCLUDEFLAG)" \
		ACFLAGS="$(ACFLAGS)" ALDFLAGS="$(ALDFLAGS)" \
		ISODELIBFLAG=$(ISODELIBFLAG) ISODELIBS="$(ISODELIBS)" \
		KRBINCLUDEFLAG="$(KRBINCLUDEFLAG)" KRBLIBFLAG=$(KRBLIBFLAG) \
		KRBLIBS="$(KRBLIBS)" ETCDIR=$(ETCDIR) CC=$(CC) \
		all)

ldap-library:
	@echo "cd libldap; $(MAKE) all"
	@(cd libldap; $(MAKE) ACFLAGS="$(ACFLAGS)" ALDFLAGS="$(ALDFLAGS)" \
		KRBINCLUDEFLAG="$(KRBINCLUDEFLAG)" KRBLIBFLAG=$(KRBLIBFLAG) \
		KRBLIBS="$(KRBLIBS)" LIBDIR=$(LIBDIR) CC=$(CC) all)

ldap-finger:
	@echo "cd finger; $(MAKE) all"
	@(cd finger; $(MAKE) ACFLAGS="$(ACFLAGS)" ALDFLAGS="$(ALDFLAGS)" \
		KRBLIBFLAG=$(KRBLIBFLAG) KRBLIBS="$(KRBLIBS)" \
		ETCDIR=$(ETCDIR) CC=$(CC) \
		all)

ldap-gopher:
	@echo "cd gopher; $(MAKE) all"
	@(cd gopher; $(MAKE) ACFLAGS="$(ACFLAGS)" ALDFLAGS="$(ALDFLAGS)" \
		KRBLIBFLAG=$(KRBLIBFLAG) KRBLIBS="$(KRBLIBS)" \
		ETCDIR=$(ETCDIR) CC=$(CC) \
		all)

ldap-ud:
	@echo "cd ud; $(MAKE) all"
	@(cd ud; $(MAKE) ACFLAGS="$(ACFLAGS)" ALDFLAGS="$(ALDFLAGS)" \
		KRBLIBFLAG=$(KRBLIBFLAG) KRBLIBS="$(KRBLIBS)" \
		ETCDIR=$(ETCDIR) CC=$(CC) DEFINES="$(UDDEFINES)" \
		all)

#
# rules to install the software
#

install: inst-include inst-server inst-lberlib inst-ldaplib inst-man

inst-others: inst-finger inst-gopher inst-ud

inst-lib: inst-lberlib inst-ldaplib

inst-include:
	@echo "cd h; $(MAKE) install"
	@(cd h; $(MAKE) INCLUDEDIR=$(INCLUDEDIR) install)

inst-server:
	@echo "cd ldapd; $(MAKE) install"
	@(cd ldapd; $(MAKE) ETCDIR=$(ETCDIR) install)

inst-lberlib:
	@echo "cd liblber; $(MAKE) install"
	@(cd liblber; $(MAKE) LIBDIR=$(LIBDIR) install)

inst-ldaplib:
	@echo "cd libldap; $(MAKE) install"
	@(cd libldap; $(MAKE) LIBDIR=$(LIBDIR) install)

inst-man:
	@echo "cd doc; $(MAKE) install"
	@( cd doc; $(MAKE) MANDIR=$(MANDIR) ETCDIR=$(ETCDIR) install )

inst-finger:
	@echo "cd finger; $(MAKE) install"
	@( cd finger; $(MAKE) ETCDIR=$(ETCDIR) install )

inst-gopher:
	@echo "cd gopher; $(MAKE) install"
	@( cd gopher; $(MAKE) ETCDIR=$(ETCDIR) install )

inst-ud:
	@echo "cd ud; $(MAKE) install"
	@( cd ud; $(MAKE) BINDIR=$(BINDIR) install )

#
# rule to make clean
#

clean:
	@for i in $(ALLDIRS); \
		do (echo "cd $$i; $(MAKE) clean"; \
			  cd $$i; $(MAKE) clean); \
		done

#
# rules to make depend
#

depend:
	@for i in $(ALLDIRS); \
		do (echo "cd $$i; $(MAKE) depend"; \
			  cd $$i; $(MAKE) \
				ISODEINCLUDEFLAG="$(ISODEINCLUDEFLAG)" \
				KRBINCLUDEFLAG="$(KRBINCLUDEFLAG)" \
				depend); \
		done

lib-depend:
	@for i in $(LDIRS); \
		do (echo "cd $$i; $(MAKE) depend"; \
			  cd $$i; $(MAKE) \
				KRBINCLUDEFLAG="$(KRBINCLUDEFLAG)" \
				depend); \
		done

#
# rules to cut a new ldap distribution
#

distribution:
	make clean
	@find . ! -name tags -a ! -type l ! -type d -a -perm -0600 \
		-exec touch /tmp/stop \; -exec echo file {} not checked in \;
	@echo "if test -f /tmp/stop; then rm -f /tmp/stop; exit 2; fi" | sh
	find . ! -name tags -a ! -type l -a ! -type d \
		-exec co -l {} \; \
		-exec ci -f$(VERSION) -m"version $(VERSION)" -u {} \;
	@find . -name Makefile -exec co -l {} \;
