# 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

srcdir=@srcdir@
include @TOP_OBJDIR@/src/config/Makefile.config
include @TOP_OBJDIR@/src/config/Makefile.lwp
include @TOP_OBJDIR@/src/config/Makefile.lwptool

HELPER_SPLINT=@HELPER_SPLINT@

VINCLS=${TOP_INCDIR}/afs/partition.h ${TOP_INCDIR}/afs/volume.h \
	${TOP_INCDIR}/afs/vlserver.h vol.h dump.h volser.h  lockdata.h \
	voltrans_inline.h

RINCLS=${TOP_INCDIR}/rx/rx.h ${TOP_INCDIR}/rx/xdr.h \
       ${TOP_INCDIR}/afs/keys.h ${TOP_INCDIR}/afs/cellconfig.h \
	${TOP_INCDIR}/ubik.h ${TOP_INCDIR}/afs/cmd.h

INTINCLS=volint.h volser.h volser_prototypes.h volser_internal.h

LIBS=\
        $(TOP_LIBDIR)/libopr.a \
	${TOP_LIBDIR}/libaudit.a \
	${TOP_LIBDIR}/vlib.a \
	${TOP_LIBDIR}/libacl.a \
	${TOP_LIBDIR}/libsys.a \
	${TOP_LIBDIR}/libvldb.a \
	${TOP_LIBDIR}/libubik.a \
	${TOP_LIBDIR}/libauth.a \
	${TOP_LIBDIR}/libcmd.a \
	${TOP_LIBDIR}/librxkad.a \
	${TOP_LIBDIR}/librxstat.a \
	${TOP_LIBDIR}/librx.a \
	${TOP_LIBDIR}/liblwp.a \
	${TOP_LIBDIR}/libsys.a \
	${TOP_LIBDIR}/libafscom_err.a \
	${TOP_LIBDIR}/libkauth.a \
	${TOP_LIBDIR}/libusd.a \
	${TOP_LIBDIR}/util.a \
	${TOP_LIBDIR}/libopr.a \
	${TOP_LIBDIR}/libafsrfc3961.a \
	${TOP_LIBDIR}/libafshcrypto_lwp.a

VOLDUMP_LIBS = \
	../vol/ihandle.o \
	../vol/physio.o \
	../vol/vlib.a \
	${TOP_LIBDIR}/libopr.a \
	${TOP_LIBDIR}/libcmd.a \
	${TOP_LIBDIR}/libafscom_err.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}/util.a \
	$(TOP_LIBDIR)/libopr.a

SOBJS=volmain.o volprocs.o physio.o common.o voltrans.o \
      dumpstuff.o volint.ss.o vol_split.o

LT_objs = vsprocs.lo vsutils.lo lockprocs.lo volint.xdr.lo volerr.lo \
	  volint.cs.lo
LT_deps = $(top_builddir)/src/opr/liboafs_opr.la \
	  $(top_builddir)/src/comerr/liboafs_comerr.la \
	  $(top_builddir)/src/rx/liboafs_rx.la \
	  $(top_builddir)/src/ubik/liboafs_ubik.la \
	  $(top_builddir)/src/vlserver/liboafs_vldb.la

all: volserver vos restorevol voldump \
	liboafs_volser.la \
	libvolser_pic.la \
	${TOP_INCDIR}/afs/volser.h \
	${TOP_INCDIR}/afs/vsutils_prototypes.h \
	${TOP_INCDIR}/afs/volser_prototypes.h \
	${TOP_INCDIR}/afs/volint.h \
	${TOP_LIBDIR}/libvolser.a

generated: volser.h volerr.c volint.cs.c volint.ss.c volint.xdr.c volint.h

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

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

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

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

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

restorevol: restorevol.o
	$(AFS_LDRULE) restorevol.o ${TOP_LIBDIR}/libcmd.a \
		${TOP_LIBDIR}/util.a $(LIB_roken) ${XLIBS}

vos: vos.o libvolser.a ${LIBS}
	$(AFS_LDRULE) vos.o libvolser.a \
		${LIBS} $(LIB_roken) ${XLIBS}

