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

HELPER_SPLINT=@HELPER_SPLINT@

LIBS=${TOP_LIBDIR}/libcmd.a vlib.a ${TOP_LIBDIR}/util.a \
	${TOP_LIBDIR}/libdir.a ${TOP_LIBDIR}/librx.a \
	${TOP_LIBDIR}/libafshcrypto_lwp.a \
	${TOP_LIBDIR}/liblwp.a ${TOP_LIBDIR}/libsys.a \
	${TOP_LIBDIR}/libacl.a ${TOP_LIBDIR}/libopr.a

MODULE_CFLAGS= -D${SYS_NAME} ${FSINCLUDES} \
	       -DFSSYNC_BUILD_SERVER -DFSSYNC_BUILD_CLIENT

PUBLICHEADERS=nfs.h vnode.h viceinode.h volume.h volume_inline.h voldefs.h partition.h \
	fssync.h ihandle.h namei_ops.h salvsync.h daemon_com.h vnode_inline.h

VLIBOBJS=vnode.o volume.o vutil.o partition.o fssync-server.o fssync-client.o \
	 clone.o nuke.o devname.o listinodes.o common.o ihandle.o purge.o \
	 namei_ops.o salvsync-server.o salvsync-client.o daemon_com.o

OBJECTS=${VLIBOBJS} physio.o vol-salvage.o vol-info.o vol-dump.o vol-bless.o fssync-debug.o \
	volinfo-main.o volscan-main.o

all: gi \
	${TOP_LIBDIR}/vlib.a \
	${TOP_LIBDIR}/libvlib.a \
	salvager \
	volinfo \
	volscan \
	vol-bless \
	fssync-debug \
	$(XFS_SIZE_CHECK) \
	${TOP_INCDIR}/afs/nfs.h \
	${TOP_INCDIR}/afs/vnode.h \
	${TOP_INCDIR}/afs/vnode_inline.h \
	${TOP_INCDIR}/afs/viceinode.h \
	${TOP_INCDIR}/afs/volume.h \
	${TOP_INCDIR}/afs/volume_inline.h \
	${TOP_INCDIR}/afs/voldefs.h \
	${TOP_INCDIR}/afs/partition.h \
	${TOP_INCDIR}/afs/fssync.h \
	${TOP_INCDIR}/afs/salvsync.h \
	${TOP_INCDIR}/afs/daemon_com.h \
	${TOP_INCDIR}/afs/ihandle.h \
	${TOP_INCDIR}/afs/namei_ops.h \
	${TOP_INCDIR}/afs/vol_prototypes.h

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

${TOP_LIBDIR}/libvlib.a: vlib.a
	${INSTALL_DATA} $? $@

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

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

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

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

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

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

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

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

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

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

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

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

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

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

${TOP_INCDIR}/afs/vol-salvage.h: vol-salvage.h
	${INSTALL_DATA} $? $@

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

