# 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
include @TOP_OBJDIR@/src/config/Makefile.lwp


SFLAGS=-I${TOP_INCDIR}
LIBS=libsys.a \
     ${TOP_LIBDIR}/librx.a \
     libsys.a \
     ${TOP_LIBDIR}/liblwp.a \
     $(TOP_LIBDIR)/libafsutil.a \
     ${TOP_LIBDIR}/libopr.a \
     ${TOP_LIBDIR}/libafshcrypto_lwp.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} ${AFS_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
glue.o: glue.c afssyscalls.h
setpag.o: setpag.c afssyscalls.h
pioctl.o: pioctl.c afssyscalls.h

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
	$(AFS_LDRULE) rmtsysd.o ${LIBS} $(LIB_roken)

pagsh:	pagsh.o libsys.a AFS_component_version_number.o
	$(AFS_LDRULE) pagsh.o ${LIBS} $(LIB_roken)

CFLAGS_pagsh.krb.o = -DAFS_KERBEROS_ENV
pagsh.krb.o: pagsh.c
	$(AFS_CCRULE) $(srcdir)/pagsh.c 

pagsh.krb: libsys.a pagsh.krb.o ${TOP_LIBDIR}/libauth.krb.a ${TOP_LIBDIR}/librxkad.a
	$(AFS_LDRULE) pagsh.krb.o ${TOP_LIBDIR}/libauth.krb.a \
		${TOP_LIBDIR}/librxkad.a ${LIBS} $(LIB_roken)

#
# Test programs.
#

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

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

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

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

iread:	iread.c  AFS_component_version_number.c
	${CC} -o iread $(AFS_CFLAGS) ${srcdir}/iread.c ${LIBS}

iwrite:	iwrite.c  AFS_component_version_number.c
	${CC} -o iwrite $(AFS_CFLAGS) ${srcdir}/iwrite.c ${LIBS}

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

fixit:	fixit.c AFS_component_version_number.c
	$(CC) -o fixit $(AFS_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 $(AFS_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