volserver: $(SOBJS) volerr.lo volint.xdr.lo volint.cs.lo \
	   $(LIBS) ${TOP_LIBDIR}/libdir.a
	$(AFS_LDRULE) $(SOBJS) .lwp/volerr.o .lwp/volint.xdr.o .lwp/volint.cs.o \
		${TOP_LIBDIR}/libdir.a \
		$(LIBS) $(LIB_roken) ${XLIBS}

voldump: vol-dump.o ${VOLDUMP_LIBS}
	$(AFS_LDRULE) vol-dump.o ${VOLDUMP_LIBS} \
		$(LIB_roken) ${XLIBS}

libvolser.a: $(LT_objs)
	$(LT_LDLIB_lwp) $(LT_objs)

liboafs_volser.la: liboafs_volser.la.sym $(LT_objs) $(LT_deps)
	$(LT_LDLIB_shlib) $(LT_objs) $(LT_deps) $(LT_libs)

libvolser_pic.la: $(LT_objs)
	$(LT_LDLIB_pic) $(LT_objs)

volerr.c: volerr.et
	${COMPILE_ET_C} -p ${srcdir} volerr

volser.h: volerr.et volser.p.h
	${COMPILE_ET_H} -p ${srcdir} volerr -h volser

common.o common.lo: volser.h
dumpstuff.o dumpstuff.lo: volser.h
lockprocs.o lockprocs.lo: volser.h
vol-dump.o vol-dump.lo: volser.h
volmain.o volmain.lo: volser.h
volprocs.o volprocs.lo: volser.h
vol_split.o vol_split.lo: volser.h
voltrans.o voltrans.lo: volser.h
vos.o vos.lo: volser.h
vsprocs.o vsprocs.lo: volser.h
vsutils.o vsutils.lo: volser.h

volint.cs.c: volint.xg
	${RXGEN} -A -x -C -o $@ ${srcdir}/volint.xg

volint.ss.c: volint.xg
	${RXGEN} -A -x -S -o $@ ${srcdir}/volint.xg

volint.xdr.c: volint.xg
	${RXGEN} -A -x -c -o $@ ${srcdir}/volint.xg

volint.h: volint.xg
	${RXGEN} -A -x -h -o $@ ${srcdir}/volint.xg

volint.cs.c: volint.h
volint.ss.c: volint.h
volint.xdr.c: volint.h

#
# Dependencies
#
volint.cs.lo: volint.cs.c ${INTINCLS}
volint.ss.o: volint.ss.c ${INTINCLS}
volint.xdr.lo: volint.xdr.c ${INTINCLS}
vsutils.lo: vsutils.c ${VINCLS} ${RINCLS} ${INTINCLS}
volmain.o: volmain.c ${VINCLS} ${RINCLS} ${INTINCLS} AFS_component_version_number.c
volprocs.o: volprocs.c ${VINCLS} ${RINCLS} ${INTINCLS}
dumpstuff.o: dumpstuff.c ${VINCLS} ${RINCLS} ${INTINCLS}
voldump.o: voldump.c ${VINCLS} ${RINCLS}
vos.o: vos.c ${VINCLS} ${RINCLS} ${INTINCLS} AFS_component_version_number.c
vsprocs.lo: vsprocs.c ${VINCLS} ${RINCLS} ${INTINCLS}
physio.o: physio.c ${VINCLS}
common.o: common.c ${VINCLS}
lockprocs.o: lockprocs.c ${VINCLS} ${INTINCLS} ${RINCLS}
vol_split.o: vol_split.c ${VINCLS} ${INTINCLS} ${RINCLS}
restorevol.o: restorevol.c ${VINCLS} ${INTINCLS}
voltrans.o: voltrans.c ${VINCLS} ${INTINCLS} ${RINCLS}
vol-dump.o: vol-dump.c ${VINCLS} ${INTINCLS} ${RINCLS}

