# API version. When something changes, increment as appropriate. 
# Ignore at your own risk.
LIBAFSSETPAGMAJOR=1
LIBAFSSETPAGMINOR=0

# 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

CFLAGS=-I. -I${srcdir} ${DBUG} -I${TOP_OBJDIR}/src/config -I${TOP_INCDIR}  ${XCFLAGS}
SFLAGS=-P -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 glue.o syscall.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 

LIBAFSSETPAG = libafssetpag.${SHLIB_SUFFIX}.${LIBAFSSETPAGMAJOR}.${LIBAFSSETPAGMINOR}

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

libsys.a: ${OBJECTS} ${RMTOBJS} afsl.exp AFS_component_version_number.o
	-$(RM) -f $@
	$(AR) crv $@ ${OBJECTS} ${RMTOBJS} \
		AFS_component_version_number.o ${LIBSYS_AIX_EXP}
	$(RANLIB) $@
	case "${SYS_NAME}" in                   	\
		rs_aix*) 			        \
			$(AR) crv $@ afsl.exp;;         \
	esac

${LIBAFSSETPAG}: ${SHLIBOBJS}
	case ${SYS_NAME} in \
	*_linux*) \
	    ${SHLIB_LINKER} -Wl,-h,libafssetpag.so.${LIBAFSSETPAGMAJOR} \
	        -o ${LIBAFSSETPAG} -Wl,--version-script=mapfile \
	        ${SHLIBOBJS};; \
	rs_aix4*) \
	    ${SHLIB_LINKER} -o ${LIBAFSSETPAG} ${SHLIBOBJS} \
	        -bE:afssetpag.exp;; \
	sun*_5*) \
	    ${SHLIB_LINKER} -h libafssetpag.so.${LIBAFSSETPAGMAJOR} \
	        -o ${LIBAFSSETPAG} ${SHLIBOBJS};; \
	*bsd*) \
	    touch ${LIBAFSSETPAG};; \
	*) \
	    ${SHLIB_LINKER} -o ${LIBAFSSETPAG} ${SHLIBOBJS};; \
	esac

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

syscall.o: syscall.s
	case "$(SYS_NAME)" in \
	 sun4c_51 | sun4c_52 | sun4m_51 | sun4m_52 | sun4c_53 | sun4m_53  | sun4_53 | sun4_52 | sun4_54 | sun4c_54 | sun4m_54 | sun4x_5? | sun4x_5?? | sunx86_5? | sunx86_5?? ) \
		/usr/ccs/lib/cpp  ${SFLAGS} ${srcdir}/syscall.s syscall.ss; \
		as -o syscall.o syscall.ss;		\
		$(RM) syscall.ss;;				\
	 sgi_* |*_darwin* ) \
                ${CC} ${CFLAGS} -c ${srcdir}/syscall.s;;          \
	 alpha_osf1 | alpha_osf20 |  alpha_osf30 | alpha_osf32 | alpha_osf32c | alpha_dux?? ) \
		${AS} -P ${CFLAGS} -D_NO_PROTO -DMACH -DOSF -nostdinc -traditional -DASSEMBLER ${srcdir}/syscall.s; \
		${AS} -o syscall.o syscall.i; \
		$(RM) -f syscall.ss syscall.i;; \
	 hp_ux11? ) \
		touch syscall.o;; \
	amd64_fbsd*|i386_*bsd*|*nbsd*) \
		touch syscall.o;; \
	 *) \
		/lib/cpp  ${SFLAGS} ${srcdir}/syscall.s syscall.ss; \
		as -o syscall.o syscall.ss;		\
		$(RM) syscall.ss;;				\
	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

picobj: afssyscalls.h
	mkdir -p picobj
	cp ${srcdir}/afssyscalls.h picobj/afssyscalls.h

picobj/glue.o: picobj glue.c afssyscalls.h
	rm -f picobj/glue.c
	cp ${srcdir}/glue.c picobj/glue.c
	cd picobj && ${CCOBJ} ${CFLAGS} ${SHLIB_CFLAGS} -c glue.c

picobj/setpag.o: picobj setpag.c afssyscalls.h
	rm -f picobj/setpag.c
	cp ${srcdir}/setpag.c picobj/setpag.c
	cd picobj && ${CCOBJ} ${CFLAGS} ${SHLIB_CFLAGS} -c setpag.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} -C -o $@ ${srcdir}/rmtsys.xg

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

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

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

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

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

