# $Header: /home/vikas/src/xtacacsd/RCS/Makefile,v 4.4 1998/02/09 15:47:39 vikas Exp $
#
## USAGE:  'make'  or 'make OS=SVR3'
REV=	4.1.2
#
###
### User settable options
###
#	DEBUG 	if you want extensive debugging information
#	LOG_FACILITY set it to the syslog() logging facility that you want.
#		LOG_DAEMON or LOG_LOCAL6, etc. Do NOT escape the quotes
#		(like for UTMP, WTMP) since it is not a string.
#		For Ultrix 4.4, do NOT set to LOG_LOCAL6
#	UTMP	the name of the 'utmp' file that is checked for *current*
#		number of logins for a user.
#	WTMP	the name of your main 'wtmp' file and prefix for all
#		extended (wtmp.<hostname>) wtmp format files.
#	SHADOW_PW  on Solaris 2.x (and other ?) systems if you are using
#		shadow password files (instead of the regular password file.
#		AIX, BSDI use this by default, so dont define this on these
#		systems.
#	SIA	on DEC OSF1 systems using the Enhanced Security (TCB)
#		Will also need to set MYLIBS to  -lsecurity
#	OSFDCE	to use the DCE security registry for authentication. You
#		need to add the appropriate DCE libraries to MYLIBS if you
#		define this (-ldce). Earlier was -DDCE in xtacacsd.
#	PIDFILE	if you want the daemon to write its pid in this file.
#	USE_NDBM if you want to create a NDBM database of the password
#		file for retrieving passwords. Use Getpw for creating
#		the NDBM database. (On Linux, define this and add
#		-ldbm to the MYLIBS, since the dbm lib is actually ndbm).
#	USE_DBM	if you dont have the NDBM routines and have to use the
#		older DBM routines instead. Unless you have a very old
#		machine, you should not need this (Linux calls its library
#		-ldbm even though these are NDBM routines).
#	XTACUTMP if you want to use new utmp file format which has a
#		comment field in it also. MAKE SURE YOU MOVE OLDER wtmp/utmp
#		files over. To convert old format to new format, dump out
#		the old file using tacupd -a and then convert it back
#		using tacupd -r.
#	ASCII_WTMP if you want to use ASCII wtmp files ONLY and not create
#		binary wtmp files at all.
#	QI	if you want support for the CSO QI/PH nameserver (get the
#		software from ftp://ftp.cso.uiuc.edu). Also set the QI_LIBS
#		and the QI_FLAGS below.
#
##
CC= 	cc
MYCFLAGS= -g  -DDEBUG -DXTACUTMP -DUSE_NDBM \
	-DLOG_FACILITY="LOG_LOCAL6" \
	-DWTMP=\"/var/adm/tacacs/wtmp\" -DUTMP=\"/var/adm/tacacs/utmp\" \
	-DPIDFILE=\"/etc/xtacacsd.pid\" 
#
## If your libraries do not use the DNS resolver, add  -lresolv
# Might also need -lshadow or -lcrypt or -lsec or -lgen or -lsecurity
# For DCE authentication under Solaris 2.5/Transarc 1.1, add
#	-ldce -lsocket -lnsl -lthread -lm
# For DBM, might need -lndbm or -lgdbm. Check without anything first.
#
MYLIBS=

## Set INSTALL to /usr/ucb/install on AIX
MAKE=make
INSTALL=install
SHELL=/bin/sh

# Uncomment these to add ARAP support. Need the DES files (arap_des.[ch])
# from # ftp.cisco.com - see README for full details.
#ARAP_FLAGS= -DARAP_SUPPORT
#ARAP_OBJS=  arap_des.o

# Uncomment these to add CHAP support
# Add -DMD5_NEED_MEM_FUNCS if your system doesn't have memcpy() and memset()
CHAP_FLAGS= -DCHAP_SUPPORT
CHAP_OBJS=  xmd5.o

# Uncomment these for QI/PH (CSO) names database. Need to get and compile
# the qiapi library from ftp://ftp.cso.uiuc.edu. EDIT ph.c and set the
# definitions. Set the -I and -L values below.
#QI_FLAGS= -ILOCATION_OF_QI_qiapi.h_FILE
#QI_LIBS=  -lqiapi -Llocation_of_libqiapi_library

BINDIR= /etc
MANPROGS= xtacacsd taclast tacupd Getpw
MANEXT=	n
MANDIR=	/usr/man/man$(MANEXT)

###
###  End user customizable options
###
#####################################