#
# Installation targets
#
install: restorevol voldump volser.h volint.h vos volserver libvolser.a
	${INSTALL} -d ${DESTDIR}${sbindir}
	${INSTALL} -d ${DESTDIR}${afssrvsbindir}
	${INSTALL} -d ${DESTDIR}${includedir}/afs
	${INSTALL} -d ${DESTDIR}${libdir}/afs
	${INSTALL} -d ${DESTDIR}${afssrvlibexecdir}
	${INSTALL_PROGRAM} restorevol ${DESTDIR}${bindir}/restorevol
	${INSTALL_PROGRAM} voldump ${DESTDIR}${sbindir}/voldump
	${INSTALL_DATA} volser.h ${DESTDIR}${includedir}/afs/volser.h
	${INSTALL_DATA} volint.h ${DESTDIR}${includedir}/afs/volint.h
	${INSTALL_DATA} ${srcdir}/vsutils_prototypes.h ${DESTDIR}${includedir}/afs/vsutils_prototypes.h
	${INSTALL_PROGRAM} vos ${DESTDIR}${sbindir}/vos
	${INSTALL_PROGRAM} vos ${DESTDIR}${afssrvsbindir}/vos
	${INSTALL_DATA} libvolser.a ${DESTDIR}${libdir}/afs/libvolser.a
	@case ${SYS_NAME} in \
	alpha_dux4*|*linux*|rs_aix*|sgi_6*|sun4x*|sunx86*) \
		echo "Don't install volserver for ${SYS_NAME}" ;; \
	*_darwin_[1-6][0-9]) \
		echo ${INSTALL} volserver \
			${DESTDIR}${afssrvlibexecdir}/volserver ; \
		${INSTALL} volserver \
			${DESTDIR}${afssrvlibexecdir}/volserver ;; \
	*_darwin_*) \
		echo "Don't install volserver for ${SYS_NAME}" ;; \
	*) \
		echo ${INSTALL_PRORAM} volserver \
			${DESTDIR}${afssrvlibexecdir}/volserver ; \
		${INSTALL} volserver \
			${DESTDIR}${afssrvlibexecdir}/volserver ;; \
	esac

dest: restorevol voldump volser.h volint.h vos volserver libvolser.a
	${INSTALL} -d ${DEST}/etc
	${INSTALL} -d ${DEST}/include/afs
	${INSTALL} -d ${DEST}/lib/afs
	${INSTALL} -d ${DEST}/root.server/usr/afs/bin
	${INSTALL_PROGRAM} restorevol ${DEST}/root.server/usr/afs/bin/restorevol
	${INSTALL_PROGRAM} voldump ${DEST}/etc/voldump
	${INSTALL_DATA} volser.h ${DEST}/include/afs/volser.h
	${INSTALL_DATA} volint.h ${DEST}/include/afs/volint.h
	${INSTALL_DATA} ${srcdir}/vsutils_prototypes.h ${DEST}/include/afs/vsutils_prototypes.h
	${INSTALL_PROGRAM} vos ${DEST}/etc/vos
	${INSTALL_PROGRAM} vos ${DEST}/root.server/usr/afs/bin/vos
	${INSTALL_DATA} libvolser.a ${DEST}/lib/afs/libvolser.a
	@case ${SYS_NAME} in \
	alpha_dux4*|*linux*|rs_aix*|sgi_6*|sun4x*|sunx86*) \
		echo "Don't install volserver for ${SYS_NAME}" ;; \
	*_darwin_[1-6][0-9]) \
		echo ${INSTALL} volserver \
			${DEST}/root.server/usr/afs/bin/volserver ; \
		${INSTALL} -ns volserver \
			${DEST}/root.server/usr/afs/bin/volserver ;; \
	*_darwin_*) \
		echo "Don't install volserver for ${SYS_NAME}" ;; \
	*) \
		echo ${INSTALL} volserver \
			${DEST}/root.server/usr/afs/bin/volserver ; \
		${INSTALL} volserver \
			${DEST}/root.server/usr/afs/bin/volserver ;; \
	esac

#
# Misc targets
#
clean:
	$(LT_CLEAN)
	$(RM) -f *.o *.a core volserver volint.ss.c volint.cs.c volint.h \
	volint.xdr.c vos volser.h volerr.c AFS_component_version_number.c restorevol voldump

check-splint::
	sh $(HELPER_SPLINT) $(CFLAGS) \
	    vos.c restorevol.c \
	    vsprocs.c vsutils.c lockprocs.c volerr.c \
	    volmain.c volprocs.c physio.c common.c voltrans.c \
	    dumpstuff.c vol_split.c

include ../config/Makefile.version
