# RCSid:
#	$Id: Makefile,v 1.43 2009/12/19 06:20:10 sjg Exp $
#
#	@(#) Copyright (c) 1994 Simon J. Gerraty
#
#	This file is provided in the hope that it will
#	be of use.  There is absolutely NO WARRANTY.
#	Permission to copy, redistribute or otherwise
#	use this file is hereby granted provided that 
#	the above copyright notice and this notice are
#	left intact. 
#      
#	Please send copies of changes and bug-fixes to:
#	sjg@crufty.net
#

LIB = sslfd

SRCS = \
	copy.c \
	crl.c \
	dh.c \
	hash.c \
	logfacs.c \
	netfgetln.c \
	netio.c \
	netiob.c \
	netrw.c \
	rcvnet.c \
	rwhook.c  \
	rwnet.c \
	sig.c \
	ssl.c \
	sslc.c \
	ssld.c \
	sslrcmd.c \
	utcsecscmp.c

#.if exists(${.CURDIR}/../../../fwtk/lib/fwtk)
#.PATH: ${.CURDIR}/../../../fwtk/lib/fwtk
#SRCS+= usessl.c
#.endif

#.if exists(/usr/local/include/socks.h)
#SRCS+= socks.c
#CFLAGS+= -DSOCKS
#.endif

USE_SSL=yes

MAN=${.CURDIR}/sslfd.3 ${.CURDIR}/ssl.3 ${.CURDIR}/ssld.3 \
	${.CURDIR}/sslc.3 ${.CURDIR}/ssl_rcmd.3
MLINKS=  sslfd.3 ssl_setopt.3

SRC_LIBS += ${LIBCRYPTO}

# we need these bits out of libsjg
SRC_LIBS += ${LIBSJG}
SRC_PATHADD+= ${SRC_libsjg}
# this will allow our clients to find the libsjg headers here
SYMLINKS += ${SRC_libsjg}/h/sjg sjg

SRCS += \
	misc/s2av.c \
	tcp/domaincmp.c \
	tcp/getipaddr.c \
	tcp/globals.c \
	tcp/hname.c \
	tcp/ipcallid.c \
	tcp/proxy_connect.c \
	tcp/sockdest.c \
	tcp/tcpopen.c

SRC_LIBS += ${LIBCOMPAT}
SRC_PATHADD += ${SRC_libcompat}
SYMLINKS += ${SRC_libcompat}/h/err.h err.h
SRCS += \
	err.c \
	fgetln.c \
	snprintf.c

W_implicit=

.include <lib.mk>

header_links: _BUILD_SYMLINKS_USE
err.o err.so ssl.o ssl.so: header_links

CFLAGS+= -DUSE_SSL -DUSE_SSLFD -I${SSLTOP}/include

.if ${host_os} == "darwin"
CFLAGS += -DNEED_NETIOB
.endif
.if exists(/usr/include/libio.h) && ${MACHINE} == "linux"
CFLAGS += -DNEED_NETIOB
.endif

.if !exists(/usr/include/sys/syscall.h)
CFLAGS+= -DNO_SYSCALL
SYSOBJS=close_.o read_.o write_.o

io.h:	bsed mkio.sh stdio.awk
	${.CURDIR}/mkio.sh 2> io.h
	${.CURDIR}/stdio.awk >> io.h

OBJS+= ${SYSOBJS}


bsed:	bsed.c
	${CC} -g -o bsed ${.CURDIR}/bsed.c

CFLAGS+= -DHAVE_IO_H

rwnet.o:	io.h
.endif


stio.h:	stdio.awk
	CC="${CC}" sh ${.CURDIR}/stdio.awk > stio.h

netrw.o netrw.so netiob.o netiob.so netrw.o netrw.so: stio.h

CFLAGS+= -DHOSTCERT_SLACK
CFLAGS+= -DX509_USER_FIELD=\"/SN=\" 
# Here are some useful settings for SSL_CIPHER_LIST
# this one allows 128 and above only
#CFLAGS+= -DSSL_CIPHER_LIST=\"!EXP:!ADH:HIGH:MEDIUM\"
# this one allows DES(56)
#CFLAGS+= -DSSL_CIPHER_LIST=\"!EXP:!ADH:HIGH:MEDIUM:LOW\"
# this one allows Anon-DH bad idea usually
#CFLAGS+= -DSSL_CIPHER_LIST=\"!EXP:HIGH:MEDIUM:LOW:ADH+3DES:ADH+RC4:ADH+DES\"
