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

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

CC		= ${MT_CC}
INCLUDES	= -I. -I${srcdir} -I../sys
CFLAGS		= ${COMMON_CFLAGS} ${INCLUDES} ${MT_CFLAGS} ${SHLIB_CFLAGS}

SFLAGS		= -I${TOP_INCDIR}
SYS		= ${srcdir}/../sys
SYSOBJS		= glue.o pioctl.o setpag.o
LIBOBJS		= kopenafs.o ${SYSOBJS} AFS_component_version_number.o

LIBKOPENAFS	= libkopenafs.${SHLIB_SUFFIX}.${MAJOR}.${MINOR}

all: ${TOP_LIBDIR}/${LIBKOPENAFS} ${TOP_LIBDIR}/libkopenafs.a \
		${TOP_INCDIR}/kopenafs.h

${TOP_LIBDIR}/${LIBKOPENAFS}: ${LIBKOPENAFS}
	../config/shlib-install -d ${TOP_LIBDIR} \
		-l libkopenafs -M ${MAJOR} -m ${MINOR}

${TOP_LIBDIR}/libkopenafs.a: libkopenafs.a
	${INSTALL_DATA} libkopenafs.a $@

${TOP_INCDIR}/kopenafs.h: kopenafs.h
	${INSTALL_DATA} kopenafs.h $@

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

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

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

# This file is only actually used on SGI and AIX, but some systems can't cope
# with an empty .o file being included in a link.
syscall.o: ${SYS}/syscall.s
	@set -e; set -x; case "$(SYS_NAME)" in \
	sgi_*) \
                ${CC} ${CFLAGS} -c ${SYS}/syscall.s; \
		;; \
	rs_aix* | hp_ux10*) \
		$(PATH_CPP) -P ${SFLAGS} ${SYS}/syscall.s > syscall.ss; \
		as -o syscall.o syscall.ss; \
		$(RM) syscall.ss; \
		;; \
	*) \
		touch syscall.o ; \
		;; \
	esac

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

${LIBKOPENAFS}: ${LIBOBJS} syscall.o
	@set -e; set -x; case ${SYS_NAME} in \
	sgi_* | rs_aix* | hp_ux10*) \
		../config/shlib-build -d $(srcdir) -l libkopenafs \
			-M ${MAJOR} -m ${MINOR} -- \
			${LIBOBJS} syscall.o ${MT_LIBS} ; \
		;; \
	*) \
		../config/shlib-build -d $(srcdir) -l libkopenafs \
			-M ${MAJOR} -m ${MINOR} -- \
			${LIBOBJS} ${MT_LIBS} ; \
		;; \
	esac

test-unlog: test-unlog.o libkopenafs.a
	${CC} -o test-unlog test-unlog.o libkopenafs.a ${XLIBS} ${CFLAGS}

test-setpag: test-setpag.o libkopenafs.a
	${CC} -o test-setpag test-setpag.o libkopenafs.a ${XLIBS} ${CFLAGS}

#
# Installation targets
#
install: ${LIBKOPENAFS}
	${INSTALL} -d ${DESTDIR}${libdir}
	${INSTALL} -d ${DESTDIR}${includedir}
	${INSTALL_DATA} libkopenafs.a ${DESTDIR}${libdir}/libkopenafs.a
	${INSTALL_DATA} kopenafs.h ${DESTDIR}${includedir}/kopenafs.h
	../config/shlib-install -d ${DESTDIR}${libdir} \
		-l libkopenafs -M ${MAJOR} -m ${MINOR}

dest: ${LIBKOPENAFS}
	${INSTALL} -d ${DEST}/lib
	${INSTALL} -d ${DEST}/include
	${INSTALL_DATA} libkopenafs.a ${DEST}/lib/libkopenafs.a
	${INSTALL_DATA} kopenafs.h ${DEST}/include/kopenafs.h
	../config/shlib-install -d ${DEST}/lib \
		-l libkopenafs -M ${MAJOR} -m ${MINOR}

#
# Misc targets
#
clean:
	$(RM) -f *.o *.a ${LIBKOPENAFS} AFS_component_version_number.c \
		test-setpag test-unlog

include ../config/Makefile.version
