#-----------------------------------------------------------------------------
# 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.
#
#	ud makefile
#
#	Use -DUOFM for University of Michigan specifics like:
#		if ud should know about noBatchUpdates
#	Use -DDOS if building for a DOS machine
#	Use -DNOTERMCAP if there is no termcap library
#		also need to redefine/undefine the Makefile TERMLIB variable
#-----------------------------------------------------------------------------
LDAPSRC	= ../..
HDIR	= $(LDAPSRC)/include
LDIR	= $(LDAPSRC)/libraries
VERSIONFILE = $(LDAPSRC)/build/version

SRCS=	main.c find.c mod.c print.c auth.c util.c help.c\
	string_to_key.c group.c edit.c globals.c
OBJS=	main.o find.o mod.o print.o auth.o util.o help.o\
	string_to_key.o group.o globals.o edit.o
HDRS=	ud.h

INCLUDES= -I$(HDIR) $(KRBINCLUDEFLAG)
DEFINES= $(DEFS) -DDEBUG
TERMLIB= -ltermcap

CFLAGS= ${INCLUDES} ${DEFINES} ${ACFLAGS}
LIBS= ${TERMLIB} -lldap -llber $(KRBLIBFLAG) $(KRBLIBS) $(ALIBS)

PURIFY=
#PURIFY=purify

all: ud

ud : version.o
	$(PURIFY) ${CC} $(ALDFLAGS) -o $@ version.o ${OBJS} -L${LDIR} ${LIBS}

version.c: ${OBJS} $(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: ud FORCE
	-$(MKDIR) -p $(LDAP_BINDIR)
	-mv -f $(LDAP_BINDIR)/ud $(LDAP_BINDIR)/ud-
	$(INSTALL) $(INSTALLFLAGS) -m 775 ud $(LDAP_BINDIR)

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

clean: FORCE
	$(RM) $(OBJS) core ud tags version.o version.c
	$(RM) *_pure_*.o ud.pure_hardlink ud.pure_linkinfo

tags: FORCE
	$(CTAGS) $(SRCS) ${HDRS}

lint: FORCE
	$(LINT) -Dlint $(INCLUDES) $(DEFINES) $(SRCS) version.c | \
		egrep -v "string_to_key|but not defined"

5lint:	FORCE
	$(5LINT) -Dlint $(INCLUDES) $(DEFINES) $(SRCS) version.c

links:
	@$(LN) .src/README .src/etc.ud.conf .src/*.[ch] .

