# 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@
HELPER_SPLINT=@HELPER_SPLINT@


CFLAGS=${DBG} ${OPTMZ} -I${TOP_OBJDIR}/src/config -I${TOP_INCDIR} \
       ${XCFLAGS} ${ARCHFLAGS} -DNINTERFACE

LDFLAGS = ${DBUG} ${XLDFLAGS} ${ARCHFLAGS}

LIBS=${TOP_LIBDIR}/libacl.a	\
	${TOP_LIBDIR}/libvldb.a	\
	${TOP_LIBDIR}/libprot.a	\
	${TOP_LIBDIR}/libauth.a	\
	${TOP_LIBDIR}/librxkad.a		\
	${TOP_LIBDIR}/libubik.a 		\
	${TOP_LIBDIR}/vlib.a		\
	${TOP_LIBDIR}/libdir.a	\
	${TOP_LIBDIR}/util.a		\
	${TOP_LIBDIR}/libsys.a	\
	${TOP_LIBDIR}/libafsint.a	\
	${TOP_LIBDIR}/librxstat.a	\
	${TOP_LIBDIR}/librx.a		\
	${TOP_LIBDIR}/libsys.a	\
	${TOP_LIBDIR}/libdes.a		\
	${TOP_LIBDIR}/libafscom_err.a	\
	${TOP_LIBDIR}/liblwp.a \
	${TOP_LIBDIR}/libafsutil.a

headers=${TOP_INCDIR}/lwp.h		\
	${TOP_INCDIR}/afs/acl.h	\
	${TOP_INCDIR}/afs/errors.h	\
	${TOP_INCDIR}/afs/ptclient.h \
	${TOP_INCDIR}/lock.h		\
	${TOP_INCDIR}/afs/volume.h	\
	${TOP_INCDIR}/afs/vnode.h	\
	${TOP_INCDIR}/rx/rx.h	\
	${TOP_INCDIR}/rx/xdr.h	\
	${TOP_INCDIR}/afs/auth.h	\
	${TOP_INCDIR}/afs/afsint.h	\
	viced.h				\
	host.h				\
	callback.h			\
	fs_stats.h

objects=viced.o		\
	afsfileprocs.o	\
	host.o		\
	physio.o	\
	callback.o	

all: cbd fsprobe check_sysid fileserver ${TOP_INCDIR}/afs/fs_stats.h

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

${objects}: ${headers}

viced.o: AFS_component_version_number.o

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

fileserver: ${objects} ${headers} ${LIBS}
	set -x; \
	case ${SYS_NAME} in \
	rs_aix*) \
	    ${CC} -K ${LDFLAGS} -o fileserver ${objects} \
	    ${TOP_LIBDIR}/libaudit.a ${LIBS} ${XLIBS} ;; \
	*) \
	    ${CC} ${LDFLAGS} -o fileserver ${objects} \
	    ${TOP_LIBDIR}/libaudit.a ${LIBS} ${XLIBS} ;; \
	esac

fsprobe.o: fsprobe.c AFS_component_version_number.c
	${CC} ${CFLAGS} @CFLAGS_NOERROR@ -DINTERPRET_DUMP -c ${srcdir}/fsprobe.c

fsprobe: fsprobe.o
	${CC} ${CFLAGS} -o fsprobe fsprobe.o ${LIBS} ${XLIBS} 

cbd.o: callback.c AFS_component_version_number.c
	${CC} ${CFLAGS} -DINTERPRET_DUMP -c -o cbd.o ${srcdir}/callback.c

cbd: cbd.o
	${CC} ${CFLAGS} -DINTERPRET_DUMP -o cbd cbd.o ${LIBS} ${XLIBS} 

install: fileserver fs_stats.h
	${INSTALL} -d ${DESTDIR}${afssrvlibexecdir}
	${INSTALL} -d ${DESTDIR}${includedir}/afs
	${INSTALL_DATA} ${srcdir}/fs_stats.h ${DESTDIR}${includedir}/afs/fs_stats.h
	@case ${SYS_NAME} in \
	alpha_dux4*|*linux*|rs_aix*|sgi_6*|sun4x*|sunx86*) \
		echo "Don't install fileserver for ${SYS_NAME}" ;; \
	*_darwin_[1-6][0-9]) \
		echo ${INSTALL} fileserver ${DESTDIR}${afssrvlibexecdir}/fileserver ; \
		${INSTALL} fileserver ${DESTDIR}${afssrvlibexecdir}/fileserver ;; \
	*_darwin_*) \
		echo "Don't install fileserver for ${SYS_NAME}" ;; \
	*) \
		echo ${INSTALL} fileserver ${DESTDIR}${afssrvlibexecdir}/fileserver ; \
		${INSTALL} fileserver ${DESTDIR}${afssrvlibexecdir}/fileserver ;; \
	esac

dest: fileserver fs_stats.h
	${INSTALL} -d ${DEST}/root.server/usr/afs/bin
	${INSTALL} -d ${DEST}/include/afs
	${INSTALL_DATA} ${srcdir}/fs_stats.h ${DEST}/include/afs/fs_stats.h
	@case ${SYS_NAME} in \
	alpha_dux4*|*linux*|rs_aix*|sgi_6*|sun4x*|sunx86*) \
		echo "Don't install fileserver for ${SYS_NAME}" ;; \
	*_darwin_[1-6][0-9]) \
		echo ${INSTALL} fileserver ${DEST}/root.server/usr/afs/bin/fileserver ; \
		${INSTALL} fileserver ${DEST}/root.server/usr/afs/bin/fileserver ;; \
	*_darwin_*) \
		echo "Don't install fileserver for ${SYS_NAME}" ;; \
	*) \
		echo ${INSTALL} fileserver ${DEST}/root.server/usr/afs/bin/fileserver ; \
		${INSTALL} fileserver ${DEST}/root.server/usr/afs/bin/fileserver ;; \
	esac

clean:
	$(RM) -f *.o fileserver core AFS_component_version_number.c cbd check_sysid fsprobe

include ../config/Makefile.version
check-splint::
	sh $(HELPER_SPLINT) $(CFLAGS) \
	    viced.c		\
	    afsfileprocs.c	\
	    host.c		\
	    physio.c	\
	    callback.c
