# Be sure to check the file include/socks.h also and make
# modifications as necessary.

SHELL=/bin/sh

#SOCKS=-DSOCKS
# or
SOCKS=-Dconnect=Rconnect -Dgetsockname=Rgetsockname -Dlisten=Rlisten -Daccept=Raccept -Drcmd=Rrcmd -Dbind=Rbind -Dselect=Rselect
# If the second definition of SOCKS is used, you MUST also
# define SHORTENED_RBIND

# Define SHORTENED_RBIND to make Rbind() take exactly the same
# argument list as the regular bind(), i.e., without the additional
# 'remhost' argument.
SHORTENED_RBIND=-DSHORTENED_RBIND

# If your system doesn't have PWD defined, define it here:
#PWD=/projects/insg/socks.cstc.4.2.1
# It should be this current directory.

# If your system has getcwd() but no getwd(), uncomment the next line:
#GETCWD=-DGETCWD

#If your system doesn't have waitpid(), uncomment the nextline:
#NO_WAITPID=-DNO_WAITPID

# Define TRY_PASV if you want ftp (rftp) to try initiating the
# connection to the ftp server for the data channel first. If
# that fails, it will then use the usually method of letting
# the ftp server make the connection.
TRY_PASV=-DTRY_PASV
#
# Normally for ftp (rftp) to work, you have allow incoming connections
# to your SOCKS server host (at least those coming from port 20). If
# you disallow that, then you must define TRY_PASV; otherwise you will
# be able to use ftp(rftp() to connect to an ftp server but 'ls', 'get',
# etc. will all fail.
# TRY_PASV will not gain you anything unless you allow connections to
# ports with number >= 1024.

# Define FASCIST if you want ftp (rftp) to log names of all files transferred
#FASCIST=-DFASCIST

# Define RCMD and SUPPORT_RCMD if you want to support Rrcmd, which is required
# for SOCKSified rlogin, rsh, and rcp.
#RCMD=Rrcmd.o
#SUPPORT_RCMD=-DSUPPORT_RCMD

# Define FOR_PS if your system is not SYSV and you want to have the
# command 'ps' show some details of sockd's activity.
#FOR_PS=-DFOR_PS

# optimization flag for cc
OPTIMIZE=-g
#OPTIMIZE=-O
# Be careful with the OPTIMIZE flag. SunPro's SC2.0.1, for example, is
# knwon to produce incorrect code when -O is used.

# Define NO_CLIENT_LOG if you don't want SOCKS clients to produce
# log entries of its activities.
#NO_CLIENT_LOG= -Dopenlog=socks_0openlog -Dsyslog=socks_0syslog -Dcloselog=socks_0closelog

# Define DNS_THROUGH_NIS if your SOCKS client hosts let their NIS
# servers do the DNS loopkup for them. You are in this category if
# your client hosts has no /etc/resolv.conf but can resolve all
# internal and external names.
#DNS_THROUGH_NIS=-DDNS_THROUGH_NIS

# If you get 'herror undefined', 'h_errno undefined', 'herror redefined'
# or 'h_errno redefined' error message,
# this is the macro to change. Define it or undefine it, whichever
# works. The reasons are too messy to explain.
#BIND_RESOLVER=-DBIND_RESOLVER

# Directory into which to install the man pages
MAN_DEST_DIR = /usr/local/man

# Directory into which the SOCKS server should be installed
SERVER_BIN_DIR = /usr/etc

# Directory into the client programs should be installed
CLIENTS_BIN_DIR = /usr/local/bin

# SunOS 4.1.x should use
#CC=cc
#CC=gcc
#OTHER_CFLAGS= $(GETCWD) $(FASCIST) $(SHORTENED_RBIND) -DCOMPAT $(DEBUG) $(TRY_PASV)
#RANLIB=ranlib
#OS=sun4.1
#INSTALL=install
#GETPASS=getpass.o
#RESOLV_LIB=-lresolv
# ... or 
#RESOLV_LIB=

