# 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
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@

CFLAGS=${DBUG} ${COMMON_INCL} ${XCFLAGS} ${ARCHFLAGS}
SFLAGS=-I${TOP_INCDIR}
LIBS=libsys.a ${TOP_LIBDIR}/librx.a libsys.a ${TOP_LIBDIR}/liblwp.a ${TOP_LIBDIR}/util.a ${XLIBS}

OBJECTS= afssyscalls.o setpag.o pioctl.o glue.o \
	AFS_component_version_number.o
SHLIBOBJS = picobj/setpag.o picobj/glue.o syscall.o
RMTOBJS=rmtsysnet.o rmtsysc.o rmtsys.cs.o rmtsys.xdr.o rmtsys.ss.o rmtsyss.o 

all: \
    rmtsysd \
    pagsh \
    pagsh.krb \
    ${TOP_INCDIR}/afs/afssyscalls.h \
    ${TOP_INCDIR}/afs/afs.exp \
    ${TOP_INCDIR}/afs/xfsattrs.h \
    ${TOP_INCDIR}/afs/sys_prototypes.h \
    ${TOP_LIBDIR}/afs.exp \
    ${TOP_LIBDIR}/libsys.a \
    ${KERNELDIR}/afs/xfsattrs.h \
    ${UKERNELDIR}/afs/afsl.exp

generated: \
	rmtsys.cs.c rmtsys.ss.c rmtsys.xdr.c rmtsys.h \
	Krmtsys.cs.c Krmtsys.xdr.c Krmtsys.h

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

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

${TOP_INCDIR}/afs/afs.exp: afs.exp
	@set -x; case ${SYS_NAME} in \
		rs_aix* ) \
			${INSTALL_DATA} $? $@ ;; \
	esac

${TOP_LIBDIR}/afs.exp: afs.exp
	@set -x; case ${SYS_NAME} in \
		rs_aix* ) \
			${INSTALL_DATA} $? $@ ;; \
	esac

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

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

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

${UKERNELDIR}/afs/afsl.exp: afsl.exp
	${INSTALL} -d ${UKERNELDIR}/afs
	@set -x; case ${SYS_NAME} in \
		rs_aix* ) \
			${INSTALL_DATA} $? $@ ;; \
	esac

${KERNELDIR}/afs/xfsattrs.h: xfsattrs.h
	${INSTALL} -d ${KERNELDIR}/afs
	${INSTALL_DATA} $? $@

depinstall: \
	${TOP_INCDIR}/afs/afssyscalls.h \
	${TOP_INCDIR}/afs/rmtsys.h \
	${TOP_INCDIR}/afs/afs.exp \
	${TOP_INCDIR}/afs/xfsattrs.h \
	${TOP_INCDIR}/afs/sys_prototypes.h \
	${TOP_LIBDIR}/afs.exp \
	${KERNELDIR}/afs/xfsattrs.h \
	${UKERNELDIR}/afs/afsl.exp \
	Krmtsys.cs.c Krmtsys.h Krmtsys.xdr.c rmtsys.h 

libsys.a: ${OBJECTS} ${RMTOBJS} syscall.o afsl.exp AFS_component_version_number.o
	$(RM) -f $@
	@set -e; set -x; case "$(SYS_NAME)" in \
	sgi_* | hp_ux10*) \
		${AR} crv $@ ${OBJECTS} ${RMTOBJS} syscall.o ;; \
	rs_aix*) \
		${AR} crv $@ ${OBJECTS} ${RMTOBJS} syscall.o afsl.exp ;; \
	*) \
		${AR} crv $@ ${OBJECTS} ${RMTOBJS} ;; \
	esac
	$(RANLIB) $@

tests:	pagsh pagsh.krb fixit iinc idec icreate iopen istat rmtsysd

syscall.o: syscall.s
	@set -e; set -x; case "$(SYS_NAME)" in \
	sgi_*) \
                ${CC} ${CFLAGS} -c ${srcdir}/syscall.s; \
		;; \
	rs_aix* | hp_ux10*) \
		$(PATH_CPP) -P ${SFLAGS} ${srcdir}/syscall.s > syscall.ss; \
		as -o syscall.o syscall.ss; \
		$(RM) syscall.ss; \
		;; \
	*) \
		touch syscall.o ; \
		;; \
	esac

afssyscalls.o: afssyscalls.c afssyscalls.h
	${CCOBJ} ${CFLAGS} -c ${srcdir}/afssyscalls.c

glue.o: glue.c afssyscalls.h
	${CCOBJ} ${CFLAGS} -c ${srcdir}/glue.c

setpag.o: setpag.c afssyscalls.h
	${CCOBJ} ${CFLAGS} -c ${srcdir}/setpag.c

pioctl.o: pioctl.c afssyscalls.h
	${CCOBJ} ${CFLAGS} -c ${srcdir}/pioctl.c

rmtsysnet.o rmtsysc.o rmtsyss.o rmtsysd.o: rmtsys.h
rmtsysd: AFS_component_version_number.o afs.exp afsl.exp

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

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

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

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

Krmtsys.cs.c: rmtsys.xg Krmtsys.h
	${RXGEN} -A -k -C -o Krmtsys.cs.c ${srcdir}/rmtsys.xg

Krmtsys.xdr.c: rmtsys.xg
	${RXGEN} -A -k -c -o Krmtsys.xdr.c ${srcdir}/rmtsys.xg

Krmtsys.h: rmtsys.xg
	${RXGEN} -A -k -h -o Krmtsys.h ${srcdir}/rmtsys.xg

rmtsysd: rmtsysd.o libsys.a
	${CC} ${CFLAGS} -o rmtsysd rmtsysd.o ${LIBS}