## OS specific defines:
#
#	SYSV		if your system has funny ioctl(), no bcopy()
#	NOFSYNC		if you dont have the fsync() system call.
#	NEED_FD_MACROS  if you dont have FD_SET, etc. (look in your 'types.h')
#	NOGETDTABLE	if you are missing getdtablesize() system call
#	HAVEGIDTYPE	if you are running SysV and have gid_t set in 
#			/usr/include/sys/types.h. This is defined yet
#			broken on BSD machines.
#	NOINITGROUPS	If you dont have initgroups()
#	POSIX		If you dont have setlinebuf()
#	HAVESYSERR	If you already have sys_errlist[] defined
#
# Choose an appropriate value for "OS" from the ones below (this can be
# automatically detected if left blank):
#
#       IRIX40          Silicon Graphics IRIX 4.0
#       IRIX51          Silicon Graphics IRIX 5.1
#       SUNOS4          Sun Microsystems SunOS 4.x
#       SUNOS5          Sun Microsystems SunOS 5.x (Solaris 2.x)
#	SVR3		older SCO systems v3.x
#       SVR4            AT&T System V Release 4, DGUX 4.x
#       ULTRIX          Digital Equipment Ultrix 4.x
#       DECOSF1         Digital Equipment OSF/1 V1.3 and later
#       BSDI            BSDI/386 (uname shows BSD/OS) or FreeBSD 1.x
#	FREEBSD		FreeBSD 2.x/3.x
#	AIX		IBM AIX
#	AUX		Apple Unix 3.x
#	LINUX12		Linux 1.2.x
#	LINUX20		Linux 2.0.x
#	HPUX		HP Unix
#	UNIXWARE	UnixWare 2.x and newer SCO systems
#
OS=

AIXCFLAGS=	-DAIX -DHAVEGIDTYPE
AUXCFLAGS=	$(SVR3CFLAGS) -Dmemmove=memcpy -D_POSIX_SOURCE
BSDICFLAGS=	-DBSDI -DHAVESYSERR
DECOSF1CFLAGS=	-DDECOSF
FREEBSDCFLAGS=	-DFREEBSD -DHAVESYSERR
HPUXCFLAGS=	-DHPUX   -DSYSV -DNOGETDTABLE -DHAVEGIDTYPE -DPOSIX
IRIX40CFLAGS=	-DIRIX40  -cckr -DHAVEGIDTYPE
IRIX51CFLAGS=	-DIRIX51  -DIRIX40 -cckr -D_BSD_SIGNALS -DHAVEGIDTYPE
LINUX12CFLAGS=	-DLINUX  -DHAVEGIDTYPE
LINUX20CFLAGS=	-DLINUX  -DHAVEGIDTYPE -DHAVESYSERR
SUNOS4CFLAGS=	-DSUNOS4
SUNOS5CFLAGS=	-DSUNOS5  -DSYSV -DNOGETDTABLE -DHAVEGIDTYPE -DPOSIX
SVR3CFLAGS=	-DNOFSYNC -DSYSV -DPOSIX -DNOINITGROUPS
SVR4CFLAGS=	-DSVR4    -DSYSV -DPOSIX
ULTRIXCFLAGS=	-DULTRIX
UNIXWARECFLAGS=	-DSVR4   -DSYSV -DPOSIX

AIXLIBS=	-lbsd
AUXLIBS=	-lposix
FREEBSDLIBS=	-lcrypt
IRIX40LIBS=	-lsun
LINUX12LIBS=	-ldbm
LINUX20LIBS=	-lgdbm
SUNOS5LIBS=	-lnsl -lsocket
SVR3LIBS=	-lsocket -lsec -lcrypt
SVR4LIBS=	-lnsl -lsocket
UNIXWARELIBS=	-lcrypt -lgen -lc -L /usr/ucblib -lucb -lsocket -ldbm

##
## Tack on the OS specific options to cflags & ldflags
CFLAGS= 	$(MYCFLAGS)  $(OS_CFLAGS)
LDFLAGS=	$(MYLIBS)    $(OS_LIBS)  $(QI_LIBS)

# Make Getpw last since some compilers may delete the .o file
TARG=	xtacacsd taclast tacupd xpasswd Getpw
OBJS=	xtacacsd.o Getpw.o charap.o perm.o misc.o ph.o \
	uwtmp.o $(ARAP_OBJS) $(CHAP_OBJS)