# IRIX 4 should use
#CC=cc
#RESOLV_LIB=-lsun
#OTHER_CFLAGS=-cckr $(GETCWD) $(FASCIST) $(SHORTENED_RBIND) -DCOMPAT $(TRY_PASV) -DSYSTYPE_SVR4
#RANLIB=/bin/true
#OS=irix4
#INSTALL=bsdinstall
#GETPASS=getpass.o

# IRIX 5 should use
CC=cc
RESOLV_LIB=-lsun
OTHER_CFLAGS=-cckr $(GETCWD) $(FASCIST) $(SHORTENED_RBIND) -DCOMPAT -DSVR3 -DNCARGS=`sysconf ARG_MAX` -D_BSD_SIGNALS $(TRY_PASV)
RANLIB=/bin/true
OS=irix5
INSTALL=bsdinstall
GETPASS=getpass.o

# Ultrix 4.0 should use
#CC=cc
#OTHER_CFLAGS= $(GETCWD) $(SHORTENED_RBIND) $(FASCIST) $(TRY_PASV)
#RANLIB=ranlib
#OS=ultrix4.0
#INSTALL=install
#GETPASS=getpass.o
#RESOLV_LIB=-lresolv
# Ultrix 4.3 should use the one below instead
#RESOLV_LIB=
# Ultrix 4.4 should use the one below instead
#RESOLV_LIB=-lresolv -l44bsd

# HP-UX should use
#CC=cc
#OTHER_CFLAGS= $(GETCWD) $(FASCIST) $(SHORTENED_RBIND) -DCOMPAT $(TRY_PASV)
#RANLIB=/bin/true
#OS=hpux9
#INSTALL=install
#GETPASS=
#RESOLV_LIB=
# HPUX does not allow 'nobody' to be used as the user in /etc/inetd.conf,
# unless it has a gid between 0 and 60000, which it normally doe not. So
# you either have to use a different user in /etc/inetd.conf or change
# the gid of 'nobody'.

# RS/6000 AIX 3.2 should use
#CC=cc
#RESOLV_LIB=-lbsd
#OTHER_CFLAGS=-D_BSD -D_NONSTD_TYPES -D_NO_PROTO -DAIX $(GETCWD) $(FASCIST) $(SHORTENED_RBIND) -DCOMPAT $(TRY_PASV)
#RANLIB=ranlib
#OS=aix3.2
#INSTALL=bsdinstall
#GETPASS=

# PS/2 AIX 1.2 should use
#CC=cc
#RESOLV_LIB=-lbsd
#OTHER_CFLAGS=-D_BSD -D_NONSTD_TYPES -D_NO_PROTO -DAIX $(GETCWD) $(FASCIST) -DCOMPAT -I/usr/local/include -DAIX_PS2 $(TRY_PASV)
#RANLIB=ranlib
#OS=aix_ps2
#INSTALL=install
#GETPASS=

# SOLARIS should use
#CC=cc
#RESOLV_LIB=-lresolv -lnsl -lsocket
#OTHER_CFLAGS=-DSOLARIS -Dindex=strchr -Drindex=strrchr $(SHORTENED_RBIND) -DUSE_DIRENT $(GETCWD) $(FASCIST) -DCOMPAT $(TRY_PASV)
#RANLIB=/bin/true
#OS=solaris2.2
#INSTALL=install
#GETPASS=getpass.o

# Interactive Systems Unix should use
#OTHER_CFLAGS = -DISC -DSVR3 -Dindex=strchr -Drindex=strrchr -D_XOPEN_SOURCE -DGETCWD $(FASCIST) $(SHORTENED_RBIND) -DCOMPAT $(TRY_PASV)
#CC=cc
#RANLIB=:
#OS=isc
#INSTALL=$(PWD)/bsdinstall
#GETPASS=
#RESOLV_LIB=-linet -lc_s

# netBSD should use
#OTHER_CFLAGS = $(GETCWD) $(SHORTENED_RBIND) $(FASCIST) $(TRY_PASV)
#CC=cc
#RANLIB=ranlib
#OS=netbsd0.9
#INSTALL=install
#GETPASS=
#RESOLV_LIB=

