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

SRCS	= main.c detach.c setproctitle.c request.c bind.c result.c error.c \
	search.c util.c compare.c message.c add.c delete.c modrdn.c modify.c \
	abandon.c syntax.c association.c kerberos.c certificate.c
OBJS	= main.o detach.o setproctitle.o request.o bind.o result.o error.o \
	search.o util.o compare.o message.o add.o delete.o modrdn.o modify.o \
	abandon.o syntax.o association.o kerberos.o LDAP_tables.o \
	certificate.o

INCLUDES= -I. -I$(HDIR) $(ISODEINCLUDEFLAG) $(KRBINCLUDEFLAG)
DEFINES = $(DEFS) $(SERVERDEFS)
CFLAGS	= $(INCLUDES) $(DEFINES) $(ACFLAGS)
LDFLAGS	= -L$(LDIR) $(ISODELIBFLAG) $(KRBLIBFLAG)
LIBS	= -llber $(ISODELIBS) $(KRBLIBS) $(ALIBS)

all:	FORCE
	@if [ "$(HAVEISODE)" = "yes" ]; then \
            $(MAKE) $(MFLAGS) CC="$(CC)" ldapd; \
	else \
	    echo "uncomment the HAVEISODE=yes line in the Make-common file to build ldapd"; \
        fi


ldapd:	version.o
	$(CC) $(ALDFLAGS) -o $@ $(OBJS) version.o $(LDFLAGS) $(LIBS)

sldapd:	version.o
	$(CC) $(ALDFLAGS) -static -o $@ $(OBJS) version.o $(LDFLAGS) $(LIBS) -lresolv

version.c: $(OBJS) $(LDIR)/liblber/liblber.a
	$(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}|" \
	< Version.c > $@)

request.o:	LDAP-types.h

LDAP_tables.c:	ldap.py
	@if [ ! -z "$(PEPSY)" ]; then \
	    $(PEPSY) -A ldap.py; \
	else \
	    touch LDAP_tables.c LDAP-types.h; \
	fi

LDAP-types.h: LDAP_tables.c

install:	FORCE
	@if [ "$(HAVEISODE)" = "yes" ]; then \
            $(MAKE) $(MFLAGS) CC="$(CC)" install-ldapd; \
	else \
	    echo "uncomment the HAVEISODE=yes line in the Make-common file to build and install ldapd"; \
        fi

install-ldapd: $(LDAP_LIBEXECDIR) $(LDAP_LIBEXECDIR)/ldapd

$(LDAP_LIBEXECDIR)/ldapd:	ldapd
	$(INSTALL) $(INSTALLFLAGS) -m 755 ldapd $(LDAP_LIBEXECDIR)

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

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

clean:	FORCE
	$(RM) ldapd sldapd *.o core a.out version.c LDAP*

depend:	FORCE
	@if [ ! -z "$(HAVEISODE)" ]; then \
	    $(MKDEP) $(INCLUDES) $(DEFINES) $(SRCS); \
	else \
	    echo "uncomment the HAVEISODE=yes line in the Make-common file to build ldapd"; \
	fi

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