DIST=	Makefile RELEASE README README.cisco \
	getok.pl tacstats.pl tacping.pl \
	tacacs.h common.h tacutmp.h version.h xtacacsd-conf \
	xtacacsd.man taclast.man tacupd.man Getpw.man \
	xtacacsd.c Getpw.c charap.c perm.c misc.c ph.c uwtmp.c \
	xmd5.h xmd5.c \
	taclast.c tacupd.c xpasswd.c \
	tacacct.c tacacct.h tacacct-conf \
	enigma sdi html

all: os-targs	# os-targs or  alltargs

alltargs:  $(TARG)	# used in 2nd pass when make calls itself

xtacacsd:	$(OBJS)	
	@echo "######## Making $@ ########"
	$(CC) $(CFLAGS) $(OBJS) -o $@ $(LDFLAGS)

taclast: taclast.o misc.o uwtmp.o
	@echo "######## Making $@ ########"
	$(CC) $(CFLAGS) uwtmp.o misc.o taclast.o -o $@ $(LDFLAGS)

tacupd: tacupd.o misc.o uwtmp.o
	@echo "######## Making $@ ########"
	$(CC) $(CFLAGS) uwtmp.o misc.o tacupd.o -o $@ $(LDFLAGS)

xpasswd:  xpasswd.o Getpw.o
	@echo "######## Making $@ ########"
	$(CC) $(CFLAGS)  $(CDEFS) xpasswd.o Getpw.o -o $@ $(LDFLAGS)

Getpw:  Getpw.c
	@echo "######## Making $@ ########"
	$(CC) $(CFLAGS)  $(CDEFS) -DGETPW_MAIN  Getpw.c -o $@ $(LDFLAGS)

tacacct:  taclast.c tacacct.c timerange.o misc.o uwtmp.o
	@echo "######## Making $@ ########"
	$(CC) $(CFLAGS)  $(CDEFS) -DTACACCT taclast.c tacacct.c \
	timerange.o misc.o uwtmp.o -o $@ $(LDFLAGS)

.c.o:
	$(CC) -c $(CFLAGS) $(ARAP_FLAGS) $(CHAP_FLAGS) $(QI_FLAGS) $(CDEFS) $<

clean:
	rm -f $(TARG) tacacct *.o *.s errs core a.out 

install:
	-for i in $(TARG) ; do \
	 $(INSTALL) -s -m 711 "$$i"  $(BINDIR)/ ;\
	done

man:
	-for i in $(MANPROGS) ; do \
	 $(INSTALL) -c -m 644 "$$i".man  $(MANDIR)/$$i.$(MANEXT) ;\
	done

shar:  xtacacsd.shar
xtacacsd.shar:  $(DIST)
	@-/bin/rm -f xtacacsd-$(REV).shar
	@ [ -d /var/tmp/t/xtacacsd-$(REV) ] || mkdir /var/tmp/t /var/tmp/t/xtacacsd-$(REV)
	@ cp -r $(DIST) /var/tmp/t/xtacacsd-$(REV)
	@ cd /var/tmp/t ; shar -v -c xtacacsd-$(REV) > xtacacsd.shar
	@ mv /var/tmp/t/xtacacsd.shar ./xtacacsd-$(REV).shar
	@ ls -l xtacacsd-$(REV).shar ; /bin/rm -rf /var/tmp/t