pagsh:	libsys.a AFS_component_version_number.o pagsh.c
	${CC} ${CFLAGS} -c ${srcdir}/pagsh.c
	${CC} ${CFLAGS} -o pagsh pagsh.o ${LIBS}

pagsh.krb: libsys.a pagsh.c ${TOP_LIBDIR}/libauth.krb.a ${TOP_LIBDIR}/librxkad.a ${TOP_LIBDIR}/libdes.a
	${CC} ${CFLAGS} -o pagsh.krb.o -c ${srcdir}/pagsh.c -DAFS_KERBEROS_ENV
	${CC} ${CFLAGS} -o pagsh.krb pagsh.krb.o ${TOP_LIBDIR}/libauth.krb.a ${TOP_LIBDIR}/librxkad.a ${TOP_LIBDIR}/libdes.a ${LIBS}

#
# Test programs.
#

iinc:	iinc.c 
	$(CC) -o iinc ${CFLAGS} ${srcdir}/iinc.c ${LIBS}

idec:	idec.c  AFS_component_version_number.c
	$(CC) -o idec ${CFLAGS} ${srcdir}/idec.c ${LIBS}

icreate:icreate.c  AFS_component_version_number.c
	$(CC) -o icreate ${CFLAGS} ${srcdir}/icreate.c ${LIBS}

iopen:	iopen.c  AFS_component_version_number.c
	$(CC) -o iopen ${CFLAGS} ${srcdir}/iopen.c ${LIBS}

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

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

istat:	istat.c  AFS_component_version_number.c
	$(CC) -o istat ${CFLAGS} ${srcdir}/istat.c ${LIBS}

fixit:	fixit.c AFS_component_version_number.c
	$(CC) -o fixit ${CFLAGS} ${srcdir}/fixit.c ${LIBS}


xfsinode: xfsinode.c  AFS_component_version_number.c
	@set -x; case "${SYS_NAME}" in \
		sgi_62 | sgi_64 ) \
		$(CC) -o xfsinode ${CFLAGS} ${srcdir}/xfsinode.c ${LIBS}
	esac

afs.exp: ${srcdir}/afs4.exp ${srcdir}/afs5.exp
	@set -x; case ${SYS_NAME} in \
		rs_aix[56]* ) \
			cp -p ${srcdir}/afs5.exp afs.exp ;; \
		rs_aix* ) \
			cp -p ${srcdir}/afs4.exp afs.exp ;; \
		* ) \
			touch afs.exp ;; \
	esac

afsl.exp: ${srcdir}/afsl4.exp ${srcdir}/afsl5.exp
	@set -x; case ${SYS_NAME} in \
		rs_aix[56]* ) \
			cp -p ${srcdir}/afsl5.exp afsl.exp ;; \
		rs_aix* ) \
			cp -p ${srcdir}/afsl4.exp afsl.exp ;; \
		* ) \
			touch afsl.exp ;; \
	esac

#
# Installation targets
#
install: libsys.a rmtsysd afssyscalls.h pagsh pagsh.krb afs.exp xfsattrs.h
	${INSTALL} -d ${DESTDIR}${libdir}/afs
	${INSTALL} -d ${DESTDIR}${sbindir}
	${INSTALL} -d ${DESTDIR}${includedir}/afs
	${INSTALL_DATA} libsys.a ${DESTDIR}${libdir}/afs/libsys.a
	${INSTALL_PROGRAM} rmtsysd ${DESTDIR}${sbindir}/rmtsysd
	${INSTALL_DATA} ${srcdir}/afssyscalls.h ${DESTDIR}${includedir}/afs/afssyscalls.h
	${INSTALL_PROGRAM} pagsh ${DESTDIR}${bindir}/pagsh
	${INSTALL_PROGRAM} pagsh.krb ${DESTDIR}${bindir}/pagsh.krb
	${INSTALL_DATA} ${srcdir}/xfsattrs.h ${DESTDIR}${includedir}/afs/xfsattrs.h
	@set -x; case ${SYS_NAME} in \
	rs_aix*) \
		${INSTALL_DATA} afs.exp ${DESTDIR}${includedir}/afs/afs.exp;; \
	esac

dest: libsys.a rmtsysd afssyscalls.h pagsh pagsh.krb afs.exp xfsattrs.h
	${INSTALL} -d ${DEST}/lib/afs
	${INSTALL} -d ${DEST}/etc
	${INSTALL} -d ${DEST}/bin
	${INSTALL} -d ${DEST}/include/afs
	${INSTALL_DATA} libsys.a ${DEST}/lib/afs/libsys.a
	${INSTALL_PROGRAM} rmtsysd ${DEST}/etc/rmtsysd
	${INSTALL_PROGRAM} pagsh ${DEST}/bin/pagsh
	${INSTALL_PROGRAM} pagsh.krb ${DEST}/bin/pagsh.krb
	${INSTALL_DATA} ${srcdir}/afssyscalls.h ${DEST}/include/afs/afssyscalls.h
	${INSTALL_DATA} ${srcdir}/xfsattrs.h ${DEST}/include/afs/xfsattrs.h
	@set -x; case ${SYS_NAME} in \
	rs_aix*) \
		${INSTALL_DATA} afs.exp ${DEST}/include/afs/afs.exp ;; \
	esac

#
# Misc targets
#
include ../config/Makefile.version

clean:
	$(RM) -f *.o libsys.a xfsinode iinc idec icreate iopen istat core \
	rmtsysc rmtsyss *.o rmtsys.ss.c rmtsys.cs.c rmtsys.xdr.c rmtsys.h \
	rmtsysd AFS_component_version_number.c pagsh pagsh.krb \
	afs.exp afsl.exp libafssetpag.* Krmtsys.cs.c Krmtsys.h Krmtsys.xdr.c
	$(RM) -rf picobj
