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


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

CFLAGS = ${COMMON_CFLAGS} -D${SYS_NAME} ${FSINCLUDES} ${XCFLAGS} ${ARCHFLAGS} -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

all: gi \
	${TOP_LIBDIR}/vlib.a \
	${TOP_LIBDIR}/libvlib.a \
	salvager \
	volinfo \
	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 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} 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 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} 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

salvager.o: salvager.c
	$(CC) $(CFLAGS) -c ${srcdir}/salvager.c

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}
	${CC} ${LDFLAGS} -o salvager vol-salvage.o physio.o salvager.o ${LIBS} ${XLIBS}

salvager.o: 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} ${CFLAGS} -D_FILE64 -c ${srcdir}/listinodes.c \
				;;			\
		hp_ux11* )		\
			${CC} ${CFLAGS} -D_FILE_OFFSET_BITS=64 -c ${srcdir}/listinodes.c \
				;;			\
		* )	${CC} ${CFLAGS} -c ${srcdir}/listinodes.c \
				;;			\
	esac

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

namei_map: ${TOP_LIBDIR}/libsys.a namei_map.o
	${CC} ${CFLAGS} -o namei_map namei_map.o ${TOP_LIBDIR}/libafsutil.a ${LIBS} ${XLIBS}

volinfo: vol-info.o physio.o ihandle.o ${LIBS}
	${CC} ${CFLAGS} -o volinfo vol-info.o physio.o \
		ihandle.o ${LIBS} ${XLIBS}

fssync-debug: fssync-debug.o physio.o AFS_component_version_number.c ${LIBS}
	${CC} ${LDFLAGS} -o fssync-debug fssync-debug.o physio.o ${LIBS} ${XLIBS}

vol-bless: vol-bless.o physio.o ihandle.o ${LIBS}
	${CC} ${CFLAGS} -o vol-bless vol-bless.o physio.o ${LIBS} ${XLIBS}

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

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

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
