# 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

srcdir=@srcdir@
include @TOP_OBJDIR@/src/config/Makefile.config
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@

  EXPORTS = -bexport:export.exp
  IMPORTS = /lib/kernex.exp /lib/syscalls.exp ${srcdir}/extras.exp
     KOBJ = export.o symtab.o

EXPORTS32 = @AIX32@export.exp export.ext.nonfs export.ext cfgexport cfgafs
EXPORTS64 = @AIX64@export64.exp export64.ext.nonfs export64.ext cfgexport64 cfgafs64
TOPEXP32  = @AIX32@${TOP_LIBDIR}/export.exp
TOPEXP64  = @AIX64@${TOP_LIBDIR}/export64.exp

all: $(TOPEXP32) $(TOPEXP64) ${TOP_LIBDIR}/extras.exp
	${INSTALL} -d ${KERNELDIR}
	${INSTALL} -d ${UKERNELDIR}
	${INSTALL_DATA} ${srcdir}/export.h ${KERNELDIR}/export.h
	@AIX32@${INSTALL_DATA} export.exp ${KERNELDIR}/export.exp
	@AIX64@${INSTALL_DATA} export64.exp ${KERNELDIR}/export64.exp
	${INSTALL_DATA} ${srcdir}/export.h ${UKERNELDIR}/export.h
	@AIX32@${INSTALL_DATA} export.exp ${UKERNELDIR}/export.exp
	@AIX64@${INSTALL_DATA} export64.exp ${UKERNELDIR}/export64.exp

${TOP_LIBDIR}/export.exp: export.exp
	${INSTALL_DATA} $? $@

${TOP_LIBDIR}/export64.exp: export64.exp
	${INSTALL_DATA} $? $@

${TOP_LIBDIR}/extras.exp: ${srcdir}/extras.exp
	${INSTALL_DATA} $? $@

noversion system: install

export.exp: ${srcdir}/export4.exp ${srcdir}/export5.exp
	case ${SYS_NAME} in \
	rs_aix4* ) \
		cp -p ${srcdir}/export4.exp export.exp ;; \
	rs_aix5* ) \
		cp -p ${srcdir}/export5.exp export.exp ;; \
	esac

export64.exp: ${srcdir}/export4-64.exp ${srcdir}/export5-64.exp
	case ${SYS_NAME} in \
	rs_aix4* ) \
		cp -p ${srcdir}/export4-64.exp export64.exp ;; \
	rs_aix5* ) \
		cp -p ${srcdir}/export5-64.exp export64.exp ;; \
	rs_aix6* ) \
		cp -p ${srcdir}/export5-64.exp export64.exp ;; \
	esac

export.ext: ${KOBJ}
	${LD} -o export.ext -eexport ${IMPORTS} ${KOBJ} ${EXPORTS} -lcsys

export64.ext: export64.o symtab64.o
	${LD} -b64 -o export64.ext -eexport ${IMPORTS} export64.o symtab64.o \
		-bexport:export64.exp -lcsys

export.ext.nonfs: export.nonfs.o symtab.o
	${LD} -o export.ext.nonfs -eexport ${IMPORTS} export.nonfs.o \
		symtab.o ${EXPORTS} -lcsys

export64.ext.nonfs: export64.nonfs.o symtab64.o
	${LD} -b64 -o export64.ext.nonfs -eexport ${IMPORTS} export64.nonfs.o \
		symtab64.o -bexport:export64.exp -lcsys

symtab.o symtab64.o: ${srcdir}/symtab.c
	case ${SYS_NAME} in \
	rs_aix4* ) \
		${CC} ${CFLAGS} -c ${srcdir}/symtab.c ;; \
	rs_aix5* ) \
		${CC} ${CFLAGS} -q64 -D__XCOFF64__ -DAFS_64BIT_KERNEL -DAFS_AIX51_ENV -c ${srcdir}/symtab.c ; \
		mv symtab.o symtab64.o ; \
		${CC} ${CFLAGS} -DAFS_AIX51_ENV -c ${srcdir}/symtab.c ;; \
	rs_aix6* ) \
		${CC} ${CFLAGS} -q64 -D__XCOFF64__ -DAFS_64BIT_KERNEL -DAFS_AIX51_ENV -c ${srcdir}/symtab.c ; \
		mv symtab.o symtab64.o ;; \
	esac

export.o export64.o: ${srcdir}/export.c
	case ${SYS_NAME} in \
	rs_aix4* ) \
		${CC} ${CFLAGS} -c ${srcdir}/export.c ;; \
	rs_aix5* ) \
		${CC} ${CFLAGS} -q64 -D__XCOFF64__ -DAFS_64BIT_KERNEL -DAFS_AIX51_ENV -c ${srcdir}/export.c ; \
		mv export.o export64.o ; \
		${CC} ${CFLAGS} -DAFS_AIX51_ENV -c ${srcdir}/export.c ;; \
	rs_aix6* ) \
		${CC} ${CFLAGS} -q64 -D__XCOFF64__ -DAFS_64BIT_KERNEL -DAFS_AIX51_ENV -c ${srcdir}/export.c ; \
		mv export.o export64.o ;; \
	esac

