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


CFLAGS=${DBG} ${OPTMZ} -I${TOP_OBJDIR}/src/config -I. -I${TOP_INCDIR} \
	-I${TOP_INCDIR}/afs -I${TOP_OBJDIR} -I${TOP_OBJDIR}/fsint\
	 ${XCFLAGS} -DRXDEBUG -DNINTERFACE

LDFLAGS = ${DBUG} ${XLDFLAGS}

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}/libcom_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				\
	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

${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} -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} 

${DEST}/root.server/usr/afs/bin/fileserver: fileserver
	@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} -ns $? $@ ; \
	${INSTALL} -ns $? $@ ;; \
	*_darwin_*) \
	echo "Don't install fileserver for ${SYS_NAME}" ;; \
	*) \
	echo ${INSTALL} -ns $? $@ ; \
	${INSTALL} -ns $? $@ ;; \
	esac

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

install:    ${DESTDIR}${afssrvlibexecdir}/fileserver ${DESTDIR}${includedir}/afs/fs_stats.h

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

include ../config/Makefile.version
${DESTDIR}${afssrvlibexecdir}/fileserver: fileserver
	@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} -ns $? $@ ; \
	${INSTALL} -ns $? $@ ;; \
	*_darwin_*) \
	echo "Don't install fileserver for ${SYS_NAME}" ;; \
	*) \
	echo ${INSTALL} -ns $? $@ ; \
	${INSTALL} -ns $? $@ ;; \
	esac

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

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

dest:    ${DEST}/root.server/usr/afs/bin/fileserver ${DEST}/include/afs/fs_stats.h

check-splint::
	sh $(HELPER_SPLINT) $(CFLAGS) \
	    viced.c		\
	    afsfileprocs.c	\
	    host.c		\
	    physio.c	\
	    callback.c
