# IRC II - written by Michael Sandrof
# Copyright (c) 1991 - All Rights Reserved
# Modified by Matthew Green, 1993.

# targets recognised by this makefile:
#   all			- compiles ircII
#   ircserv		- compiles ircserv
#   wserv		- compiles wserv.
#   ircflush		- compiles ircflush
#   install		- installs ircII in the bindir.
#   installserv		- installs ircserv in the bindir.
#   installwserv	- installs wserv in the bindir.
#   installflush	- installs ircflush in the bindir.
#   installscript 	- installs the scripts to the correct dir.
#   installtranslation	- installs the translation tables to the correct dir.
#   everything		- compiles everything
#   installeverything   - all of the above.

prefix = /usr/tools/irc/2.2.9
bindir = ${prefix}/bin

# Where the ircII binary will be installed.
# 'make install' will compile and install the program
INSTALL_EXECUTABLE = ${bindir}/ircII

# Where the ircII library will be.  Generally this is the place that
# you put the scripts, help pages and translation tables.  It is
# very important that you set this correctly.
IRCII_LIBRARY = ${prefix}/lib

# Set the next line to the full path for installation of the ircserv program
# if you wish to use it. 
INSTALL_IRCSERV = ${bindir}/ircserv

# This little program is necessary to have an interactive shell
# in a window of ircII. The 'shell' script uses it, so also update
# the path in there, if you want to enable this.
INSTALL_IRCFLUSH = ${bindir}/ircflush

# This program allows you to use screen/xterm's to put new irc windows
# on new screen/xterm windows.
INSTALL_WSERV = ${bindir}/wserv

# Uncomment the following if you want a secure IRC which binds to a
# privileged port. This feature is completely useless in the current
# IRC environment, but in the future some servers may use privileged
# port systems to verify users connecting to them. The value of
# PRIV_PORT determines the minimum port number to use.
# If you modify these (including uncommenting them) you will need to
# touch config.h
#
# If you are on a system where test-suid works, you can simply define
# PP_DEFS to be PRIV_PORT_ULC and irc will change effective UID back
# to a normal user immediately, and change to root when binding a port.
# This feature is undocumented, but is known to work on Sun, MIPS and
# Apollo (Cos we've tested them already).
# PP_DEFS = -DPRIV_PORT=667
# PP_OBJS = file.o
# PP_DEFS = -DPRIV_PORT_ULC

# Below are system specific setups.
# If your system is not included in the lines below, do some experimenting
# with the DEFINES and program code, then if you happen to make it work
# properly, mail about the changes you had to make, include system type
# and version, so it can be included into ircII distribution.

# Note that if you are using a machine with a segmented architecture you will
# need to compile in the large or huge memory model. This is not included
# in the flags below, so you'll need to check the manual entry for cc
# to find out and insert them below.

# Set this to the lex you want to use, and if they lex uses a library.
# linux will want LEXLIB set to nothing.

LEX = lex
LEXLIB = -ll

# This is the default setup that should work for BSD and similar systems.
# This means, SunOS (if there is a real resolver in libc), Ultrix, Linux,
# 386BSD (duh), OSF/1, Dynix (not Dynix/ptx).

#LIBS = -ltermcap
#CC = cc
#DEFINES = 

# For sunos systems, use without a real resolver in libc use this,
# else use the BSD ones.
LIBS = -ltermcap /usr/tools/socks/0/lib/libsocks.a -lresolv
CC = cc
DEFINES = -DSOCKS

# For Solaris 2 systems, use
# LIBS = -lsocket -lnsl -lelf -L/usr/ucblib -ltermcap -lucb
# CC = cc
# DEFINES = -DSVR4 -DSOLARIS

# For IBM RS6000 systems running AIX 3.1 or 3.2, the following will work
# LIBS = -lcurses
# CC = c89 -D_ALL_SOURCE
# DEFINES = -DPOSIX

# For IBM RTs running AIX 2.2.1, use the following:
# LIBS = -lcurses
# DEFINES = -D_RT -D_AUX_SOURCE -DBSD_INCLUDES

# For AIX/370 V1.0 use:
# LIBS = -lcurses
# DEFINES = -D_BSD -DAIX_370

