#	from: @(#)Makefile	5.6 (Berkeley) 9/27/90
#	$Id: Makefile,v 1.15 1997/03/11 20:41:54 sjg Exp $

PROG=	SSLrdist
NOMAN=no

SRCS= gram.y rdist.c client.c child.c docmd.c  distopt.c expand.c \
	lookup.c  isexec.c signal.c rshrcmd.c  common.c message.c setargs.c   

RDISTSRC?=${.CURDIR}/src
.PATH:	${RDISTSRC}/src

CFLAGS+= -U_ANSI_SOURCE 
CFLAGS+=  -I${RDISTSRC}/include -I${RDISTSRC}/config
.if ${MACHINE} == "i386" || ${MACHINE} == "sparc"
CFLAGS+= -DOS_H=\"os-netbsd1.h\"
LDADD+= -L/usr/lib -lcompat
.elif ${MACHINE} == "sun386"
CFLAGS+= -DOS_H=\"os-sunos4.h\"
.else
CFLAGS+= -DOS_H=\"os-`${RDISTSRC}/config/os-type`.h\"
.endif
.if ${MACHINE} == "hp-ux"
SRCS+= regex.c
.endif

.include "prog.mk"

BINDIR=/usr/local/bin
CFLAGS+= -D_PATH_RDISTD=\"${BINDIR}/rdistd\" -Dread=read_net -Dwrite=write_net

.if !exists(${.CURDIR}/rdist.c)
rdist.o:	${.CURDIR}/rdist.c
rshrcmd.o:	${.CURDIR}/rshrcmd.c
${.CURDIR}/rdist.c:	${RDISTSRC}/src/rdist.c 
	cd ${RDISTSRC}/src; cp rdist.c rshrcmd.c ${.CURDIR}
	cd ${.CURDIR} && patch < ${.CURDIR}/rdist.patch
.endif

test:
	@mkdir -p /tmp/source /tmp/dest
	@cp ${.CURDIR}/distfile /tmp/source
	@rm -f /tmp/dest/distfile
	./SSLrdist -p ${.CURDIR}/../rdistd/${.OBJDIR:T}/rdistd -f ${.CURDIR}/distfile test
	@cmp /tmp/source/distfile /tmp/dest/distfile
