# API version. When something changes, increment as appropriate. 
# Ignore at your own risk.
LIBAFSRPCMAJOR=1
LIBAFSRPCMINOR=1

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

# This is a pthread safe library containing rx, rxkad and des.

srcdir=@srcdir@
include @TOP_OBJDIR@/src/config/Makefile.config

CC=${MT_CC}
INCLUDES=-I.. -I${srcdir}/../rx -I${srcdir}../des -I../des \
	-I../rxkad -I${srcdir}/../rxkad -I../rxstat -I../fsint
CFLAGS = ${COMMON_CFLAGS} ${INCLUDES} -DRXDEBUG ${MT_CFLAGS} ${SHLIB_CFLAGS}
SFLAGS=-P -I${TOP_INCDIR}

RX = ../rx
CCRULE = ${CC} ${CFLAGS} -c $?
RXKAD = ../rxkad
RXSTAT = ../rxstat
FSINT = ../fsint
DES = ../des
COMERR = ../comerr
UTIL = ../util
SYS = ${srcdir}/../sys
LWP = ${srcdir}/../lwp

SYSOBJS =\
	syscall.o

UTILOBJS =\
	assert.o \
	casestrcpy.o \
	base64.o

COMERROBJS =\
	error_msg.o \
	et_name.o \
	com_err.o

XDROBJS =\
	xdr.o \
	xdr_array.o \
	xdr_arrayn.o \
	xdr_rx.o \
	xdr_int32.o \
	xdr_int64.o \
	xdr_afsuuid.o \
	xdr_update.o \
	xdr_refernce.o \
	AFS_component_version_number.o

RXOBJS =\
	rx_event.o \
	rx_user.o \
	rx_pthread.o \
	rx.o \
	rx_null.o \
	rx_conncache.o \
	rx_globals.o \
	rx_getaddr.o \
	rx_misc.o \
	rx_packet.o \
	rx_rdwr.o \
	rx_trace.o \
	rx_multi.o

RXSTATOBJS =\
	rxstat.o \
	rxstat.ss.o \
	rxstat.xdr.o \
	rxstat.cs.o

FSINTOBJS =\
	afsint.cs.o \
	afsint.xdr.o \
	afscbint.cs.o \
	afscbint.xdr.o \
	afsaux.o

RXKADOBJS =\
	rxkad_client.o \
	rxkad_server.o \
	rxkad_common.o \
	ticket.o \
	ticket5.o \
	crc.o \
	md4.o \
	md5.o \
	fcrypt.o \
	crypt_conn.o

DESOBJS =\
	des.o \
	cbc_encrypt.o \
	pcbc_encrypt.o \
	cksum.o \
	new_rnd_key.o \
	key_sched.o \
	debug_decl.o \
	quad_cksum.o \
	key_parity.o \
	weak_key.o \
	strng_to_key.o \
	misc.o \
	util.o

CRYPT_OBJ = crypt.o

LWPOBJS = \
	fasttime.o

LIBOBJS = \
	${RXOBJS} \
	${DESOBJS} \
	${XDROBJS} \
	${RXKADOBJS} \
	${COMERROBJS} \
	${UTILOBJS} \
	${SYSOBJS} \
	${CRYPT_OBJ} \
	${RXSTATOBJS} \
	${LWPOBJS} \
	${FSINTOBJS}

LIBAFSRPC = libafsrpc.${SHLIB_SUFFIX}.${LIBAFSRPCMAJOR}.${LIBAFSRPCMINOR}

all: ${TOP_LIBDIR}/${LIBAFSRPC}

install: ${DESTDIR}${libdir}/${LIBAFSRPC}

${DEST}/lib/${LIBAFSRPC}: ${LIBAFSRPC}
	${INSTALL} ${LIBAFSRPC} ${DEST}/lib/${LIBAFSRPC}
	-ln -f -s ${LIBAFSRPC} ${DEST}/lib/libafsrpc.${SHLIB_SUFFIX}
	-ln -f -s ${LIBAFSRPC} ${DEST}/lib/libafsrpc.${SHLIB_SUFFIX}.${LIBAFSRPCMAJOR}

${LIBAFSRPC}: ${LIBOBJS}
	case ${SYS_NAME} in \
	rs_aix4* | rs_aix5*) \
		${SHLIB_LINKER} -o ${LIBAFSRPC} ${LIBOBJS} -bE:${srcdir}/afsrpc.exp ${MT_LIBS};; \
	sun*_5*) \
		${SHLIB_LINKER} -h libafsrpc.${SHLIB_SUFFIX}.${LIBAFSRPCMAJOR} -o ${LIBAFSRPC} ${LIBOBJS} ${MT_LIBS};; \
	amd64_linux*) \
		${SHLIB_LINKER} -Wl,-h,libafsrpc.${SHLIB_SUFFIX}.${LIBAFSRPCMAJOR} -Wl,--version-script=${srcdir}/mapfile.afs_xdr -o ${LIBAFSRPC} ${LIBOBJS} ${MT_LIBS};; \
	*_linux*) \
		${SHLIB_LINKER} -Wl,-h,libafsrpc.${SHLIB_SUFFIX}.${LIBAFSRPCMAJOR} -Wl,--version-script=${srcdir}/mapfile -o ${LIBAFSRPC} ${LIBOBJS} ${MT_LIBS};; \
	*) \
		${SHLIB_LINKER} -o ${LIBAFSRPC} ${LIBOBJS} ${MT_LIBS};; \
	esac

