#	from: @(#)Makefile	5.6 (Berkeley) 9/27/90
#	$Id: Makefile,v 1.25 2009/12/14 18:09:47 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   

CFLAGS+= -U_ANSI_SOURCE 
CFLAGS+=  -I${RDISTSRC}/include -I${RDISTSRC}/config -I${RDISTSRC}/src

.include "../Makefile.inc"

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

ldadd:= ${LDADD}
LDADD=

.if ${host_os} == "freebsd"
os_h:=os-${host_targ}.h
.if !exists(${RDISTSRC}/config/${os_h})
# even for FreeBSD, os-netbsd1.h works better
os_h=os-netbsd1.h
.endif
CFLAGS+= -DOS_H=\"${os_h}\"
LDADD+= -L/usr/lib -lcompat
.elif ${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" || ${host_os} == "freebsd"
# FreeBSD has regex in libcompat but it also has regerror
# mutiply defined :-(
SRCS+= regex.c
.endif
LDADD+= ${ldadd}

.include <prog.mk>

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

.if exists(/usr/lib/libutil.a)
LDADD+= -lutil
.endif

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