# 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
include @TOP_OBJDIR@/src/config/Makefile.lwp

INCLS=${TOP_INCDIR}/afs/afsint.h \
	${TOP_INCDIR}/afs/cmd.h \
	${TOP_INCDIR}/afs/afsutil.h

AFSIO_INCLS=${TOP_INCDIR}/afs/afsint.h \
	${TOP_INCDIR}/afs/cmd.h \
	${TOP_INCDIR}/afs/auth.h \
	${TOP_INCDIR}/afs/vlserver.h \
	${TOP_INCDIR}/afs/ihandle.h \
	${TOP_INCDIR}/afs/com_err.h \
	${TOP_INCDIR}/afs/afscp.h \
	${TOP_INCDIR}/afs/afsutil.h

AFSIO_LIBS=${TOP_LIBDIR}/libafscp.a \
	$(top_builddir)/src/rxkad/liboafs_rxkad.la \
	$(top_builddir)/src/fsint/liboafs_fsint.la \
	$(top_builddir)/src/vlserver/liboafs_vldb.la \
	$(top_builddir)/src/cmd/liboafs_cmd.la \
	$(top_builddir)/src/util/liboafs_util.la \
	$(top_builddir)/src/opr/liboafs_opr.la

FSLIBS=${TOP_LIBDIR}/libsys.a \
	 ${TOP_LIBDIR}/libvldb.a \
	 ${TOP_LIBDIR}/libubik.a \
	 ${TOP_LIBDIR}/vlib.a \
	 ${TOP_LIBDIR}/libauth.a \
	 ${TOP_LIBDIR}/librxkad.a \
	 ${TOP_LIBDIR}/libafscom_err.a \
	 ${TOP_LIBDIR}/libcmd.a \
	 ${TOP_LIBDIR}/libkauth.a \
	 ${TOP_LIBDIR}/librx.a \
	 ${TOP_LIBDIR}/libsys.a \
	 ${TOP_LIBDIR}/liblwp.a \
	 ${TOP_LIBDIR}/libaudit.a \
	 $(TOP_LIBDIR)/libafsutil.a \
	 $(TOP_LIBDIR)/libopr.a \
	 ${TOP_LIBDIR}/libafsrfc3961.a \
	 ${TOP_LIBDIR}/libafshcrypto_lwp.a

CMLIBS=${TOP_LIBDIR}/libsys.a \
	 ${TOP_LIBDIR}/libafsint.a \
	 ${TOP_LIBDIR}/librxkad.a \
	 ${TOP_LIBDIR}/libauth.a \
	 ${TOP_LIBDIR}/libafscom_err.a \
	 ${TOP_LIBDIR}/libcmd.a \
	 ${TOP_LIBDIR}/librx.a \
	 ${TOP_LIBDIR}/libafshcrypto_lwp.a \
	 ${TOP_LIBDIR}/libsys.a \
	 ${TOP_LIBDIR}/liblwp.a \
	 $(TOP_LIBDIR)/libopr.a \
	 $(TOP_LIBDIR)/libafsutil.a

LIBS = ${FSLIBS}

all: fs up fstrace cmdebug livesys cacheout afsio

#
# Build targets
#
cacheout: cacheout.o
	$(AFS_LDRULE) cacheout.o ${LIBS} $(LIB_roken) ${XLIBS} ${CMLIBS}

cacheout.o: cacheout.c


up.o: up.c AFS_component_version_number.c

up: up.o
	$(AFS_LDRULE) up.o ${LIBS} $(LIB_roken) ${XLIBS}

fs.o: fs.c ${INCLS} AFS_component_version_number.c

fs: fs.o $(LIBS)
	$(AFS_LDRULE) fs.o ${TOP_LIBDIR}/libprot.a $(LIBS) \
		$(LIB_roken) ${XLIBS}

afsio.o: afsio.c ${AFSIO_INCLS} AFS_component_version_number.c
	${PTH_CCRULE} ${srcdir}/afsio.c