rx_event.o: ${RX}/rx_event.c
	${CCRULE}

rx_user.o: ${RX}/rx_user.c
	${CCRULE}

rx_pthread.o: ${RX}/rx_pthread.c
	${CCRULE}

rx.o: ${RX}/rx.c
	${CCRULE}

rx_conncache.o: ${RX}/rx_conncache.c
	${CCRULE}

rx_null.o: ${RX}/rx_null.c
	${CCRULE}

rx_globals.o: ${RX}/rx_globals.c
	${CCRULE}

rx_getaddr.o: ${RX}/rx_getaddr.c
	${CCRULE}

rx_misc.o: ${RX}/rx_misc.c
	${CCRULE}

rx_packet.o: ${RX}/rx_packet.c
	${CCRULE}

rx_rdwr.o: ${RX}/rx_rdwr.c
	${CCRULE}

rx_trace.o: ${RX}/rx_trace.c
	${CCRULE}

rx_multi.o: ${RX}/rx_multi.c
	${CCRULE}

rxkad_client.o: ${RXKAD}/rxkad_client.c
	${CCRULE}

rxkad_server.o: ${RXKAD}/rxkad_server.c
	${CCRULE}

rxkad_common.o: ${RXKAD}/rxkad_common.c
	${CCRULE}

ticket.o: ${RXKAD}/ticket.c
	${CCRULE}

ticket5.o: ${RXKAD}/ticket5.c
	${CCRULE}

crc.o: ${RXKAD}/crc.c
	${CCRULE}

md4.o: ${RXKAD}/md4.c
	${CCRULE}

md5.o: ${RXKAD}/md5.c
	${CCRULE}

fcrypt.o: ${RXKAD}/domestic/fcrypt.c
	${CCRULE}

crypt_conn.o: ${RXKAD}/domestic/crypt_conn.c
	${CCRULE}

AFS_component_version_number.o: ${RX}/AFS_component_version_number.c
	${CCRULE}

xdr.o: ${RX}/xdr.c
	${CCRULE}

xdr_int32.o: ${RX}/xdr_int32.c
	${CCRULE}

xdr_int64.o: ${RX}/xdr_int64.c
	${CCRULE}

xdr_array.o: ${RX}/xdr_array.c
	${CCRULE}

xdr_arrayn.o: ${RX}/xdr_arrayn.c
	${CCRULE}

xdr_float.o: ${RX}/xdr_float.c
	${CCRULE}

xdr_mem.o: ${RX}/xdr_mem.c
	${CCRULE}

xdr_rec.o: ${RX}/xdr_rec.c
	${CCRULE}

xdr_refernce.o: ${RX}/xdr_refernce.c
	${CCRULE}

xdr_rx.o: ${RX}/xdr_rx.c
	${CCRULE}

xdr_update.o: ${RX}/xdr_update.c
	${CCRULE}

xdr_afsuuid.o: ${RX}/xdr_afsuuid.c
	${CCRULE}

# Note that the special case statement for compiling des.c is present
# simply to work around a compiler bug on HP-UX 11.0.  The symptom of
# the problem is that linking the pthread fileserver fails with messages
# such as
#
#   pxdb internal warning: cu[84]: SLT_SRCFILE[411] out of synch
#   Please contact your HP Support representative
#   pxdb internal warning: cu[84]: SLT_SRCFILE[442] out of synch
#   pxdb internal warning: cu[84]: SLT_SRCFILE[450] out of synch
#   pxdb internal warning: cu[84]: SLT_SRCFILE[529] out of synch
#   pxdb internal warning: cu[84]: SLT_SRCFILE[544] out of synch
#   ...
#   pxdb32: internal error. File won't be debuggable (still a valid executable)
#   *** Error exit code 10
#
# The problematic version of pxdb is:
#
#   $ what /opt/langtools/bin/pxdb32
#   /opt/langtools/bin/pxdb32:
#           HP92453-02 A.10.0A HP-UX SYMBOLIC DEBUGGER (PXDB) $Revision: 1.15.2.10 $
#
# The problem occurs when -g and -O are both used when compiling des.c.
# The simplest way to work around the problem is to leave out either -g or -O.
# Since des.c is relatively stable I've chosen to eliminate -g rather
# than take any hit in performance.