# for HP/UX 9.0 systems..
# LIBS = -lcurses

# Use the following set up for HPUX 8.0 systems
# (I'm told that hpux 8.0 has a buggy libmalloc)
# LIBS = -lcurses # -lmalloc
# DEFINES = -DHPUX

# For HPUX 7.0 systems:
# LIBS = -lcurses -lBSD -lPW
# DEFINES = -DHPUX -DHPUX70

# For Apollo systems (10.2 and upwards) use the following with BSD defaults:
# DEFINES = -Asys,bsd4.3

# Use one of the following for mips systems:
# Choice 1, if your system has the wait3() call
# DEFINES = -systype bsd43
# Choice 2, if your system has the wait2() call
# DEFINES = -systype bsd43 -Duse_wait2
#
# Or, if you only have sysv installed, use one of the following:
# DEFINES = -DMIPS_SYSV
# DEFINES = -DMIPS_SYSV -Duse_wait2

# For SGI Irix systems:
# DEFINES = -I/usr/include/bsd
# Use the following for SGI Irix systems not running Yellow Pages
# LIBS = -lcurses -lPW -lbsd -lc
# Use the following for SGI Irix systems running Yellow Pages
# LIBS = -lsun -lcurses -lPW -lbsd -lc

# Use the following for MUNIX systems:
# LIBS = -lcurses -lresolv -lbsd -lc
# DEFINES = -DMUNIX -D_AUX_SOURCE -I/usr/include/bsd

# For the ISC22 system:
# DEFINES = -DISC22 -D_AUX_SOURCE

# For Tektronix XD88:
# DEFINES = -DXD88 -D_AUX_SOURCE
# LIBS = -ltermcap

# For Dell System V Release 4
# DEFINES= -DSVR4
# LIBS= -lsocket -lnsl -lxtermcap

# Use the following for sysV and termio systems:
# DEFINES = -D_AUX_SOURCE

# Use the following for Sequent PTX or POSIX Complient Machines:
# CC = cc
# DEFINES= -DDYNIXPTX -DPOSIX
# LIBS= -lsocket -linet -lnsl -lseq -lcurses

# Use the following for SCO Unix 3.2v4.0 and ODT/2.0
# CC = cc -quiet
# DEFINES = -DSCO -D_AUX_SOURCE
# LIBS = -lsocket -ltermcap

# Use the following for NeXT, running NeXTstep 3.0.
# CC = cc
# LIBS = -ltermcap
# DEFINES = -DNeXT -D__STRICT_BSD__

# Use the following for Cray UNICOS systems.
# CC = cc
# LIBS = 
# DEFINES = -DUNICOS
## You probably don't need to change anything below this line

# Full path of the directory for ircII help files.  
# The help files are not within the source distribution, if you don't have
# them and want them, check out your nearest ircII archive.
# You may comment HELP_DIR, then the ircIIhelp service will be used.
# If you don't comment it out and want to use the IRCIIHelp service anyway,
# you must make sure that the directory doesn't exist.
HELP_DIR = ${IRCII_LIBRARY}/help

# Full path of the directory in which to copy the
# IRCII scripts supplied with the code.  These scripts
# may be loaded by using the LOAD command in IRCII.
INSTALL_SCRIPT = ${IRCII_LIBRARY}/script

# Default setting for IRC_PATH where irc will look for
# its script files if the environment variable is undefined.
# Usually, this should contain the same path as used for INSTALL_SCRIPT in
# the Makefile, but it can contain multiple path elements
# separated by colons. The path MUST lead to an existing directory,
# because the 'global' script is expected to be found there.
IRC_LOAD_PATH = .:~/.irc:${INSTALL_SCRIPT}

# Path for TRANSLATION variable.
TRANSLATION_PATH = ${IRCII_LIBRARY}/translation

# Set this to -g if you want to be able to debug the client, otherwise
# use -O to have the compiler do some optimization instead.
CFLAGS = -g

# Uncomment this if you want the binary to be striped.
# LDFLAGS = -s

## You shouldn't have to change anything below here

RM = rm -f
CP = cp
LN = ln -s
MV = mv -f
CHMOD = chmod 755