tar:	xtacacsd.tar.gz
xtacacsd.tar.gz:  $(DIST)
	@ [ -d /var/tmp/t/xtacacsd-$(REV) ] || mkdir /var/tmp/t /var/tmp/t/xtacacsd-$(REV)
	@ cp -r $(DIST) /var/tmp/t/xtacacsd-$(REV)
	@ /bin/rm -rf /var/tmp/t/xtacacsd-$(REV)/*/RCS
	@ cd /var/tmp/t ; tar cf - xtacacsd-$(REV) | gzip -c > xtacacsd.tar.gz
	@ mv /var/tmp/t/xtacacsd.tar.gz ./xtacacsd-$(REV).tar.gz
	@ ls -l xtacacsd-$(REV).tar.gz ; /bin/rm -rf /var/tmp/t

version.h: Makefile
	@rm -f version.h
	@echo "#define XVERSION \"${REV}\"" > version.h
	@cat version.h

## Auto detect the operating system and set the OS_specific flags.
#
os-targs:
	@echo "This is xtacacsd revision $(REV)"
	@if [ "$(OS)" = "" ]; then \
	    OS=`uname -s -r` ; \
	else \
	    echo "OS set manually" ;\
	    OS="$(OS)" ;\
	fi; \
	case "$$OS" in \
	IRIX40|IRIX\ 4*) \
	    OS_CFLAGS="$(IRIX40CFLAGS)" ; OS_LIBS="$(IRIX40LIBS)" ; \
	    ;; \
	IRIX51|IRIX\ 5*) \
	    OS_CFLAGS="$(IRIX51CFLAGS)" ; OS_LIBS="$(IRIX51LIBS)" ; \
	    ;; \
	SUNOS4|SunOS\ 4*) \
	    OS_CFLAGS="$(SUNOS4CFLAGS)" ; OS_LIBS="$(SUNOS4LIBS)" ; \
	    ;; \
	SUNOS5|SunOS\ 5*) \
	    OS_CFLAGS="$(SUNOS5CFLAGS)" ; OS_LIBS="$(SUNOS5LIBS)" ; \
	    ;; \
	SVR4|System\ V\ Release\ 4*) \
	    OS_CFLAGS="$(SVR4CFLAGS)"   ; OS_LIBS="$(SVR4LIBS)" ; \
	    ;; \
	SVR3|SCO|System\ V\ Release\ 3*) \
	    OS_CFLAGS="$(SVR3CFLAGS)"   ; OS_LIBS="$(SVR3LIBS)" ; \
	    ;; \
	ULTRIX\ *|Ultrix\ *|ultrix\ *) \
	    OS_CFLAGS="$(ULTRIXCFLAGS)" ; OS_LIBS="$(ULTRIXLIBS)" ; \
	    ;; \
	OSF1|OSF1\ *|OSF\ 1*) \
	    OS_CFLAGS="$(DECOSF1CFLAGS)" ; OS_LIBS="$(DECOSF1LIBS)" ; \
	    ;; \
	BSDI|BSDI\ *|BSD386\ *|BSD/386\ *|FreeBSD\ 1*|BSD/OS\ *) \
	    OS_CFLAGS="$(BSDICFLAGS)"  ;  OS_LIBS="$(BSDILIBS)" ; \
	    ;; \
	FREEBSD|FreeBSD\ 2*|FreeBSD\ 3*) \
	    OS_CFLAGS="$(FREEBSDCFLAGS)"  ;  OS_LIBS="$(FREEBSDLIBS)" ; \
	    ;; \
	AIX|AIX\ *) \
	    OS_CFLAGS="$(AIXCFLAGS)"  ;  OS_LIBS="$(AIXLIBS)" ; \
	    INSTALL=/usr/ucb/install ; \
	    ;; \
	AUX|A/UX\ 3*) \
	    OS_CFLAGS="$(AUXCFLAGS)"  ;  OS_LIBS="$(AUXLIBS)" ; \
	    ;; \
	HPUX|HP-UX\ *) \
	    OS_CFLAGS="$(HPUXCFLAGS)"  ;  OS_LIBS="$(HPUXLIBS)" ; \
	    ;; \
	UNIXWARE|UNIXWARE\ *|SCO_SV\ 3*) \
	    OS_CFLAGS="$(UNIXWARECFLAGS)"  ;  OS_LIBS="$(UNIXWARELIBS)" ; \
	    ;; \
	LINUX12|Linux\ 1*) \
	    OS_CFLAGS="$(LINUX12CFLAGS)"  ;  OS_LIBS="$(LINUX12LIBS)" ; \
	    ;; \
	LINUX20|Linux\ 2*) \
	    OS_CFLAGS="$(LINUX20CFLAGS)"  ;  OS_LIBS="$(LINUX20LIBS)" ; \
	    ;; \
	*) \
	    echo "OS=$$OS is not a supported or detected operating system."; \
	    echo "Try setting OS manually to the type of your system or set the"; \
	    echo "OS_CFLAGS and OS_LIBS value manually in the makefile if compile fails"; \
	    OS_CFLAGS=""  ;  OS_LIBS="" ; \
	    ;; \
	esac ; \
	echo "Making for OS $$OS" ; \
	echo "	OS_CFLAGS= $$OS_CFLAGS  and  OS_LIBS= $$OS_LIBS" ; \
	echo "" ; \
	$(MAKE) CC="$(CC)" OS_CFLAGS="$$OS_CFLAGS" OS_LIBS="$$OS_LIBS" alltargs ;


# DO NOT DELETE THIS LINE -- mkdep uses it.
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.

xtacacsd.o:	xtacacsd.c tacacs.h tacutmp.h common.h
perm.o:		perm.c tacacs.h tacutmp.h common.h
misc.o:		misc.c tacacs.h tacutmp.h common.h
arap_des.o:	arap_des.c arap_des.h
xmd5.o:		xmd5.c xmd5.h
