#-----------------------------------------------------------------------------
# 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: $(ETCDIR) $(ETCDIR)/ldapd

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

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] .
# DO NOT DELETE THIS LINE -- mkdep uses it.
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.

main.o: main.c ../../include/portable.h ../../include/lber.h
main.o: ../../include/ldap.h common.h
detach.o: detach.c ../../include/portable.h
setproctitle.o: setproctitle.c
request.o: request.c ../../include/lber.h ../../include/ldap.h common.h
bind.o: bind.c ../../include/lber.h ../../include/ldap.h common.h
result.o: result.c ../../include/lber.h ../../include/ldap.h common.h
error.o: error.c ../../include/lber.h ../../include/ldap.h
search.o: search.c ../../include/lber.h ../../include/ldap.h common.h
util.o: util.c ../../include/lber.h ../../include/ldap.h common.h
compare.o: compare.c ../../include/lber.h ../../include/ldap.h common.h
message.o: message.c ../../include/lber.h ../../include/ldap.h common.h
add.o: add.c ../../include/lber.h ../../include/ldap.h common.h
delete.o: delete.c ../../include/lber.h ../../include/ldap.h common.h
modrdn.o: modrdn.c ../../include/lber.h ../../include/ldap.h common.h
modify.o: modify.c ../../include/lber.h ../../include/ldap.h common.h
abandon.o: abandon.c ../../include/lber.h ../../include/ldap.h common.h
syntax.o: syntax.c ../../include/lber.h ../../include/ldap.h common.h
association.o: association.c ../../include/lber.h ../../include/ldap.h common.h
kerberos.o: kerberos.c ../../include/lber.h ../../include/ldap.h common.h
certificate.o: certificate.c ../../include/lber.h ../../include/ldap.h common.h

# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