#
# Installation targets
#
install: vlib.a salvager volinfo volscan fssync-debug
	${INSTALL} -d ${DESTDIR}${libdir}/afs
	${INSTALL} -d ${DESTDIR}${afssrvlibexecdir}
	${INSTALL} -d ${DESTDIR}${afssrvsbindir}
	${INSTALL} -d ${DESTDIR}${includedir}/afs
	${INSTALL_DATA} vlib.a ${DESTDIR}${libdir}/afs/vlib.a
	${INSTALL_DATA} vlib.a ${DESTDIR}${libdir}/afs/libvlib.a
	${INSTALL_PROGRAM} salvager ${DESTDIR}${afssrvlibexecdir}/salvager
	${INSTALL_PROGRAM} volinfo ${DESTDIR}${afssrvsbindir}/volinfo
	${INSTALL_PROGRAM} volscan ${DESTDIR}${afssrvsbindir}/volscan
	${INSTALL_PROGRAM} fssync-debug ${DESTDIR}${afssrvsbindir}/fssync-debug
	${INSTALL_DATA} ${srcdir}/nfs.h ${DESTDIR}${includedir}/afs/nfs.h
	${INSTALL_DATA} ${srcdir}/vnode.h ${DESTDIR}${includedir}/afs/vnode.h
	${INSTALL_DATA} ${srcdir}/vnode_inline.h ${DESTDIR}${includedir}/afs/vnode_inline.h
	${INSTALL_DATA} ${srcdir}/viceinode.h ${DESTDIR}${includedir}/afs/viceinode.h
	${INSTALL_DATA} ${srcdir}/volume.h ${DESTDIR}${includedir}/afs/volume.h
	${INSTALL_DATA} ${srcdir}/volume_inline.h ${DESTDIR}${includedir}/afs/volume_inline.h
	${INSTALL_DATA} ${srcdir}/voldefs.h ${DESTDIR}${includedir}/afs/voldefs.h
	${INSTALL_DATA} ${srcdir}/partition.h ${DESTDIR}${includedir}/afs/partition.h
	${INSTALL_DATA} ${srcdir}/fssync.h ${DESTDIR}${includedir}/afs/fssync.h
	${INSTALL_DATA} ${srcdir}/salvsync.h ${DESTDIR}${includedir}/afs/salvsync.h
	${INSTALL_DATA} ${srcdir}/daemon_com.h ${DESTDIR}${includedir}/afs/daemon_com.h
	${INSTALL_DATA} ${srcdir}/ihandle.h ${DESTDIR}${includedir}/afs/ihandle.h
	${INSTALL_DATA} ${srcdir}/namei_ops.h ${DESTDIR}${includedir}/afs/namei_ops.h
	set -x; if test x"$(install_XFS_SIZE_CHECK)" != x"" ; then \
		${INSTALL_PROGRAM} xfs_size_check \
			${DESTDIR}${afssrvsbindir}/xfs_size_check ; \
	fi

dest: vlib.a salvager volinfo volscan fssync-debug
	${INSTALL} -d ${DEST}/lib/afs
	${INSTALL} -d ${DEST}/root.server/usr/afs/bin
	${INSTALL} -d ${DEST}/include/afs
	${INSTALL_DATA} vlib.a ${DEST}/lib/afs/vlib.a
	${INSTALL_DATA} vlib.a ${DEST}/lib/afs/libvlib.a
	${INSTALL_PROGRAM} salvager ${DEST}/root.server/usr/afs/bin/salvager
	${INSTALL_PROGRAM} volinfo ${DEST}/root.server/usr/afs/bin/volinfo
	${INSTALL_PROGRAM} volscan ${DEST}/root.server/usr/afs/bin/volscan
	${INSTALL_PROGRAM} fssync-debug ${DEST}/root.server/usr/afs/bin/fssync-debug
	${INSTALL_DATA} ${srcdir}/nfs.h ${DEST}/include/afs/nfs.h
	${INSTALL_DATA} ${srcdir}/vnode.h ${DEST}/include/afs/vnode.h
	${INSTALL_DATA} ${srcdir}/vnode_inline.h ${DEST}/include/afs/vnode_inline.h
	${INSTALL_DATA} ${srcdir}/viceinode.h ${DEST}/include/afs/viceinode.h
	${INSTALL_DATA} ${srcdir}/volume.h ${DEST}/include/afs/volume.h
	${INSTALL_DATA} ${srcdir}/volume_inline.h ${DEST}/include/afs/volume_inline.h
	${INSTALL_DATA} ${srcdir}/voldefs.h ${DEST}/include/afs/voldefs.h
	${INSTALL_DATA} ${srcdir}/partition.h ${DEST}/include/afs/partition.h
	${INSTALL_DATA} ${srcdir}/fssync.h ${DEST}/include/afs/fssync.h
	${INSTALL_DATA} ${srcdir}/salvsync.h ${DEST}/include/afs/salvsync.h
	${INSTALL_DATA} ${srcdir}/daemon_com.h ${DEST}/include/afs/daemon_com.h
	${INSTALL_DATA} ${srcdir}/ihandle.h ${DEST}/include/afs/ihandle.h
	${INSTALL_DATA} ${srcdir}/namei_ops.h ${DEST}/include/afs/namei_ops.h
	set -x; if test x"$(install_XFS_SIZE_CHECK)" != x"" ; then \
		${INSTALL_PROGRAM} xfs_size_check \
			$(DEST)/root.server/usr/afs/bin/xfs_size_check ; \
	fi