afscbint.ss.o: ../fsint/afscbint.ss.c
	${PTH_CCRULE} ../fsint/afscbint.ss.c

afsio: afsio.o afscbint.ss.o ${AFSIO_LIBS}
	$(LT_LDRULE_static) afsio.o afscbint.ss.o \
		${AFSIO_LIBS} \
		$(LIB_hcrypto) $(LIB_roken) ${MT_LIBS} \
		$(LDFLAGS_krb5) $(LIB_krb5)

livesys.o: livesys.c ${INCLS} AFS_component_version_number.c

livesys: livesys.o $(LIBS)
	$(AFS_LDRULE) livesys.o $(LIBS) $(LIB_roken) ${XLIBS}

twiddle: twiddle.o $(LIBS)
	$(AFS_LDRULE) twiddle.o $(LIBS) $(LIB_roken) ${XLIBS}

gcpags: gcpags.o $(LIBS)
	$(AFS_LDRULE) gcpags.o $(LIBS) $(LIB_roken) ${XLIBS}

whatfid.o: whatfid.c ${INCLS} AFS_component_version_number.c

whatfid: whatfid.o ${LIBS}
	$(AFS_LDRULE) whatfid.o ${LIBS} $(LIB_roken) ${XLIBS}

fstrace: fstrace.o
	$(AFS_LDRULE) fstrace.o $(LIBS) $(LIB_roken) ${XLIBS}

cmdebug.o: cmdebug.c ${INCLS} AFS_component_version_number.c

cmdebug: cmdebug.o ${CMLIBS}
	$(AFS_LDRULE) cmdebug.o ${CMLIBS} $(LIB_roken) ${XLIBS}

dedebug.o: dedebug.c ${INCLS} AFS_component_version_number.c

dedebug: dedebug.o ${CMLIBS}
	$(AFS_LDRULE) dedebug.o ${CMLIBS} $(LIB_roken) ${XLIBS}

#
# Install targets
#
install: fs livesys up fstrace cmdebug afsio
	${INSTALL} -d ${DESTDIR}${bindir}
	${INSTALL} -d ${DESTDIR}${afssrvbindir}
	${INSTALL} -d ${DESTDIR}${sbindir}
	${INSTALL_PROGRAM} fs ${DESTDIR}${bindir}/fs
	${INSTALL_PROGRAM} livesys ${DESTDIR}${bindir}/livesys
	${INSTALL_PROGRAM} fs ${DESTDIR}${afssrvbindir}/fs
	${INSTALL_PROGRAM} up ${DESTDIR}${bindir}/up
	${INSTALL_PROGRAM} fstrace ${DESTDIR}${sbindir}/fstrace
	${INSTALL_PROGRAM} cmdebug ${DESTDIR}${bindir}/cmdebug
	${INSTALL_PROGRAM} afsio ${DESTDIR}${bindir}/afsio ;

dest: fs livesys up fstrace cmdebug afsio
	${INSTALL} -d ${DEST}/bin
	${INSTALL} -d ${DEST}/etc
	${INSTALL} -d ${DEST}/root.server/usr/afs/bin
	${INSTALL_PROGRAM} fs ${DEST}/bin/fs
	${INSTALL_PROGRAM} livesys ${DEST}/bin/livesys
	${INSTALL_PROGRAM} fs ${DEST}/root.server/usr/afs/bin/fs
	${INSTALL_PROGRAM} up ${DEST}/bin/up
	${INSTALL_PROGRAM} fstrace ${DEST}/etc/fstrace
	${INSTALL_PROGRAM} cmdebug ${DEST}/bin/cmdebug
	${INSTALL_PROGRAM} afsio ${DEST}/bin/afsio

#
# Misc targets
#

clean:
	$(LT_CLEAN)
	$(RM) -f *.o *.a up fs core cmdebug \
		AFS_component_version_number.c fstrace gcpags livesys dedebug \
		cacheout afsio

.PHONY: test
test:
	cd test && $(MAKE)

include ../config/Makefile.version