pagsh.krb: libsys.a
	${CC} ${CFLAGS} -c ${srcdir}/pagsh.c -DAFS_KERBEROS_ENV 
	${CC} ${CFLAGS} -o pagsh.krb pagsh.o ${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
	case "${SYS_NAME}" in \
		sgi_62 | sgi_64 ) \
		$(CC) -o xfsinode ${CFLAGS} ${srcdir}/xfsinode.c ${LIBS}
	esac

${TOP_LIBDIR}/${LIBAFSSETPAG}: ${LIBAFSSETPAG}
	${INSTALL} ${LIBAFSSETPAG} ${TOP_LIBDIR}/${LIBAFSSETPAG}
	-ln -f -s ${LIBAFSSETPAG} ${TOP_LIBDIR}/libafssetpag.${SHLIB_SUFFIX}
	-ln -f -s ${LIBAFSSETPAG} ${TOP_LIBDIR}/libafssetpag.${SHLIB_SUFFIX}.${LIBAFSSETPAGMAJOR}
 

afs.exp: ${srcdir}/afs4.exp ${srcdir}/afs5.exp
	case ${SYS_NAME} in \
		rs_aix5* ) \
			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
	case ${SYS_NAME} in \
		rs_aix5* ) \
			cp -p ${srcdir}/afsl5.exp afsl.exp ;; \
		rs_aix* ) \
			cp -p ${srcdir}/afsl4.exp afsl.exp ;; \
		* ) \
			touch afsl.exp ;; \
	esac

#
# Installation targets
#

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

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

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

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

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

${UKERNELDIR}/afs:
	mkdir -p $@

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

${KERNELDIR}/afs:
	mkdir -p $@

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

depinstall: \
	${TOP_INCDIR}/afs/afssyscalls.h \
	${TOP_INCDIR}/afs/afs.exp \
	${TOP_INCDIR}/afs/xfsattrs.h \
	${KERNELDIR}/afs/xfsattrs.h \
	${UKERNELDIR}/afs/afsl.exp

install: \
	${DESTDIR}${libdir}/afs/libsys.a \
	${DESTDIR}${libdir}/${LIBAFSSETPAG} \
	${DESTDIR}${sbindir}/rmtsysd \
	${DESTDIR}${includedir}/afs/afssyscalls.h \
	${DESTDIR}${bindir}/pagsh \
	${DESTDIR}${bindir}/pagsh.krb \
	${DESTDIR}${includedir}/afs/afs.exp \
	${DESTDIR}${includedir}/afs/xfsattrs.h

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

${DESTDIR}${libdir}/${LIBAFSSETPAG}: ${LIBAFSSETPAG}
	${INSTALL} ${LIBAFSSETPAG} ${DESTDIR}${libdir}/${LIBAFSSETPAG}
	-ln -f -s ${LIBAFSSETPAG} \
	    ${DESTDIR}${libdir}/libafssetpag.${SHLIB_SUFFIX}
	-ln -f -s ${LIBAFSSETPAG} \
	    ${DESTDIR}${libdir}/libafssetpag.${SHLIB_SUFFIX}.${LIBAFSSETPAGMAJOR}

${DESTDIR}${sbindir}/rmtsysd: rmtsysd
	${INSTALL} -s $? $@

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

${DESTDIR}${bindir}/pagsh: pagsh
	${INSTALL} -s $? $@

${DESTDIR}${bindir}/pagsh.krb: pagsh.krb
	${INSTALL} -s $? $@

${DESTDIR}${includedir}/afs/afs.exp: afs.exp
	case ${SYS_NAME} in \
		rs_aix* ) \
			${INSTALL} $? $@ ;; \
	esac

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

dest: \
	${DEST}/lib/afs/libsys.a \
	${TOP_LIBDIR}/${LIBAFSSETPAG} \
	${DEST}/etc/rmtsysd \
	${DEST}/bin/pagsh \
	${DEST}/bin/pagsh.krb \
	${DEST}/include/afs/afssyscalls.h \
	${DEST}/include/afs/afs.exp \
	${DEST}/include/afs/xfsattrs.h

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

${DEST}/include/afs/afs.exp: afs.exp
	case ${SYS_NAME} in \
		rs_aix* ) \
			${INSTALL} $? $@ ;; \
	esac

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

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

${DEST}/etc/rmtsysd: rmtsysd
	${INSTALL} -s $? $@

${DEST}/bin/pagsh: pagsh
	${INSTALL} -s $? $@

${DEST}/bin/pagsh.krb: pagsh.krb
	${INSTALL} -s $? $@

#
# 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.*
	$(RM) -rf picobj