# FreeBSD should use:
#CC=cc
#OS=freebsd1.1
#RESOLV_LIB=
#OTHER_CFLAGS= $(GETCWD) $(SHORTENED_RBIND) $(FASCIST) $(TRY_PASV)
#RANLIB=ranlib
#GETPASS=
#INSTALL=install

# LINUX should use
#CC=gcc
#RANLIB=ranlib
#RESOLV_LIB=
# NOTE: Older versions of Linux may need to define the following variable,
#       as their <sys/socket.h> files do not define "struct linger".
#NEED_STRUCT_LINGER = -DNEED_STRUCT_LINGER
#OTHER_CFLAGS=-traditional -DLINUX  $(GETCWD) $(FASCIST) $(SHORTENED_RBIND) -DCOMPAT $(NEED_STRUCT_LINGER) -DCONST="" $(TRY_PASV)
#OS=linux
#INSTALL=install
#GETPASS=getpass.o
# Additional notes for Linux:
# 1) There is a bug in getsockname() which returns address 127.0.0.1 when
#    the result should be 0.0.0.0. Because of this, the non multi-homed
#    version of sockd doesn't work. The multi-homed version works fine
#    and can be used even on a single-homed Linux box. Just set up the
#    /etc/sockd.route file to direct all traffic through the one and only
#    interface.
# 2) Linux doesn't define user 'nobody' in its distribution. To run sockd on
#    linux, you must either add 'nobody' (give it minimum privileges) or
#    run it under an existing userid (i.e., replace 'nobody' in the
#    /etc/inetd.conf entry by an existing userid).

# UnixWare should use
#CC=cc
#RESOLV_LIB=-lresolv -lnsl -lsocket
#OTHER_CFLAGS= -DSOLARIS -Dindex=strchr -Drindex=strrchr -DUSE_DIRENT $(SHORTENED_RBIND) $(GETCWD) $(FASCIST) -DCOMPAT $(TRY_PASV)
#RANLIB=/bin/true
#INSTALL=/usr/ucb/install
#OS=UnixWare
#GETPASS=getpass.o

# Alpha OSF should use:
#CC=cc
#RESOLV_LIB=-lresolv
#OS=alphaOSF
#OTHER_CFLAGS= $(GETCWD) $(FASCIST) $(SHORTENED_RBIND) -DCOMPAT $(TRY_PASV)
#RANLIB=ranlib
#INSTALL=install
#GETPASS=

# SCO UNIX/ODT should use:
#CC=cc
#OS=sco
#RESOLV_LIB=-lsocket
#OTHER_CFLAGS= $(GETCWD) $(FASCIST) -DSCO -DSVR3 -Dindex=strchr -Drindex=strrchr $(SHORTENED_RBIND) -DUSE_DIRENT $(TRY_PASV)
#RANLIB=/bin/true
#GETPASS=
#You MUST define PWD; see explanation earlier in this file.
# >>> Thomas Essebier <tom@stallion.oz.au>
#SERVER_BIN_DIR = /etc
# sco install does not work like 'other' installs.
# assuming all calls to install here are: install -m xxx file dir
# sco uses the convention: install -c dir -m xxx file
# create scoinstall in a directory in the normal path (eg. /usr/local/bin)
# its a 1 line script to munge the parameters to fit SCO's conventions
# -> install -c $4 $1 $2 $3
#INSTALL=scoinstall
# <<< Thomas Essebier <tom@stallion.oz.au>


# BSD/386 should use:
#CC=cc
#OS=bsdi
#RESOLV_LIB=
#OTHER_CFLAGS= $(GETCWD) $(SHORTENED_RBIND) $(FASCIST) $(TRY_PASV)
#RANLIB=ranlib
#GETPASS=
# BSDI forgot to put appropriate lines in their /usr/include/netinet/in.h
# to prevent the code from being processed multiple times. This causes
# compiler to complain. You have to fix their oversight by adding
#	#ifndef _netinet_in_h
#	#define _netinet_in_h
# at the beginning of the file, and adding
#	#endif
# at the end of the file.