#
# Build targets
#
${OBJECTS}: ${PUBLICHEADERS} ${TOP_INCDIR}/lwp.h ${TOP_INCDIR}/lock.h ${TOP_INCDIR}/afs/afsint.h vutils.h salvage.h AFS_component_version_number.c

vol-salvage.o vutil.o: volinodes.h
vol-salvage.o salvager.o: vol-salvage.h
vol-salvage.o: salvsync.h daemon_com.h

vlib.a:	${VLIBOBJS} AFS_component_version_number.o
	$(RM) -f $@
	$(AR) crv $@ ${VLIBOBJS} AFS_component_version_number.o
	$(RANLIB) $@

# new salvager:  remove references to /vice by linking with novice.o
salvager: vol-salvage.o physio.o vlib.a salvager.o ${LIBS}
	$(AFS_LDRULE) vol-salvage.o physio.o salvager.o \
		${LIBS} $(LIB_roken) ${XLIBS}

salvager.o: salvager.c AFS_component_version_number.c

vol-salvage: vol-salvage.o
vol-info: vol-info.o physio.o ihandle.o

listinodes.o: listinodes.c AFS_component_version_number.c
	case ${SYS_NAME} in				\
		hp?00_ux101 | hp_ux10? )		\
			${CC} ${AFS_CFLAGS} -D_FILE64 -c ${srcdir}/listinodes.c \
				;;			\
		hp_ux11* )		\
			${CC} ${AFS_CFLAGS} -D_FILE_OFFSET_BITS=64 -c ${srcdir}/listinodes.c \
				;;			\
		* )	${CC} ${AFS_CFLAGS} -c ${srcdir}/listinodes.c \
				;;			\
	esac

gi: ${TOP_LIBDIR}/libsys.a
	$(Q)case ${SYS_NAME} in \
	        *linux* | sgi_* | *fbsd* ) \
			echo "Don't build gi on ${SYS_NAME}";; \
	        *) \
			${CC} $(AFS_CPPFLAGS) $(AFS_CFLAGS) \
				-c ${srcdir}/gi.c ; \
			$(AFS_LDRULE_NOQ) gi.o ${TOP_LIBDIR}/libsys.a;; \
	esac

namei_map: ${TOP_LIBDIR}/libsys.a namei_map.o
	$(AFS_LDRULE) namei_map.o ${TOP_LIBDIR}/libafsutil.a \
		${LIBS} $(LIB_roken) ${XLIBS}

volinfo: volinfo-main.o vol-info.o physio.o ihandle.o ${LIBS}
	$(AFS_LDRULE) volinfo-main.o vol-info.o physio.o ihandle.o \
		${LIBS} $(LIB_roken) ${XLIBS}

volscan: volscan-main.o vol-info.o physio.o ihandle.o ${LIBS}
	$(AFS_LDRULE) volscan-main.o vol-info.o physio.o ihandle.o \
		${LIBS} $(LIB_roken) ${XLIBS}

fssync-debug: fssync-debug.o physio.o AFS_component_version_number.c ${LIBS}
	$(AFS_LDRULE) fssync-debug.o physio.o \
		${LIBS} $(LIB_roken) ${XLIBS}

vol-bless: vol-bless.o physio.o ihandle.o ${LIBS}
	$(AFS_LDRULE) vol-bless.o physio.o \
		${LIBS} $(LIB_roken) ${XLIBS}

xfs_size_check: xfs_size_check.o
	$(AFS_LDRULE) xfs_size_check.o

#
# Misc. targets
#
clean:
	$(RM) -f *.o *.a AFS_component_version_number.c
	$(RM) -f ${SCMPROGS} ${STAGEPROGS} core salvager volinfo volscan vol-bless gi fssync-debug

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

include ../config/Makefile.version

check-splint::
	sh $(HELPER_SPLINT) $(CFLAGS) \
	    vnode.c volume.c vutil.c partition.c fssync-server.c fssync-client.c \
	    clone.c nuke.c devname.c listinodes.c common.c ihandle.c \
	    namei_ops.c salvsync-server.c salvsync-client.c daemon_com.c purge.c \
	    physio.c vol-salvage.c vol-info.c vol-bless.c fssync-debug.c \
	    volinfo-main.c volscan-main.c