export.nonfs.o export64.nonfs.o: ${srcdir}/export.c
	case ${SYS_NAME} in \
	rs_aix4* ) \
		${CC} ${INCS} -DAFS_NONFSTRANS -c ${srcdir}/export.c ; \
		mv export.o export.nonfs.o ;; \
	rs_aix5* ) \
		${CC} -q64 ${INCS} -D__XCOFF64__ -DAFS_64BIT_KERNEL -DAFS_NONFSTRANS -DAFS_AIX51_ENV -c ${srcdir}/export.c ; \
		mv export.o export64.nonfs.o ; \
		${CC} ${INCS} -DAFS_NONFSTRANS -DAFS_AIX51_ENV -c ${srcdir}/export.c ; \
		mv export.o export.nonfs.o ;; \
	rs_aix6* ) \
		${CC} -q64 ${INCS} -D__XCOFF64__ -DAFS_64BIT_KERNEL -DAFS_NONFSTRANS -DAFS_AIX51_ENV -c ${srcdir}/export.c ; \
		mv export.o export64.nonfs.o ;; \
	esac

cfgexport: cfgexport.o
	${CC} -g ${INCS} -o cfgexport cfgexport.o

cfgexport64: cfgexport64.o
	${CC} -g ${INCS} -q64 -o cfgexport64 cfgexport64.o

cfgafs: cfgafs.o
	${CC} ${INCS} -o cfgafs cfgafs.o

cfgafs64: cfgafs64.o
	${CC} -g ${INCS} -q64 -o cfgafs64 cfgafs64.o

cfgexport64.o: ${srcdir}/cfgexport.c AFS_component_version_number.c
	${CC} -g -q64 ${CFLAGS} -D__XCOFF64__ -c ${srcdir}/cfgexport.c -o cfgexport64.o

cfgexport.o: ${srcdir}/cfgexport.c AFS_component_version_number.c
cfgafs.o: ${srcdir}/cfgafs.c AFS_component_version_number.c
cfgafs64.o: ${srcdir}/cfgafs.c AFS_component_version_number.c
	${CC} -q64 ${CFLAGS} -c ${srcdir}/cfgafs.c -o cfgafs64.o

clean:
	$(RM) -f *.o *.Zlst *.map *.out AFS_component_version_number.c
	$(RM) -f export.exp export64.exp
	$(RM) -f cfgexport cfgexport64
	$(RM) -f cfgafs cfgafs64
	$(RM) -f *.ext *.ext.nonfs

install: $(EXPORTS32) $(EXPORTS64)
	${INSTALL} -d ${DESTDIR}${afskerneldir}
	${INSTALL} -d ${DESTDIR}${libdir}/afs
	${INSTALL_DATA} ${srcdir}/extras.exp ${DESTDIR}${libdir}/afs/extras.exp
	@AIX32@${INSTALL_DATA} export.exp ${DESTDIR}${libdir}/afs/export.exp
	@AIX32@${INSTALL_DATA} export.ext ${DESTDIR}${afskerneldir}/export.ext
	@AIX32@${INSTALL_DATA} export.ext.nonfs ${DESTDIR}${afskerneldir}/export.ext.nonfs
	@AIX32@${INSTALL_DATA} cfgexport ${DESTDIR}${afskerneldir}/cfgexport
	@AIX32@${INSTALL_DATA} cfgafs ${DESTDIR}${afskerneldir}/cfgafs
	@AIX64@${INSTALL_DATA} export64.exp ${DESTDIR}${libdir}/afs/export64.exp
	@AIX64@${INSTALL_DATA} export64.ext ${DESTDIR}${afskerneldir}/export64.ext
	@AIX64@${INSTALL_DATA} export64.ext.nonfs ${DESTDIR}${afskerneldir}/export64.ext.nonfs
	@AIX64@${INSTALL_DATA} cfgexport64 ${DESTDIR}${afskerneldir}/cfgexport64
	@AIX64@${INSTALL_DATA} cfgafs64 ${DESTDIR}${afskerneldir}/cfgafs64

dest: $(EXPORTS32) $(EXPORTS64)
	${INSTALL} -d ${DEST}/root.client/usr/vice/etc/dkload
	${INSTALL} -d ${DEST}/lib/afs
	${INSTALL_DATA} ${srcdir}/extras.exp ${DEST}/lib/afs/extras.exp
	@AIX32@${INSTALL_DATA} export.exp ${DEST}/lib/afs/export.exp
	@AIX32@${INSTALL} export.ext ${DEST}/root.client/usr/vice/etc/dkload/export.ext
	@AIX32@${INSTALL} export.ext.nonfs ${DEST}/root.client/usr/vice/etc/dkload/export.ext.nonfs
	@AIX32@${INSTALL} cfgexport ${DEST}/root.client/usr/vice/etc/dkload/cfgexport
	@AIX32@${INSTALL} cfgafs ${DEST}/root.client/usr/vice/etc/dkload/cfgafs
	@AIX64@${INSTALL_DATA} export64.exp ${DEST}/lib/afs/export64.exp
	@AIX64@${INSTALL} export64.ext ${DEST}/root.client/usr/vice/etc/dkload/export64.ext
	@AIX64@${INSTALL} export64.ext.nonfs ${DEST}/root.client/usr/vice/etc/dkload/export64.ext.nonfs
	@AIX64@${INSTALL} cfgexport64 ${DEST}/root.client/usr/vice/etc/dkload/cfgexport64
	@AIX64@${INSTALL} cfgafs64 ${DEST}/root.client/usr/vice/etc/dkload/cfgafs64

include ../config/Makefile.version