# NextStep 3.2, SOCKS server and library only
# (William Lewis, wiml@omnigroup.com)
#CC=cc
#OTHER_CFLAGS= $(GETCWD) $(FASCIST) $(SHORTENED_RBIND) -DCOMPAT $(DEBUG) -Dstrdup=NXCopyStringBuffer $(TRY_PASV)
#RANLIB=ranlib
#GETPASS=getpass.o
#RESOLV_LIB=-lresolv
# ... or 
#RESOLV_LIB=

# DG/UX 5.4 should use
#CC=cc
#RESOLV_LIB=
#OTHER_CFLAGS=-DDGUX $(SHORTENED_RBIND) -DUSE_DIRENT $(GETCWD) $(FASCIST) -DCOMPAT $(TRY_PASV)
#RANLIB=/bin/true
#OS=dgux5.4
#INSTALL=bsdinstall
#GETPASS=
  
# NewsOS 4.x should use
#CC=gcc
#OTHER_CFLAGS= $(GETCWD) $(FASCIST) $(SHORTENED_RBIND) -DCOMPAT $(DEBUG) $(TRY_PASV)
#RANLIB=ranlib
#OS=newsos4
#INSTALL=install
#GETPASS=getpass.o
#RESOLV_LIB=-lresolv -l44bsd
# !!! Remember to define NO_WAITPID !!!

# >>>---------------- Others:

# Define RESOLV_LIB if your system doesn't search resolver
# library automatically.
# Leave it undefined otherwise.
#RESOLV_LIB=-lresolv
# If your compiler or loader complains about _res_init being
# an undefined symbol, then you must define RESOLV_LIB.

#RANLIB=ranlib
# Systems (e.g., IRIX) that do not need (and thus don't have) ranlib should use
#RANLIB=/bin/true

# Comment out defintion of GETPASS if your system has problems
# compiling it, the version built into your system will then be used.
# The getpass() function in most Unix systems truncates passwords
# after 8 characters; the version provided here does not.
# This only affects ftp with non-anonymous login, and telnet.
# Ftp with anonymous login allows long passwords regardless
# of whether GETPASS is defined or not.
#GETPASS=getpass.o

# The 'install' command is assumed to be the BSD variety (using -m to
# set the file mode). If the default 'install' on your system doesn't
# do that, you have to either specify an alternative one in the line below
# (e.g., /usr/ucb/install) or modify the other Makefile.
#INSTALL= install

# Macro OS is used in making rtelnet. See the list near top of
# rtelnet/telnet/Makefile for available choices.

# Remember to include -Dindex=strchr -Drindex=strrchr in OTHER_CFLAGS if
# you don't have index() and rindex() (Sys-V camp)

# <<<----------------

# The Internet Whois server; used to be nic.ddn.mil.
WHOIS_SERVER= WHOIS_SERVER=-DWHOIS_SERVER\'=\"rs.internic.net\"\'

SOCKS_LIB=$(PWD)/lib/libsocks.a
IDENT_LIB=$(PWD)/libident/libident.a

#==============================================================================

all: LIB LIBIDENT server clients

server: LIB LIBIDENT
	(cd sockd; $(MAKE) CC="$(CC)" RESOLV_LIB="$(RESOLV_LIB)" \
		OPTIMIZE="$(OPTIMIZE)" \
		SOCKS_LIB="$(SOCKS_LIB)" SUPPORT_RCMD="$(SUPPORT_RCMD)" \
		IDENT_LIB="$(IDENT_LIB)" \
		OTHER_CFLAGS="$(OTHER_CFLAGS) $(FOR_PS) $(NO_WAITPID)")

clients: RFINGER RFTP RTELNET

