# 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.
# Portions Copyright (c) 2006 Sine Nomine Associates

srcdir=@srcdir@
include @TOP_OBJDIR@/src/config/Makefile.config
include @TOP_OBJDIR@/src/config/Makefile.pthread


MODULE_CFLAGS = -DRXDEBUG -DFSSYNC_BUILD_CLIENT \
		-DSALVSYNC_BUILD_SERVER -DSALVSYNC_BUILD_CLIENT \
		-DAFS_DEMAND_ATTACH_FS

SCFLAGS=$(COMMON_CFLAGS) -I.. -DRXDEBUG -DFSSYNC_BUILD_CLIENT \
	-DAFS_DEMAND_ATTACH_FS $(PTH_CFLAGS)

SCCRULE=$(RUN_CC) $(CC_WRAPPER) ${MT_CC} ${SCFLAGS} -c $? -o $@

DIR=$(srcdir)/../dir
VOL=$(srcdir)/../vol

SALVAGEDOBJS=salvaged.o vol-salvage.o physio.o
SALVAGEROBJS=salvager.o s_vol-salvage.o s_physio.o

DIROBJS=buffer.o dir.o salvage.o
SDIROBJS=s_buffer.o s_dir.o s_salvage.o

VLIBOBJS=volume.o vnode.o vutil.o partition.o fssync-client.o \
	 clone.o nuke.o devname.o listinodes.o ihandle.o \
	 namei_ops.o salvsync-server.o salvsync-client.o daemon_com.o
SVLIBOBJS=s_volume.o s_vnode.o s_vutil.o s_partition.o s_fssync-client.o \
	 s_clone.o s_nuke.o s_devname.o s_listinodes.o s_ihandle.o \
	 s_namei_ops.o s_salvsync-server.o s_salvsync-client.o s_daemon_com.o

OBJECTS= ${SALVAGEDOBJS} ${VLIBOBJS} ${DIROBJS}
SOBJECTS= ${SALVAGEROBJS} ${SVLIBOBJS} ${SDIROBJS}

FSSDEBUG_OBJS = fssync-debug.o physio.o common.o ${VLIBOBJS} ${DIROBJS}

SSSDEBUG_OBJS = salvsync-debug.o physio.o common.o ${VLIBOBJS} ${DIROBJS}

LIBS=   \
	$(top_builddir)/src/sys/liboafs_sys.la \
	$(top_builddir)/src/rx/liboafs_rx.la \
	$(top_builddir)/src/util/liboafs_util.la \
	$(top_builddir)/src/cmd/liboafs_cmd.la \
	$(top_builddir)/src/lwp/liboafs_lwpcompat.la \
	$(top_builddir)/src/opr/liboafs_opr.la

all: salvageserver dafssync-debug salvsync-debug dasalvager

salvager.o: ${VOL}/salvager.c
	${SCCRULE}
s_vol-salvage.o: ${VOL}/vol-salvage.c
	${SCCRULE}
s_physio.o: ${VOL}/physio.c
	${SCCRULE}
s_volume.o: ${VOL}/volume.c
	${SCCRULE}
s_vnode.o: ${VOL}/vnode.c
	${SCCRULE}
s_vutil.o: ${VOL}/vutil.c
	${SCCRULE}
s_partition.o: ${VOL}/partition.c
	${SCCRULE}
s_fssync-client.o: ${VOL}/fssync-client.c
	${SCCRULE}
s_clone.o: ${VOL}/clone.c
	${SCCRULE}
s_nuke.o: ${VOL}/nuke.c
	${SCCRULE}
s_devname.o: ${VOL}/devname.c
	${SCCRULE}
s_listinodes.o: ${VOL}/listinodes.c
	${SCCRULE}
s_ihandle.o: ${VOL}/ihandle.c
	${SCCRULE}
s_namei_ops.o: ${VOL}/namei_ops.c
	${SCCRULE}
s_salvsync-server.o: ${VOL}/salvsync-server.c
	${SCCRULE}
s_salvsync-client.o: ${VOL}/salvsync-client.c
	${SCCRULE}
s_daemon_com.o: ${VOL}/daemon_com.c
	${SCCRULE}
s_buffer.o: ${DIR}/buffer.c
	$(SCCRULE)
s_dir.o: ${DIR}/dir.c
	$(SCCRULE)
s_salvage.o: ${DIR}/salvage.c
	$(SCCRULE)

salvaged.o: ${VOL}/salvaged.c
	$(AFS_CCRULE) $(VOL)/salvaged.c

vol-salvage.o: ${VOL}/vol-salvage.c
	$(AFS_CCRULE) $(VOL)/vol-salvage.c

physio.o: ${VOL}/physio.c
	$(AFS_CCRULE) $(VOL)/physio.c

fssync-debug.o: ${VOL}/fssync-debug.c
	$(AFS_CCRULE) $(VOL)/fssync-debug.c

