# 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

DEST=@DEST@
TOP_INCDIR=@TOP_INCDIR@
TOP_LIBDIR=@TOP_LIBDIR@
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
sbindir=@sbindir@
libexecdir=@libexecdir@
libdir=@libdir@
includedir=@includedir@
mandir=@mandir@
afssrvbindir=@afssrvbindir@
afssrvsbindir=@afssrvsbindir@
afssrvlibexecdir=@afssrvlibexecdir@
TOP_SRCDIR=@TOP_SRCDIR@
SYS_NAME=@AFS_SYSNAME@

SHELL=/bin/sh

include ../config/Makefile.${SYS_NAME}

COMPILE_ET=${TOP_SRCDIR}/comerr/compile_et
RXGEN=${TOP_SRCDIR}/rxgen/rxgen

CFLAGS=${DBG} ${OPTMZ} -I${TOP_SRCDIR}/config -I${TOP_INCDIR} ${XCFLAGS}
LDFLAGS=${DBG} ${OPTMZ} ${XLDFLAGS}

INCDIRS=-I${TOP_SRCDIR}/config -I${TOP_INCDIR}/afs -I${TOP_INCDIR}
INCLIBS=-L${SRCDIR}/lib/afs -L${TOP_LIBDIR}

VINCLS=${TOP_INCDIR}/afs/partition.h ${TOP_INCDIR}/afs/volume.h \
	${TOP_INCDIR}/afs/vlserver.h vol.h dump.h volser.h  lockdata.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 

LIBS=\
	${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}/libdes.a \
	${TOP_LIBDIR}/librxstat.a \
	${TOP_LIBDIR}/librx.a \
	${TOP_LIBDIR}/liblwp.a \
	${TOP_LIBDIR}/libsys.a \
	${TOP_LIBDIR}/libcom_err.a \
	${TOP_LIBDIR}/libkauth.a \
	${TOP_LIBDIR}/libusd.a \
	${TOP_LIBDIR}/util.a

VSOBJS=vsprocs.o vsutils.o lockprocs.o volint.xdr.o volerr.o 
SOBJS=volmain.o volprocs.o physio.o common.o voltrans.o volerr.o \
 volint.cs.o dumpstuff.o  volint.ss.o volint.xdr.o

all: volserver vos restorevol \
	${TOP_INCDIR}/afs/volser.h \
	${TOP_INCDIR}/afs/volint.h \
	${TOP_LIBDIR}/libvolser.a

restorevol: restorevol.c
	${CC} ${CFLAGS} -o restorevol restorevol.c \
		${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a

vos: vos.o ${VSOBJS} libvolser.a ${LIBS}
	${CC} ${LDFLAGS} -o vos vos.o $(VSOBJS) libvolser.a ${LIBS} ${XLIBS}

volserver: $(SOBJS) $(LIBS) ${TOP_LIBDIR}/libdir.a
	${CC} ${DBUG} -o volserver $(SOBJS) ${TOP_LIBDIR}/libdir.a \
		${LDFLAGS} $(LIBS) ${XLIBS}

libvolser.a: volint.cs.o  $(VSOBJS) volint.ss.o AFS_component_version_number.o
	-$(RM) -f $@
	$(AR) crv $@ volint.cs.o $(VSOBJS) volint.ss.o AFS_component_version_number.o 
	$(RANLIB) $@

volser.h volerr.c: volerr.et volser.p.h
	$(RM) -f volser.h volerr.c
	${COMPILE_ET} volerr -h volser

volint.h volint.ss.c volint.cs.c volint.xdr.c: volint.xg
	${RXGEN} -x volint.xg

#
# Dependencies
#
volint.cs.o: volint.cs.c ${INTINCLS}
volint.ss.o: volint.ss.c ${INTINCLS}
volint.xdr.o: volint.xdr.c ${INTINCLS}
vsutils.o: vsutils.c ${VINCLS} ${RINCLS} ${INTINCLS}
volmain.o: volmain.c ${VINCLS} ${RINCLS} 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.o: vsprocs.c ${VINCLS} ${RINCLS} ${INTINCLS}
physio.o: physio.c ${VINCLS}
common.o: common.c ${VINCLS}
lockprocs.o: lockprocs.c ${VINCLS} ${INTINCLS} ${RINCLS}

#
# Installation targets
#
install: \
	${DESTDIR}${sbindir}/restorevol \
	${DESTDIR}${includedir}/afs/volser.h \
	${DESTDIR}${includedir}/afs/volint.h \
	${DESTDIR}${sbindir}/vos \
	${DESTDIR}${afssrvsbindir}/vos \
	${DESTDIR}${afssrvlibexecdir}/volserver \
	${DESTDIR}${libdir}/afs/libvolser.a


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

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

${DEST}/etc/restorevol: restorevol
	${INSTALL} $? $@

${DEST}/etc/vos ${DEST}/root.server/usr/afs/bin/vos: vos
	${INSTALL} $? $@

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

${DEST}/root.server/usr/afs/bin/volserver: volserver
	${INSTALL} $? $@

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

include ../config/Makefile.version

${DESTDIR}${sbindir}/restorevol: restorevol
	${INSTALL} $? $@

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

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

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

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

${DESTDIR}${sbindir}/vos: vos
	${INSTALL} $? $@

${DESTDIR}${afssrvsbindir}/vos: vos
	${INSTALL} $? $@

${DESTDIR}${afssrvlibexecdir}/volserver: volserver
	${INSTALL} $? $@

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

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

dest: \
	${DEST}/etc/restorevol \
	${DEST}/include/afs/volser.h \
	${DEST}/include/afs/volint.h \
	${DEST}/etc/vos \
	${DEST}/root.server/usr/afs/bin/vos \
	${DEST}/root.server/usr/afs/bin/volserver \
	${DEST}/lib/afs/libvolser.a