LIB:
	(cd lib; $(MAKE) CC="$(CC)" GETPASS="$(GETPASS)" \
		OPTIMIZE="$(OPTIMIZE)" \
		RCMD="$(RCMD)" SUPPORT_RCMD="$(SUPPORT_RCMD)" \
		DNS_THROUGH_NIS="$(DNS_THROUGH_NIS)" \
		OTHER_CFLAGS="$(OTHER_CFLAGS) $(NO_CLIENT_LOG) $(BIND_RESOLVER) $(NO_WAITPID)" \
		RANLIB="$(RANLIB)")

LIBIDENT:
	(cd libident; $(MAKE) CC="$(CC)" OTHER_CFLAGS="$(OTHER_CFLAGS)" \
		OPTIMIZE="$(OPTIMIZE)" RANLIB="$(RANLIB)")

# This also build rwhois
RFINGER: LIB
	(cd rfinger; $(MAKE) CC="$(CC)" $(WHOIS_SERVER) \
		OPTIMIZE="$(OPTIMIZE)" SOCKS="$(SOCKS)" \
		RESOLV_LIB="$(RESOLV_LIB)" SOCKS_LIB="$(SOCKS_LIB)" \
		OTHER_CFLAGS="$(OTHER_CFLAGS) $(NO_CLIENT_LOG) $(NO_WAITPID)")

RTELNET: LIB
	(cd rtelnet; $(MAKE) CC="$(CC)" OS="$(OS)" SOCKS_LIB="$(SOCKS_LIB)" \
		OPTIMIZE="$(OPTIMIZE)" SOCKS="$(SOCKS)" \
		RESOLV_LIB="$(RESOLV_LIB)" \
		OTHER_CFLAGS="$(OTHER_CFLAGS) $(NO_CLIENT_LOG) $(NO_WAITPID)")

RFTP: LIB
	(cd rftp; $(MAKE) CC="$(CC)" SOCKS_LIB="$(SOCKS_LIB)" \
		OPTIMIZE="$(OPTIMIZE)" SOCKS="$(SOCKS)" \
		RESOLV_LIB="$(RESOLV_LIB)" \
		OTHER_CFLAGS="$(OTHER_CFLAGS) $(NO_CLIENT_LOG) $(BIND_RESOLVER) $(NO_WAITPID)")

install.server:
	(cd sockd; $(MAKE) INSTALL="$(INSTALL)" MAN_DEST_DIR="$(MAN_DEST_DIR)" \
		CC="$(CC)" RESOLV_LIB="$(RESOLV_LIB)" \
		OPTIMIZE="$(OPTIMIZE)" \
		SOCKS_LIB="$(SOCKS_LIB)" SUPPORT_RCMD="$(SUPPORT_RCMD)" \
		IDENT_LIB="$(IDENT_LIB)" \
		OTHER_CFLAGS="$(OTHER_CFLAGS) $(FOR_PS)" \
		SERVER_BIN_DIR="$(SERVER_BIN_DIR)" install install.man)

install.clients: install.man
	for i in rfinger rftp rtelnet; do \
		(cd $$i ; $(MAKE) INSTALL="$(INSTALL)" \
			CC="$(CC)" OS="$(OS)" SOCKS_LIB="$(SOCKS_LIB)" \
			OPTIMIZE="$(OPTIMIZE)" SOCKS="$(SOCKS)" \
			RCMD="$(RCMD)" SUPPORT_RCMD="$(SUPPORT_RCMD)" \
			DNS_THROUGH_NIS="$(DNS_THROUGH_NIS)" \
			RESOLV_LIB="$(RESOLV_LIB)" \
			OTHER_CFLAGS="$(OTHER_CFLAGS) $(NO_CLIENT_LOG)" \
			CLIENTS_BIN_DIR="$(CLIENTS_BIN_DIR)" \
			install) done
install.man:
	(cd doc; $(MAKE) INSTALL="$(INSTALL)" MAN_DEST_DIR="$(MAN_DEST_DIR)" \
		install)

clean:
	for i in lib libident sockd rfinger rftp rtelnet ; do \
		( cd $$i ; $(MAKE) clean) done


