# 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}
CFLAGS = ${COMMON_CFLAGS} -I${srcdir}/../des -I../des -I../rxkad -I${srcdir}/../rxkad \
	-I../fsint -DRXDEBUG ${MT_CFLAGS}

SFLAGS=-P -I${TOP_INCDIR}
RX = ${srcdir}/../rx
CCRULE = ${CC} ${CFLAGS} -c 
RXKAD = ${srcdir}/../rxkad
RXSTAT = ${srcdir}/../rxstat
FSINT = ${srcdir}/../fsint
DES = ${srcdir}/../des
COMERR = ${srcdir}/../comerr
UTIL = ${srcdir}/../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}

all: ${TOP_LIBDIR}/libafsrpc.a

install: ${DESTDIR}${libdir}/libafsrpc.a

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

libafsrpc.a: ${LIBOBJS}
	$(RM) -f $@
	$(AR) crv $@ ${LIBOBJS}
	$(RANLIB) $@
	case "${SYS_NAME}" in \
	    rs_aix*) \
		$(AR) crv $@ ../sys/afsl.exp;; \
        esac

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

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

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

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

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

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

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

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

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

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

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

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

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

${RXOBJS}: ${RX}/rx.h ${RX}/rx_user.h ${RX}/rx_globals.h ${RX}/rx_clock.h ${RX}/rx_queue.h ${RX}/rx_event.h

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

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

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

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

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

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

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

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

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

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

AFS_component_version_number.o: ${TOP_OBJDIR}/src/rx/AFS_component_version_number.c
	${CCRULE} ${TOP_OBJDIR}/src/rx/AFS_component_version_number.c

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

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

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

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

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

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

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

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

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

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

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

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

# 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.36 $
#
# 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} ${DES}/des.c | sed s/-g//`; shift; \
		"$$@" \
		;; \
	*) \
		${CCRULE} ${DES}/des.c \
		;; \
	esac

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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;; \
	 *bsd* ) \
		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}/rxstat.c

rxstat.cs.o: ${TOP_OBJDIR}/src/rxstat/rxstat.cs.c
	${CCRULE} ${TOP_OBJDIR}/src/rxstat/rxstat.cs.c

rxstat.ss.o: ${TOP_OBJDIR}/src/rxstat/rxstat.ss.c
	${CCRULE} ${TOP_OBJDIR}/src/rxstat/rxstat.ss.c

rxstat.xdr.o: ${TOP_OBJDIR}/src/rxstat//rxstat.xdr.c
	${CCRULE} ${TOP_OBJDIR}/src/rxstat//rxstat.xdr.c

afsint.cs.o: ${TOP_OBJDIR}/src/fsint/afsint.cs.c
	${CCRULE} ${TOP_OBJDIR}/src/fsint/afsint.cs.c

afsint.xdr.o: ${TOP_OBJDIR}/src/fsint/afsint.xdr.c
	${CCRULE} ${TOP_OBJDIR}/src/fsint/afsint.xdr.c

afscbint.cs.o: ${TOP_OBJDIR}/src/fsint/afscbint.cs.c
	${CCRULE} ${TOP_OBJDIR}/src/fsint/afscbint.cs.c

afscbint.xdr.o: ${TOP_OBJDIR}/src/fsint/afscbint.xdr.c
	${CCRULE} ${TOP_OBJDIR}/src/fsint/afscbint.xdr.c

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

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

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

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

dest: ${DEST}/lib/libafsrpc.a

