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

SCCRULE=${MT_CC} ${SCFLAGS} -c $? -o $@

LWP=$(srcdir)/../lwp
UTIL=$(srcdir)/../util
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

LWPOBJS=lock.o threadname.o

UTILOBJS=uuid.o serverLog.o fileutil.o netutils.o dirpath.o volparse.o flipbase64.o softsig.o fstab.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} ${UTILOBJS} ${VLIBOBJS} ${DIROBJS} ${LWPOBJS}
SOBJECTS= ${SALVAGEROBJS} ${SVLIBOBJS}

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

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

LIBS=   ${TOP_LIBDIR}/libafsauthent.a \
	${TOP_LIBDIR}/libafsrpc.a \
	${TOP_LIBDIR}/util.a \
	${TOP_LIBDIR}/libcmd.a \
	${TOP_LIBDIR}/libopr.a

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

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}

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

uuid.o: ${UTIL}/uuid.c
	$(AFS_CCRULE) $(UTIL)/uuid.c

serverLog.o: ${UTIL}/serverLog.c
	$(AFS_CCRULE) $(UTIL)/serverLog.c

fileutil.o: ${UTIL}/fileutil.c
	$(AFS_CCRULE) $(UTIL)/fileutil.c

volparse.o: ${UTIL}/volparse.c
	$(AFS_CCRULE) $(UTIL)/volparse.c

flipbase64.o: ${UTIL}/flipbase64.c
	$(AFS_CCRULE) $(UTIL)/flipbase64.c

netutils.o: ${UTIL}/netutils.c
	$(AFS_CCRULE) -I../util $(UTIL)/netutils.c

dirpath.o: ${UTIL}/dirpath.c
	$(AFS_CCRULE) $(UTIL)/dirpath.c

softsig.o: ${UTIL}/softsig.c
	$(AFS_CCRULE) $(UTIL)/softsig.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

lock.o: ${LWP}/lock.c
	$(AFS_CCRULE) $(LWP)/lock.c

threadname.o: ${LWP}/threadname.c
	$(AFS_CCRULE) $(LWP)/threadname.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

# only for darwin?
fstab.o: ${UTIL}/fstab.c
	$(AFS_CCRULE) $(UTIL)/fstab.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}
	$(AFS_LDRULE) ${OBJECTS} ${LIBS} \
		$(LIB_hcrypto) $(LIB_roken) $(LIB_crypt) ${MT_LIBS} ${XLIBS}

dasalvager: ${SOBJECTS} ${SLIBS}
	$(AFS_LDRULE) ${SOBJECTS} ${SLIBS} \
		$(LIB_roken) ${XLIBS}

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

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

install: salvageserver dafssync-debug salvsync-debug dasalvager
	${INSTALL} -d ${DESTDIR}${afssrvlibexecdir}
	${INSTALL} -d ${DESTDIR}${afssrvsbindir}
	${INSTALL_PROGRAM} dasalvager \
		${DESTDIR}${afssrvlibexecdir}/dasalvager
	${INSTALL_PROGRAM} salvageserver \
		${DESTDIR}${afssrvlibexecdir}/salvageserver
	${INSTALL_PROGRAM} dafssync-debug \
		${DESTDIR}${afssrvsbindir}/dafssync-debug
	${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:
	$(RM) -f *.o salvageserver core AFS_component_version_number.c dafssync-debug salvsync-debug dasalvager

include ../config/Makefile.version
