#-----------------------------------------------------------------------------
# Copyright (c) 1995 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.
#
#       Stand-alone LDAP Update RePlication Daemon makefile
#
#-----------------------------------------------------------------------------
LDAPSRC	= ../..
HDIR	= $(LDAPSRC)/include
LDIR	= $(LDAPSRC)/libraries
VERSIONFILE = $(LDAPSRC)/build/version

SRCS	=	admin.c args.c ch_malloc.c config.c detach.c \
		fm.c globals.c ldap_op.c lock.c main.c re.c \
		reject.c replica.c replog.c ri.c rq.c sanity.c st.c \
		tsleep.c

OBJS	=	admin.o args.o ch_malloc.o config.o detach.o \
		fm.o globals.o ldap_op.o lock.o main.o re.o \
		reject.o replica.o replog.o ri.o rq.o sanity.o st.o \
		tsleep.o

INCLUDES= -I. -I$(HDIR) $(KRBINCLUDEFLAG)
DEFINES = $(DEFS) $(SERVERDEFS)
CFLAGS	= $(INCLUDES) $(THREADSINCLUDE) $(DEFINES) $(ACFLAGS) $(THREADS)
LDFLAGS	= -L$(LDIR) $(KRBLIBFLAG)
LIBS	= -lldap -llber -lm -llthread -lldif $(THREADSLIB) $(KRBLIBS) \
	  $(ALIBS)

all: 	FORCE
	@if [ -z "$(MAKESLAPD)" ]; then \
		echo "uncomment the MAKESLAPD line in Make-common to make slurpd"; \
		exit 0; \
	else \
		make slurpd; \
	fi

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

slurpd.pure:	version.o
	purify $(CC) $(ALDFLAGS) -o $@ $(OBJS) version.o $(LDFLAGS) $(LIBS)

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

install: $(LDAP_LIBEXECDIR) $(LDAP_LIBEXECDIR)/slurpd

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

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

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

clean:	FORCE
	@echo "making clean in `$(PWD)`"
	$(RM) slurpd *.o core a.out version.c

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

links:
	@echo "making links in `$(PWD)`"
	@$(LN) .src/*.[ch] .