buffer.o: ${DIR}/buffer.c
	$(AFS_CCRULE) $(DIR)/buffer.c

dir.o: ${DIR}/dir.c
	$(AFS_CCRULE) $(DIR)/dir.c

salvage.o: ${DIR}/salvage.c
	$(AFS_CCRULE) $(DIR)/salvage.c

vnode.o: ${VOL}/vnode.c
	$(AFS_CCRULE) $(VOL)/vnode.c

volume.o: ${VOL}/volume.c
	$(AFS_CCRULE) $(VOL)/volume.c

vutil.o: ${VOL}/vutil.c
	$(AFS_CCRULE) $(VOL)/vutil.c

partition.o: ${VOL}/partition.c
	$(AFS_CCRULE) $(VOL)/partition.c

fssync-client.o: ${VOL}/fssync-client.c
	$(AFS_CCRULE) $(VOL)/fssync-client.c

salvsync-server.o: ${VOL}/salvsync-server.c
	$(AFS_CCRULE) $(VOL)/salvsync-server.c

salvsync-client.o: ${VOL}/salvsync-client.c
	$(AFS_CCRULE) $(VOL)/salvsync-client.c

daemon_com.o: ${VOL}/daemon_com.c
	$(AFS_CCRULE) $(VOL)/daemon_com.c

clone.o: ${VOL}/clone.c
	$(AFS_CCRULE) $(VOL)/clone.c

nuke.o: ${VOL}/nuke.c
	$(AFS_CCRULE) $(VOL)/nuke.c

devname.o: ${VOL}/devname.c
	$(AFS_CCRULE) $(VOL)/devname.c

common.o: ${VOL}/common.c
	$(AFS_CCRULE) $(VOL)/common.c

listinodes.o: ${VOL}/listinodes.c
	$(AFS_CCRULE) $(VOL)/listinodes.c

ihandle.o: ${VOL}/ihandle.c
	$(AFS_CCRULE) $(VOL)/ihandle.c

namei_ops.o: ${VOL}/namei_ops.c
	$(AFS_CCRULE) $(VOL)/namei_ops.c

salvageserver: ${OBJECTS} ${LIBS}
	$(LT_LDRULE_static) ${OBJECTS} ${LIBS} \
		$(LIB_hcrypto) $(LIB_roken) $(LIB_crypt) ${MT_LIBS}

dasalvager: ${SOBJECTS} ${LIBS}
	$(LT_LDRULE_static) ${SOBJECTS} ${LIBS} \
		$(LIB_hcrypto) $(LIB_roken) $(LIB_crypt) ${MT_LIBS} ${XLIBS}

dafssync-debug: ${FSSDEBUG_OBJS} ${LIBS}
	$(LT_LDRULE_static) ${FSSDEBUG_OBJS} ${LIBS} \
		$(LIB_hcrypto) $(LIB_roken) $(LIB_crypt) ${MT_LIBS}

salvsync-debug: ${SSSDEBUG_OBJS} ${LIBS}
	$(LT_LDRULE_static) ${SSSDEBUG_OBJS} ${LIBS} \
		$(LIB_hcrypto) $(LIB_roken) $(LIB_crypt) ${MT_LIBS}

install: salvageserver dafssync-debug salvsync-debug dasalvager
	${INSTALL} -d ${DESTDIR}${afssrvlibexecdir}
	${INSTALL} -d ${DESTDIR}${afssrvsbindir}
	${LT_INSTALL_PROGRAM} dasalvager \
		${DESTDIR}${afssrvlibexecdir}/dasalvager
	${LT_INSTALL_PROGRAM} salvageserver \
		${DESTDIR}${afssrvlibexecdir}/salvageserver
	${LT_INSTALL_PROGRAM} dafssync-debug \
		${DESTDIR}${afssrvsbindir}/dafssync-debug
	${LT_INSTALL_PROGRAM} salvsync-debug \
		${DESTDIR}${afssrvsbindir}/salvsync-debug

dest: salvageserver dafssync-debug salvsync-debug dasalvager
	${INSTALL} -d ${DEST}/root.server/usr/afs/bin
	${INSTALL_PROGRAM} dasalvager \
		${DEST}/root.server/usr/afs/bin/dasalvager
	${INSTALL_PROGRAM} salvageserver \
		${DEST}/root.server/usr/afs/bin/salvageserver
	${INSTALL_PROGRAM} dafssync-debug \
		${DEST}/root.server/usr/afs/bin/dafssync-debug
	${INSTALL_PROGRAM} salvsync-debug \
		${DEST}/root.server/usr/afs/bin/salvsync-debug

clean:
	$(LT_CLEAN)
	$(RM) -f *.o salvageserver core AFS_component_version_number.c dafssync-debug salvsync-debug dasalvager

include ../config/Makefile.version
