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


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

CFLAGS = ${COMMON_CFLAGS} -D${SYS_NAME} ${FSINCLUDES} ${XCFLAGS}

PUBLICHEADERS=nfs.h vnode.h viceinode.h volume.h voldefs.h partition.h\
	fssync.h ihandle.h namei_ops.h

VLIBOBJS=vnode.o volume.o vutil.o partition.o fssync.o purge.o \
	 clone.o nuke.o devname.o listinodes.o common.o ihandle.o \
	 namei_ops.o fstab.o

OBJECTS=${VLIBOBJS} physio.o vol-salvage.o vol-info.o vol-dump.o vol-bless.o

all: gi \
	${TOP_LIBDIR}/vlib.a \
	${TOP_LIBDIR}/libvlib.a \
	salvager \
	volinfo \
	$(FS_CONV_OSF40D) \
	$(XFS_SIZE_CHECK) \
	$(FS_CONV_SOL26) \
	${TOP_INCDIR}/afs/nfs.h \
	${TOP_INCDIR}/afs/vnode.h \
	${TOP_INCDIR}/afs/viceinode.h \
	${TOP_INCDIR}/afs/volume.h \
	${TOP_INCDIR}/afs/voldefs.h \
	${TOP_INCDIR}/afs/partition.h \
	${TOP_INCDIR}/afs/fssync.h \
	${TOP_INCDIR}/afs/ihandle.h \
	${TOP_INCDIR}/afs/namei_ops.h

#
# Installation targets
#
install: \
	${DESTDIR}${libdir}/afs/vlib.a \
	${DESTDIR}${libdir}/afs/libvlib.a \
	${DESTDIR}${afssrvlibexecdir}/salvager \
	${DESTDIR}${afssrvsbindir}/volinfo \
	$(install_FS_CONV_OSF40D) \
	$(install_XFS_SIZE_CHECK) \
	$(install_FS_CONV_SOL26) \
	${DESTDIR}${includedir}/afs/nfs.h \
	${DESTDIR}${includedir}/afs/vnode.h \
	${DESTDIR}${includedir}/afs/viceinode.h \
	${DESTDIR}${includedir}/afs/volume.h \
	${DESTDIR}${includedir}/afs/voldefs.h \
	${DESTDIR}${includedir}/afs/partition.h \
	${DESTDIR}${includedir}/afs/fssync.h \
	${DESTDIR}${includedir}/afs/ihandle.h \
	${DESTDIR}${includedir}/afs/namei_ops.h

${DEST}/root.server/usr/afs/bin/salvager: salvager 
	${INSTALL} -s $? $@

${DEST}/root.server/usr/afs/bin/volinfo: volinfo
	${INSTALL} -s $? $@

${DEST}/lib/afs/vlib.a: vlib.a
	${INSTALL} $? $@

${DEST}/lib/afs/libvlib.a: vlib.a
	${INSTALL} $? $@

${DESTDIR}${afssrvsbindir}/fs_conv_dux40D:  fs_conv_dux40D
	${INSTALL} -s $? $@

${DESTDIR}${afssrvsbindir}/xfs_size_check:  xfs_size_check
	${INSTALL} -s $? $@

${DESTDIR}${afssrvsbindir}/fs_conv_sol26:  fs_conv_sol26
	${INSTALL} -s $? $@

$(DEST)/root.server/usr/afs/bin/fs_conv_dux40D:  fs_conv_dux40D
	${INSTALL} -s $? $@

$(DEST)/root.server/usr/afs/bin/xfs_size_check:  xfs_size_check
	${INSTALL} -s $? $@

$(DEST)/root.server/usr/afs/bin/fs_conv_sol26:  fs_conv_sol26
	${INSTALL} -s $? $@

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

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

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

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

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

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

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

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

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

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

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

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

volinfo: vol-info.o physio.o ihandle.o fstab.o ${LIBS}
	${CC} ${CFLAGS} -o volinfo vol-info.o physio.o \
		ihandle.o fstab.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}

fs_conv_dux40D: fs_conv_411.o
	${CC} ${CFLAGS} ${TOP_LIBDIR}/libcmd.a -o fs_conv_dux40D fs_conv_411.o  ${LIBS} ${XLIBS}

fs_conv_sol26: fs_conv_411.o vlib.a 
	${CC} ${CFLAGS} ${TOP_LIBDIR}/libcmd.a -o fs_conv_sol26 fs_conv_411.o  ${LIBS} ${XLIBS}

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

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 fs_conv_sol26 fs_conv_dux40D

test:
	cd test; $(MAKE)

include ../config/Makefile.version
${DESTDIR}${libdir}/afs/vlib.a: vlib.a
	${INSTALL} $? $@

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

${DESTDIR}${libdir}/afs/libvlib.a: vlib.a
	${INSTALL} $? $@

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

${DESTDIR}${afssrvlibexecdir}/salvager: salvager
	${INSTALL} -s $? $@

${DESTDIR}${afssrvsbindir}/volinfo: volinfo
	${INSTALL} -s $? $@

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

dest: \
	${DEST}/lib/afs/vlib.a \
	${DEST}/lib/afs/libvlib.a \
	${DEST}/root.server/usr/afs/bin/salvager \
	${DEST}/root.server/usr/afs/bin/volinfo \
	$(dest_FS_CONV_OSF40D) \
	$(dest_XFS_SIZE_CHECK) \
	$(dest_FS_CONV_SOL26) \
	${DEST}/include/afs/nfs.h \
	${DEST}/include/afs/vnode.h \
	${DEST}/include/afs/viceinode.h \
	${DEST}/include/afs/volume.h \
	${DEST}/include/afs/voldefs.h \
	${DEST}/include/afs/partition.h \
	${DEST}/include/afs/fssync.h \
	${DEST}/include/afs/ihandle.h \
	${DEST}/include/afs/namei_ops.h

check-splint::
	sh $(HELPER_SPLINT) $(CFLAGS) \
	    vnode.c volume.c vutil.c partition.c fssync.c purge.c \
	    clone.c nuke.c devname.c listinodes.c common.c ihandle.c \
	    namei_ops.c \
	    physio.c vol-salvage.c vol-info.c vol-bless.c
