# 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
#
# Portions Copyright (c) 2003 Apple Computer, Inc.

srcdir=@srcdir@
include @TOP_OBJDIR@/src/config/Makefile.config
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@

INCLS=${TOP_INCDIR}/afs/partition.h ${TOP_INCDIR}/afs/volume.h \
	${TOP_INCDIR}/afs/vlserver.h ${TOP_INCDIR}/rx/rx.h \
	${TOP_INCDIR}/rx/xdr.h ${TOP_INCDIR}/afs/keys.h \
	${TOP_INCDIR}/afs/cellconfig.h ${TOP_INCDIR}/ubik.h \
	${TOP_INCDIR}/afs/cmd.h ${TOP_INCDIR}/afs/butc.h \
	${TOP_INCDIR}/afs/tcdata.h ${TOP_INCDIR}/afs/bubasics.h \
	${TOP_INCDIR}/afs/butm.h

HACKS=${TOP_LIBDIR}/libdir.a

LIBS=${TOP_LIBDIR}/libbudb.a \
	$(TOP_LIBDIR)/libbxdb.a \
	${TOP_LIBDIR}/libbubasics.a \
        ${TOP_LIBDIR}/libbutm.a \
	${TOP_LIBDIR}/libvolser.a \
	${TOP_LIBDIR}/libvldb.a \
        ${TOP_LIBDIR}/vlib.a \
	${TOP_LIBDIR}/libacl.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}/libafscom_err.a \
	${TOP_LIBDIR}/libusd.a \
	${TOP_LIBDIR}/util.a \
	${TOP_LIBDIR}/libprocmgmt.a

TESTOBJS=test.o

SOBJS=dbentries.o tcprocs.o lwps.o tcmain.o list.o recoverDb.o tcudbprocs.o \
	dump.o tcstatus.o

all: butc read_tape

butc_test: ${TESTOBJS} ${LIBS} ${INCLS} ${HACKS}
	${CC} ${CFLAGS} ${TESTOBJS} ${LIBS} ${XLIBS} ${KRB5_LIBS} -o butc_test

tdump: tdump.c AFS_component_version_number.c
	${CC} ${CFLAGS} ${srcdir}/tdump.c -o tdump

butc: ${SOBJS} ${LIBS} ${INCLS} ${HACKS}
	@case ${SYS_NAME} in \
	  rs_aix*) ${CC} ${CFLAGS} ${SOBJS} ${LIBS} ${XLIBS} ${KRB5_LIBS} /usr/lib/libc_r.a -o butc;; \
	  *)        ${CC} ${CFLAGS} ${SOBJS} ${LIBS} ${XLIBS} ${KRB5_LIBS} -o butc;; \
	esac

tcmain.o: tcmain.c ${INCLS} AFS_component_version_number.c
	$(CC) $(CFLAGS) -c ${srcdir}/tcmain.c

dbentries.o: dbentries.c ${INCLS}
tcprocs.o: tcprocs.c ${INCLS}
test.o: test.c ${INCLS} AFS_component_version_number.c
lwps.o: lwps.c ${INCLS}
	$(CC) $(CFLAGS) -c ${srcdir}/lwps.c
list.o: list.c ${INCLS}
recoverDb.o: recoverDb.c ${INCLS}
tcudbprocs.o: tcudbprocs.c ${INCLS}
	$(CC) $(CFLAGS) @CFLAGS_NOERROR@ -c ${srcdir}/tcudbprocs.c
dump.o: dump.c ${INCLS}
	$(CC) $(CFLAGS) -c ${srcdir}/dump.c
tcstatus.o: tcstatus.c ${INCLS}

read_tape: read_tape.c
	${CC} ${CFLAGS} -o read_tape ${srcdir}/read_tape.c \
		${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/libusd.a \
		${TOP_LIBDIR}/util.a

clean:
	$(RM) -f butc *.o butc_test core tdump read_tape AFS_component_version_number.c

install: butc read_tape
	${INSTALL} -d ${DESTDIR}${sbindir}
	@case ${SYS_NAME} in \
	alpha_dux*|sgi_*|sun4x_*|sunx86_*|rs_aix*|*linux*|hp_ux*) \
		echo "Don't install butc for ${SYS_NAME} (will install from tbutc)" ;; \
	*_darwin_[1-6][0-9]) \
		echo ${INSTALL_PROGRAM} butc ${DESTDIR}${sbindir}/butc ; \
		${INSTALL_PROGRAM} butc ${DESTDIR}${sbindir}/butc ;; \
	*_darwin_*) \
		echo "Don't install butc for ${SYS_NAME} (will install from tbutc)" ;; \
	*) \
		echo ${INSTALL_PROGRAM} butc ${DESTDIR}${sbindir}/butc ; \
		${INSTALL_PROGRAM} butc ${DESTDIR}${sbindir}/butc ;; \
	esac
	${INSTALL_PROGRAM} read_tape ${DESTDIR}${sbindir}/read_tape

dest: butc read_tape
	${INSTALL} -d ${DEST}/etc
	@case ${SYS_NAME} in \
	alpha_dux*|sgi_*|sun4x_*|sunx86_*|rs_aix*|*linux*|hp_ux*) \
		echo "Don't install butc for ${SYS_NAME} (will install from tbutc)" ;; \
	*_darwin_[1-6][0-9]) \
		echo ${INSTALL_PROGRAM} butc ${DEST}/etc/butc ; \
		${INSTALL_PROGRAM} butc ${DEST}/etc/butc ;; \
	*_darwin_*) \
		echo "Don't install butc for ${SYS_NAME} (will install from tbutc)" ;; \
	*) \
		echo ${INSTALL_PROGRAM} butc ${DEST}/etc/butc ; \
		${INSTALL_PROGRAM} butc ${DEST}/etc/butc ;; \
	esac
	${INSTALL_PROGRAM} read_tape ${DEST}/etc/read_tape

include ../config/Makefile.version