SHELL = /bin/sh

all: source/Makefile
	cd source; make
	
installeverything: install installflush installserv installwserv \
	installscript installtranslation

everything: all ircflush ircserv wserv

source/Makefile: source/Makefile.proto Makefile
	@${RM} source/Makefile
	sed -e 's;INSTALL_NAME_PROTO;${INSTALL_EXECUTABLE};'\
	    -e 's;LIBS_PROTO;${LIBS};'\
	    -e 's;CFLAGS_PROTO;${CFLAGS};'\
	    -e 's;LDFLAGS_PROTO;${LDFLAGS};'\
	    -e 's;RM_PROTO;${RM};'\
	    -e 's;CP_PROTO;${CP};'\
	    -e 's;LN_PROTO;${LN};'\
	    -e 's;CC_PROTO;${CC};'\
	    -e 's;MV_PROTO;${MV};'\
	    -e 's;LEX_PROTO;${LEX};'\
	    -e 's;LEXLIB_PROTO;${LEXLIB};'\
	    -e 's;DEFINES_PROTO;${DEFINES};'\
	    -e 's;IRCLIB_PROTO;${IRCII_LIBRARY};'\
	    -e 's;IRCPATH_PROTO;${IRC_LOAD_PATH};'\
	    -e 's;CHMOD_PROTO;${CHMOD};'\
	    -e 's;HELP_PROTO;${HELP_DIR};' \
	    -e 's;INSTALL_IRCSERV_PROTO;${INSTALL_IRCSERV};'\
	    -e 's;INSTALL_WSERV_PROTO;${INSTALL_WSERV};'\
	    -e 's;TRANSLATION_PROTO;${TRANSLATION_PATH};'\
	    -e 's;PP_DEFS_PROTO;${PP_DEFS};'\
	    -e 's;PP_OBJS_PROTO;${PP_OBJS};'\
	    -e 's;PPS_DEFS_PROTO;${PPS_DEFS};'\
	 	source/Makefile.proto > source/Makefile 

ircserv: source/Makefile
	cd source; make ircserv

ircflush: source/ircflush.c source/Makefile
	cd source; make ircflush

wserv: source/wserv.c source/term.c source/Makefile
	cd source; make wserv

install: all
	-${MV} ${INSTALL_EXECUTABLE} ${INSTALL_EXECUTABLE}.old
	${CP} source/irc ${INSTALL_EXECUTABLE}
	@${CHMOD} ${INSTALL_EXECUTABLE}

installscript:
	-mkdir ${INSTALL_SCRIPT}
	chmod -x script/*
	-cp ${INSTALL_SCRIPT}/local script
	cp script/* ${INSTALL_SCRIPT}
	chmod 644 ${INSTALL_SCRIPT}/*

installtranslation:
	-mkdir ${TRANSLATION_PATH}
	chmod -x translation/*
	cp translation/* ${TRANSLATION_PATH}
	chmod 644 ${TRANSLATION_PATH}/*

installserv: ircserv
	${CP} source/ircserv ${INSTALL_IRCSERV}
	@${CHMOD} ${INSTALL_IRCSERV}

installflush: ircflush
	${CP} source/ircflush ${INSTALL_IRCFLUSH}
	@${CHMOD} ${INSTALL_IRCFLUSH}

installwserv: wserv
	${CP} source/wserv ${INSTALL_WSERV}
	@${CHMOD} ${INSTALL_WSERV}

installhelp:
	@echo Help files are no more within this package.  You
	@echo can probably get them from the same place you got
	@echo this source from.

clena: clean
clean:
	@if [ -f source/Makefile ]; then cd source; make clean; fi

lint:
	@if [ -f source/Makefile ]; then cd source; make lint; fi

dist: clean
	mv config.h ..
	mv Makefile ..
	mv config.h.orig config.h
	mv Makefile.orig Makefile
	( PWD=`pwd`; VERSION_DIR=`basename ${PWD}`; cd ..; tar cf ${VERSION_DIR}.tar $VERSION_DIR; compress $VERSION_DIR.tar; )
	mv Makefile Makefile.orig
	mv ../Makefile .
	mv config.h config.h.orig
	mv ../config.h .
