# 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

LIBOBJS=disk.o  remote.o beacon.o recovery.o ubik.o  vote.o lock.o phys.o \
	ubik_int.cs.o ubik_int.ss.o ubik_int.xdr.o ubikcmd.o \
	ubikclient.o uerrors.o uinit.o

INCLS=${TOP_INCDIR}/lwp.h ${TOP_INCDIR}/lock.h \
	${TOP_INCDIR}/rx/rx.h ${TOP_INCDIR}/rx/xdr.h \
	${TOP_INCDIR}/lock.h ubik.h ubik_int.h

LIBS=${TOP_LIBDIR}/librx.a ${TOP_LIBDIR}/liblwp.a \
     ${TOP_LIBDIR}/libcom_err.a ${TOP_LIBDIR}/libcmd.a \
     ${TOP_LIBDIR}/util.a ${TOP_LIBDIR}/libsys.a ${XLIBS}

all: depinstall ${TOP_LIBDIR}/libubik.a udebug utst_server utst_client

depinstall: \
	ubik_int.cs.c ubik_int.xdr.c \
	${TOP_INCDIR}/ubik.h \
	${TOP_INCDIR}/ubik_int.h

utst_server: utst_server.o utst_int.ss.o utst_int.xdr.o libubik.a 
	${CC} ${CFLAGS} -o utst_server utst_server.o utst_int.ss.o utst_int.xdr.o libubik.a $(LIBS)

utst_client: utst_client.o utst_int.cs.o utst_int.xdr.o libubik.a 
	${CC} ${CFLAGS} -o utst_client utst_client.o utst_int.cs.o utst_int.xdr.o libubik.a $(LIBS)

udebug: udebug.o libubik.a 
	${CC} ${CFLAGS} -o udebug udebug.o libubik.a $(LIBS)

ubik_int.cs.c: ubik_int.xg
	${RXGEN} -x -A -C -o $@ ${srcdir}/ubik_int.xg

ubik_int.ss.c: ubik_int.xg
	${RXGEN} -x -A -S -o $@ ${srcdir}/ubik_int.xg

ubik_int.xdr.c: ubik_int.xg
	${RXGEN} -x -A -c -o $@ ${srcdir}/ubik_int.xg

ubik_int.h: ubik_int.xg
	${RXGEN} -x -A -h -o $@ ${srcdir}/ubik_int.xg

ubik_int.cs.c: ubik_int.h
ubik_int.ss.c: ubik_int.h
ubik_int.xdr.c: ubik_int.h

Kubik_int.cs.c: ubik_int.xg Kubik_int.h
	${RXGEN} -x -k -A -C -o Kubik_int.cs.c ${srcdir}/ubik_int.xg
 
Kubik_int.xdr.c: ubik_int.xg
	${RXGEN} -x -k -A -c -o Kubik_int.xdr.c ${srcdir}/ubik_int.xg
 
Kubik_int.h: ubik_int.xg
	${RXGEN} -x -k -A -h -o Kubik_int.h ${srcdir}/ubik_int.xg

utst_int.ss.o: utst_int.ss.c utst_int.xdr.c
utst_int.cs.o: utst_int.cs.c utst_int.xdr.c
utst_int.xdr.o: utst_int.xdr.c utst_int.h

utst_int.cs.c: utst_int.xg
	${RXGEN} -A -C -o $@ ${srcdir}/utst_int.xg

utst_int.ss.c: utst_int.xg
	${RXGEN} -A -S -o $@ ${srcdir}/utst_int.xg

utst_int.xdr.c: utst_int.xg
	${RXGEN} -A -c -o $@ ${srcdir}/utst_int.xg

utst_int.h: utst_int.xg
	${RXGEN} -A -h -o $@ ${srcdir}/utst_int.xg

utst_int.cs.c: utst_int.h
utst_int.ss.c: utst_int.h
utst_int.xdr.c: utst_int.h

utst_server.o: utst_server.c ${INCLS} utst_int.h AFS_component_version_number.c
utst_client.o: utst_client.c ${INCLS} utst_int.h AFS_component_version_number.c

udebug.o: udebug.c ${INCLS} AFS_component_version_number.c
	${CC} ${CFLAGS} -I. -I${TOP_INCDIR} -I${TOP_INCDIR}/afs -c ${srcdir}/udebug.c

uerrors.o: uerrors.c

uerrors.c ubik.h: uerrors.et ubik.p.h
	$(RM) -f ubik.h uerrors.c
	${COMPILE_ET} -p ${srcdir} uerrors -h ubik

libubik.a: ${LIBOBJS} AFS_component_version_number.o
	-$(RM) -f $@
	$(AR) crc $@ ${LIBOBJS} AFS_component_version_number.o
	$(RANLIB) $@

disk.o: disk.c ${INCLS}
uinit.o: uinit.c ${INCLS}
remote.o: remote.c ${INCLS}
beacon.o: beacon.c ${INCLS}
lock.o: lock.c ${INCLS}
recovery.o: recovery.c ${INCLS}
ubik.o: ubik.c ${INCLS}
phys.o: phys.c ${INCLS}
vote.o: vote.c ${INCLS}
ubikcmd.o: ubikcmd.c ${INCLS}
ubikclient.o: ubikclient.c ${INCLS}
ubik_int.ss.o: ubik_int.ss.c ${INCLS}
ubik_int.cs.o: ubik_int.cs.c ${INCLS}
ubik_int.xdr.o: ubik_int.xdr.c ${INCLS}
utst_int.ss.o: utst_int.ss.c ${INCLS} utst_int.h
utst_int.cs.o: utst_int.cs.c ${INCLS} utst_int.h
utst_int.xdr.o: utst_int.xdr.c ${INCLS} utst_int.h 

#
# Installation targets
#
test: all

install: \
	${DESTDIR}${libdir}/libubik.a \
	${DESTDIR}${includedir}/ubik.h \
	${DESTDIR}${includedir}/ubik_int.h \
	${DESTDIR}${bindir}/udebug \
	${DESTDIR}${afssrvbindir}/udebug

${DEST}/bin/udebug ${DEST}/root.server/usr/afs/bin/udebug: udebug
	${INSTALL} $? $@

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

${DEST}/include/ubik.h: ubik.h
	${INSTALL} $? $@

${DEST}/include/ubik_int.h: ubik_int.h
	${INSTALL} $? $@

#
# Misc. targets
#
clean:
	$(RM) -f *.o utst_server utst_client udebug *.a *.cs.c *.ss.c *.xdr.c
	$(RM) -f utst_int.h ubik_int.h uerrors.c ubik.h core AFS_component_version_number.c Kubik_int.h

include ../config/Makefile.version


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

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

${DESTDIR}${includedir}/ubik.h: ubik.h
	${INSTALL} $? $@

${TOP_INCDIR}/ubik.h: ubik.h
	${INSTALL} $? $@

${DESTDIR}${includedir}/ubik_int.h: ubik_int.h
	${INSTALL} $? $@

${TOP_INCDIR}/ubik_int.h: ubik_int.h
	${INSTALL} $? $@

${DESTDIR}${bindir}/udebug: udebug
	${INSTALL} $? $@

${DESTDIR}${afssrvbindir}/udebug: udebug
	${INSTALL} $? $@

dest: \
	${DEST}/lib/libubik.a \
	${DEST}/include/ubik.h \
	${DEST}/include/ubik_int.h \
	${DEST}/bin/udebug \
	${DEST}/root.server/usr/afs/bin/udebug

