# Copyright 2000, International Business Machines Corporation and others.
# All Rights Reserved.
# 
# This software has been released under the terms of the IBM Public
# License.  For details, see the LICENSE file in the top-level source
# directory or online at http://www.openafs.org/dl/license10.html
# */

srcdir=@srcdir@
include @TOP_OBJDIR@/src/config/Makefile.config

INCLS=\
	${TOP_INCDIR}/lock.h \
	${TOP_INCDIR}/ubik.h \
	${TOP_INCDIR}/lwp.h \
	${TOP_INCDIR}/des.h \
	${TOP_INCDIR}/rx/rx.h \
	${TOP_INCDIR}/rx/xdr.h \
	${TOP_INCDIR}/rx/rxkad.h \
	${TOP_INCDIR}/afs/auth.h \
	${TOP_INCDIR}/afs/cellconfig.h \
	${TOP_INCDIR}/afs/com_err.h \
	${TOP_INCDIR}/afs/bubasics.h \
	budb.h budb_client.h database.h

# library ordering defined by top level makefile
LIBS=${TOP_LIBDIR}/libbubasics.a \
	${TOP_LIBDIR}/libaudit.a \
	${TOP_LIBDIR}/libprot.a \
	${TOP_LIBDIR}/libkauth.a \
	${TOP_LIBDIR}/libubik.a \
	${TOP_LIBDIR}/libauth.a \
	${TOP_LIBDIR}/librxkad.a \
	${TOP_LIBDIR}/libsys.a \
	${TOP_LIBDIR}/libdes.a \
	${TOP_LIBDIR}/librx.a \
	${TOP_LIBDIR}/libsys.a \
	${TOP_LIBDIR}/liblwp.a \
	${TOP_LIBDIR}/libcmd.a \
	${TOP_LIBDIR}/libcom_err.a \
	${TOP_LIBDIR}/util.a

COMMON_OBJS = database.o db_alloc.o db_dump.o db_hash.o struct_ops.o ol_verify.o

SERVER_OBJS = ${COMMON_OBJS} budb.ss.o budb.xdr.o dbs_dump.o db_lock.o db_text.o \
	procs.o server.o budb_errs.o

all: ${TOP_LIBDIR}/libbudb.a ${TOP_INCDIR}/afs/budb.h ${TOP_INCDIR}/afs/budb_errs.h ${TOP_INCDIR}/afs/budb_client.h budb_server

#
# budb_errs.o actually depends on neither budb_client.h nor budb_errs.h
# but generating either of them will rebuild budb_errs.c
#
budb_errs.o: budb_errs.c budb_client.h budb_errs.h

budb_errs.c budb_client.h: budb_errs.et budb_client.p.h
	$(RM) -f budb_client.h budb_errs.c; ${COMPILE_ET} -p ${srcdir} budb_errs -h budb_client

budb_errs.h: budb_errs.et
	${COMPILE_ET} -p ${srcdir} budb_errs

database.o: database.c budb_errs.h globals.h ${INCLS}
db_alloc.o: db_alloc.c budb_errs.h ${INCLS}
dbs_dump.o: dbs_dump.c budb_errs.h ${INCLS}
db_lock.o:  db_lock.c budb_errs.h ${INCLS}
db_text.o:  db_text.c budb_errs.h ${INCLS}
db_hash.o: db_hash.c budb_errs.h ${INCLS}
ol_verify.o:	ol_verify.c budb_errs.h ${INCLS}
procs.o: procs.c budb_errs.h globals.h ${INCLS}
struct_ops.o: budb_errs.h
server.o: server.c budb_errs.h ${INCLS} AFS_component_version_number.c

budb_server: $(SERVER_OBJS) ${LIBS}
	${CC} ${LDFLAGS} -o budb_server $(SERVER_OBJS) ${LIBS} ${XLIBS}

budb.cs.c: budb.rg
	${RXGEN} -u -C -o $@ ${srcdir}/budb.rg

budb.ss.c: budb.rg
	${RXGEN} -S -o $@ ${srcdir}/budb.rg

budb.xdr.c: budb.rg
	${RXGEN} -c -o $@ ${srcdir}/budb.rg

budb.h: budb.rg
	${RXGEN} -u -h -o $@ ${srcdir}/budb.rg

budb.cs.c: budb.h
budb.xdr.c: budb.h
budb.ss.c: budb.h

libbudb.a: budb_errs.o budb.cs.o budb.xdr.o struct_ops.o AFS_component_version_number.o
	-$(RM) -f $@
	$(AR) crv $@ budb_errs.o budb.cs.o budb.xdr.o struct_ops.o AFS_component_version_number.o
	$(RANLIB) $@

#
# Install targets
#
install: \
	${DESTDIR}${libdir}/afs/libbudb.a \
	${DESTDIR}${includedir}/afs/budb.h \
	${DESTDIR}${includedir}/afs/budb_errs.h \
	${DESTDIR}${includedir}/afs/budb_client.h \
	${DESTDIR}${afssrvlibexecdir}/buserver

${DEST}/lib/afs/libbudb.a: libbudb.a
	${INSTALL} $? $@

${DEST}/include/afs/budb.h: budb.h
	${INSTALL} $? $@

${DEST}/include/afs/budb_errs.h: budb_errs.h
	${INSTALL} $? $@

${DEST}/include/afs/budb_client.h: budb_client.h
	${INSTALL} $? $@

${DEST}/root.server/usr/afs/bin/buserver: budb_server
	${INSTALL} -f $? $@

#
# Misc targets
#
clean:
	$(RM) -f *.o *~ budb_errs.[ch] budb.h budb_client.h *.a *.xdr.c \
		*.ss.c *.cs.c core budb_server AFS_component_version_number.c

include ../config/Makefile.version
${DESTDIR}${libdir}/afs/libbudb.a: libbudb.a
	${INSTALL} $? $@

${TOP_LIBDIR}/libbudb.a: libbudb.a
	${INSTALL} $? $@

${DESTDIR}${includedir}/afs/budb.h: budb.h
	${INSTALL} $? $@

${TOP_INCDIR}/afs/budb.h: budb.h
	${INSTALL} $? $@

${DESTDIR}${includedir}/afs/budb_errs.h: budb_errs.h
	${INSTALL} $? $@

${TOP_INCDIR}/afs/budb_errs.h: budb_errs.h
	${INSTALL} $? $@

${DESTDIR}${includedir}/afs/budb_client.h: budb_client.h
	${INSTALL} $? $@

${TOP_INCDIR}/afs/budb_client.h: budb_client.h
	${INSTALL} $? $@

${DESTDIR}${afssrvlibexecdir}/buserver: budb_server
	${INSTALL} -f $? $@

dest: \
	${DEST}/lib/afs/libbudb.a \
	${DEST}/include/afs/budb.h \
	${DEST}/include/afs/budb_errs.h \
	${DEST}/include/afs/budb_client.h \
	${DEST}/root.server/usr/afs/bin/buserver

