# $Copyright: $
# Copyright (c) 1995-2000 by Steve Baker
# All Rights reserved
#
# This software is provided as is without any express or implied
# warranties, including, without limitation, the implied warranties
# of merchant-ability and fitness for a particular purpose.
#
# Thanks to Edward S. Marshall for extending the Makefile.
#

CC=gcc

# For Intel platforms (use -m386 w/ AMD CPU's for better speed):
#CFLAGS=-Wall -O2 -fomit-frame-pointer -m486
# Don't use -m486 on Debian
CFLAGS=-Wall -O2 -fomit-frame-pointer 
# For everything else:
#CFLAGS=-Wall -O2
# For debugging
#CFLAGS=-ggdb

# Comment this if doing debugging.
LDFLAGS=-s

# Define acording to your architechure.  Only SOLARIS and LINUX are valid
# thus far.  Most OS's should work with one or the other.
# Solaris 2.x only:
#ARCH=SOLARIS
# Linux libc5 / glibc 2.x:
ARCH=LINUX

# Radius Options:
DETAIL_NAME=detail
#RADIUS_DIR=/usr/adm/radacct
RADIUS_DIR=/var/log/radacct
#Set to "1" if you wish to use Framed-IP-Address for the users hostname.
USE_FRAMED_IP_ADDR=0

RADOPTS=-DRADIUS_DIR=\"${RADIUS_DIR}\" -DDETAIL_NAME=\"${DETAIL_NAME}\" \
	-DUSE_FRAMED_IP_ADDR=${USE_FRAMED_IP_ADDR}

# General options:
SAC_DEST=sac
RAW_DEST=rawtmp
WRITETMP_DEST=writetmp
#BINDIR=/usr/local/bin
BINDIR=$(DESTDIR)/bin
MANS=sac.8 rawtmp.1 writetmp.8
MANDIR=/usr/man

all:	sac rawtmp writetmp

sac:	sac.o
	$(CC) $(CFLAGS) $(LDFLAGS) -o $(SAC_DEST) sac.o

sac.o:	sac.c
	$(CC) $(CFLAGS) -D$(ARCH)=1 $(RADOPTS) -c sac.c

rawtmp:	rawtmp.o
	$(CC) $(LDFLAGS) -o $(RAW_DEST) rawtmp.o

writetmp: writetmp.o
	$(CC) $(LDFLAGS) -o $(WRITETMP_DEST) writetmp.o

rawtmp.o:	rawtmp.c
	$(CC) $(CFLAGS) -D$(ARCH)=1 -c rawtmp.c

writetmp.o:	writetmp.c
	$(CC) $(CFLAGS) -D$(ARCH)=1 -c writetmp.c

clean:
	if [ -e $(SAC_DEST) ]; then rm $(SAC_DEST); fi
	if [ -e $(RAW_DEST) ]; then rm $(RAW_DEST); fi
	if [ -e $(WRITETMP_DEST) ]; then rm $(WRITETMP_DEST); fi
	if [ -e sac.o -o -e raw.o -o -e writetmp.o ]; then rm *.o; fi

install:
	install -d $(BINDIR)
	if [ -f $(SAC_DEST) ]; then \
		install -s $(SAC_DEST) $(BINDIR)/$(SAC_DEST); \
	fi
	if [ -f $(RAW_DEST) ]; then \
		install -s $(RAW_DEST) $(BINDIR)/$(RAW_DEST); \
	fi
	if [ -f $(WRITETMP_DEST) ]; then \
		install -s $(WRITETMP_DEST) $(BINDIR)/$(WRITETMP_DEST); \
	fi
	for man in $(MANS); do \
		m=`expr match $$man '.*\(.\)'`; \
		install $$man $(MANDIR)/man$$m/$$man; \
	done

VERSION=1.9

tarball:
	cd ..; \
	tar cvzf sac-${VERSION}.tgz `cat sac-${VERSION}/.tarball`
