# 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
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@

LIBS=${TOP_LIBDIR}/libbudb.a ${TOP_LIBDIR}/libbubasics.a \
        ${TOP_LIBDIR}/libbutm.a ${TOP_LIBDIR}/libvolser.a \
        ${TOP_LIBDIR}/libvldb.a  ${TOP_LIBDIR}/vlib.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

all: ${TOP_LIBDIR}/libbxdb.a ${TOP_INCDIR}/afs/bucoord_prototypes.h ${TOP_INCDIR}/afs/bc.h backup

generated: bucoord_errs.c bc.h

${TOP_LIBDIR}/libbxdb.a: libbxdb.a
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/bucoord_prototypes.h: bucoord_prototypes.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/bc.h: bc.h
	${INSTALL_DATA} $? $@

libbxdb.a: dsstub.o ubik_db_if.o status.o dlq.o bucoord_errs.o volstub.o AFS_component_version_number.o
	-$(RM) -f $@
	$(AR) crv $@ dsstub.o ubik_db_if.o status.o dlq.o bucoord_errs.o volstub.o AFS_component_version_number.o
	$(RANLIB) $@

ttest: ttest.o ${TOP_LIBDIR}/librx.a ${TOP_LIBDIR}/liblwp.a libbxdb.a
	${CC} ${CFLAGS} -o ttest ttest.o libbxdb.a \
		${TOP_LIBDIR}/libbubasics.a \
		${TOP_LIBDIR}/librx.a ${TOP_LIBDIR}/liblwp.a

ttest.o: AFS_component_version_number.c

btest: btest.o ${TOP_LIBDIR}/libbubasics.a ${TOP_LIBDIR}/librx.a ${TOP_LIBDIR}/liblwp.a
	${CC} ${CFLAGS} -o btest btest.o ${TOP_LIBDIR}/libbubasics.a \
		${TOP_LIBDIR}/librx.a ${TOP_LIBDIR}/liblwp.a

btest.o: AFS_component_version_number.c

BACKSRCS = main.c config.c dsstub.c volstub.c commands.c server.c \
	dsvs.c dump.c restore.c ubik_db_if.c 				  \
	dump_sched.c vol_sets.c tape_hosts.c				  \
	bc_status.c status.c dlq.c

BACKOBJS = main.o config.o dsstub.o volstub.o commands.o server.o \
	dsvs.o dump.o restore.o ubik_db_if.o dump_sched.o vol_sets.o	\
	tape_hosts.o bucoord_errs.o bc_status.o status.o dlq.o

main.o: AFS_component_version_number.c

$(BACKOBJS): bc.h ${TOP_INCDIR}/afs/butc.h

backup:  $(BACKOBJS) ${LIBS}
	${CC} ${CFLAGS} -o backup $(BACKOBJS) ${LIBS} ${XLIBS}

bucoord_errs.c bc.h:	bucoord_errs.et bc.p.h
	$(RM) -f bc.h bucoord_errs.c
	${COMPILE_ET} -p ${srcdir} bucoord_errs -h bc

#
# Errors
#
ubik_db_if.o: ubik_db_if.c
	$(CC) $(CFLAGS) -c $<

volstub.o: volstub.c
	$(CC) $(CFLAGS) -c $<

commands.o: commands.c
	$(CC) $(CFLAGS) @CFLAGS_NOERROR@ -c $<

regex.o: regex.c
	$(CC) $(CFLAGS) -c $<

#
# Install targets
#

install: libbxdb.a backup
	${INSTALL} -d ${DESTDIR}${libdir}/afs
	${INSTALL} -d ${DESTDIR}${sbindir}
	${INSTALL_DATA} libbxdb.a ${DESTDIR}${libdir}/afs/libbxdb.a
	${INSTALL_PROGRAM} backup ${DESTDIR}${sbindir}/backup

dest: libbxdb.a backup
	${INSTALL} -d ${DEST}/lib/afs
	${INSTALL} -d ${DEST}/etc
	${INSTALL_DATA} libbxdb.a ${DEST}/lib/afs/libbxdb.a
	${INSTALL_PROGRAM} backup ${DEST}/etc/backup

#
# Misc targets
#

clean:
	$(RM) -f *.o backup convert *.ss.c *.cs.c *.xdr.c *.a core btest ttest AFS_component_version_number.c bc.h bucoord_errs.c

include ../config/Makefile.version