des.o: ${DES}/des.c
	set -x; \
	case ${SYS_NAME} in \
	hp_ux11*) \
		set X `echo ${CCRULE} | sed s/-g//`; shift; \
		"$$@" \
		;; \
	*) \
		${CCRULE} \
		;; \
	esac

crypt.o: ${DES}/crypt.c
	${CCRULE}

cbc_encrypt.o: ${DES}/cbc_encrypt.c
	${CCRULE}

pcbc_encrypt.o: ${DES}/pcbc_encrypt.c
	${CCRULE}

cksum.o: ${DES}/cksum.c
	${CCRULE}

new_rnd_key.o: ${DES}/new_rnd_key.c
	${CCRULE}

key_sched.o: ${DES}/key_sched.c
	${CCRULE}

debug_decl.o: ${DES}/debug_decl.c
	${CCRULE}

quad_cksum.o: ${DES}/quad_cksum.c
	${CCRULE}

key_parity.o: ${DES}/key_parity.c
	${CCRULE}

weak_key.o: ${DES}/weak_key.c
	${CCRULE}

strng_to_key.o: ${DES}/strng_to_key.c
	${CCRULE}

misc.o: ${DES}/misc.c
	${CCRULE}

util.o: ${DES}/util.c
	${CCRULE}

error_msg.o: ${COMERR}/error_msg.c
	${CCRULE}

et_name.o: ${COMERR}/et_name.c
	${CCRULE}

com_err.o: ${COMERR}/com_err.c
	${CCRULE}

casestrcpy.o: ${UTIL}/casestrcpy.c
	${CCRULE}

assert.o: ${UTIL}/assert.c
	${CCRULE}

base64.o: ${UTIL}/base64.c
	${CCRULE}

fasttime.o: ${LWP}/fasttime.c
	${CCRULE} ${LWP}/fasttime.c

syscall.o: ${SYS}/syscall.s
	case "$(SYS_NAME)" in \
	     sun4x_5* | sunx86_5*) \
		/usr/ccs/lib/cpp  ${SFLAGS} ${SYS}/syscall.s syscall.ss; \
		as -o syscall.o syscall.ss;		\
		$(RM) syscall.ss;;				\
	 sgi_* | *_darwin_* ) \
                ${CC} ${CFLAGS} -c ${SYS}/syscall.s;;          \
	 alpha_dux?? ) \
		${AS} -P ${CFLAGS} -D_NO_PROTO -DMACH -DOSF -nostdinc -traditional -DASSEMBLER ${SYS}/syscall.s; \
		${AS} -o syscall.o syscall.i; \
		$(RM) -f syscall.ss syscall.i;; \
	 *fbsd* ) \
		touch syscall.o ;; \
	 *) \
		/lib/cpp  ${SFLAGS} ${SYS}/syscall.s syscall.ss; \
		as -o syscall.o syscall.ss;		\
		$(RM) syscall.ss;;				\
	esac

rxstat.o: ${RXSTAT}/rxstat.c
	${CCRULE}

rxstat.cs.o: ${RXSTAT}/rxstat.cs.c
	${CCRULE}

rxstat.ss.o: ${RXSTAT}/rxstat.ss.c
	${CCRULE}

rxstat.xdr.o: ${RXSTAT}/rxstat.xdr.c
	${CCRULE}

afsint.cs.o: ${FSINT}/afsint.cs.c
	${CCRULE}

afsint.xdr.o: ${FSINT}/afsint.xdr.c
	${CCRULE}

afscbint.cs.o: ${FSINT}/afscbint.cs.c
	${CCRULE}

afscbint.xdr.o: ${FSINT}/afscbint.xdr.c
	${CCRULE}

afsaux.o: ${FSINT}/afsaux.c
	${CCRULE}

clean:
	$(RM) -f *.o libafsrpc*

${DESTDIR}${libdir}/${LIBAFSRPC}: ${LIBAFSRPC}
	${INSTALL} ${LIBAFSRPC} ${DESTDIR}${libdir}/${LIBAFSRPC}
	-ln -f -s ${LIBAFSRPC} ${DESTDIR}${libdir}/libafsrpc.${SHLIB_SUFFIX}
	-ln -f -s ${LIBAFSRPC} ${DESTDIR}${libdir}/libafsrpc.${SHLIB_SUFFIX}.${LIBAFSRPCMAJOR}

${TOP_LIBDIR}/${LIBAFSRPC}: ${LIBAFSRPC}
	${INSTALL} ${LIBAFSRPC} ${TOP_LIBDIR}/${LIBAFSRPC}
	-ln -f -s ${LIBAFSRPC} ${TOP_LIBDIR}/libafsrpc.${SHLIB_SUFFIX}
	-ln -f -s ${LIBAFSRPC} ${TOP_LIBDIR}/libafsrpc.${SHLIB_SUFFIX}.${LIBAFSRPCMAJOR}

dest: ${DEST}/lib/${LIBAFSRPC}

