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

LT_current = 2
LT_revision = 0
LT_age = 0

LT_objs = glue.lo pioctl.lo setpag.lo kopenafs.lo \
	AFS_component_version_number.lo

MODULE_INCLUDE	= -I. -I${srcdir} -I../sys

SFLAGS		= -I${TOP_INCDIR}
SYS		= ${srcdir}/../sys

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

${TOP_LIBDIR}/libkopenafs.${SHLIB_SUFFIX}: libkopenafs.la
	${LT_INSTALL_DATA} libkopenafs.la ${TOP_LIBDIR}/libkopenafs.la
	${RM} ${TOP_LIBDIR}/libkopenafs.la

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

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

# Build rules for foreign sources.  The implicit ones don't work when our
# sources are in a different castle.
glue.lo: $(SYS)/glue.c $(SYS)/afssyscalls.h
	$(LT_CCRULE) $(SYS)/glue.c

pioctl.lo: $(SYS)/pioctl.c $(SYS)/afssyscalls.h
	$(LT_CCRULE) $(SYS)/pioctl.c

setpag.lo: $(SYS)/setpag.c $(SYS)/afssyscalls.h
	$(LT_CCRULE) $(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.lo: $(SYS)/syscall.s
	@set -e; set -x; case "$(SYS_NAME)" in \
	sgi_*) \
	        ${CC} ${AFS_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.c ; \
		$(CC) $(AFS_CFLAGS) -c syscall.c -o syscall.o; \
		;; \
	esac
	rm -f $@
	echo "# Generated by libtool (GNU libtool) 0.0.0" > $@
	echo "pic_object='syscall.o'" >> $@
	echo "non_pic_object='syscall.o'" >> $@

libkopenafs.a: $(LT_objs)
	$(LT_LDLIB_static) $(LT_objs)

libkopenafs.la: libkopenafs.la.sym $(LT_objs)
	$(LT_LDLIB_shlib) $(LT_objs)

test-unlog: test-unlog.lo libkopenafs.la
	$(LT_LDRULE_static) test-unlog.lo libkopenafs.la $(XLIBS)

test-setpag: test-setpag.lo libkopenafs.la
	$(LT_LDRULE_static) test-setpag.lo libkopenafs.la $(XLIBS)

#
# Installation targets
#
install: libkopenafs.la libkopenafs.a
	${INSTALL} -d ${DESTDIR}${libdir}
	${INSTALL} -d ${DESTDIR}${includedir}
	${LT_INSTALL_DATA} libkopenafs.la ${DESTDIR}${libdir}/libkopenafs.la
	${RM} ${DESTDIR}${libdir}/libkopenafs.la
	${INSTALL_DATA} libkopenafs.a ${DESTDIR}${libdir}/libkopenafs.a
	${INSTALL_DATA} ${srcdir}/kopenafs.h ${DESTDIR}${includedir}/kopenafs.h

dest: libkopenafs.la libkopenafs.a
	${INSTALL} -d ${DEST}/lib
	${INSTALL} -d ${DEST}/include
	${LT_INSTALL_DATA} libkopenafs.la ${DEST}/lib/libkopenafs.la
	${RM} ${DEST}/lib/libkopenafs.la
	${INSTALL_DATA} libkopenafs.a ${DEST}/lib/libkopenafs.a
	${INSTALL_DATA} ${srcdir}/kopenafs.h ${DEST}/include/kopenafs.h

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

include ../config/Makefile.version
