# 
# /*************************************************
# *     rpld - an IBM style RIPL server            *
# *************************************************/
# 
# /* Copyright (c) 1999,2000,2001 James McKenzie.
#  *                      All rights reserved
#  * Copyright (c) 1998,2000,2001 Christopher Lightfoot.
#  *                      All rights reserved
#  *
#  * NetBSD and BPF support by Takashi YAMAMOTO
#  * Copyright (C) 2001 YAMAMOTO Takashi <yamt@netbsd.org>.
#  *
#  * By using this file, you agree to the terms and conditions set
#  * forth in the LICENCE file which can be found at the top level of
#  * the rpld distribution.
#  *
#  * IBM is a trademark of IBM corp.
#  *
#  */

#
# $Id: Makefile,v 1.26 2001/11/01 15:26:30 root Exp $
#
# $Log: Makefile,v $
# Revision 1.26  2001/11/01 15:26:30  root
# #
#
# Revision 1.25  2001/11/01 15:24:28  root
# #
#
# Revision 1.24  2001/11/01 15:24:00  root
# #
#
# Revision 1.23  2000/09/26 03:46:20  root
# #
#
# Revision 1.22  2000/09/26 02:32:47  root
# #
#
# Revision 1.21  2000/09/26 02:31:39  root
# #
#
# Revision 1.20  2000/09/26 01:03:22  root
# #
#
#

#

# Important you need to choose a driver for rpld
# there are two sorts of driver for rpld:
#   nit: easy to write and dirty
#        these drivers send a copy of
#        every (LLC) packet transmitted
#        or received to rpld, and greatly
#        increase CPU load.
#
#   llc: these are for systems which have
#        native LLC support, the kernel
#        takes care of the LLC layer and
#        passes decoded data down to rpld  
#

# Available NIT drivers: choose from
#  linux-nit.c:	  For modern kerenels, attempts to persuade the
#		  kernel to send rpld only 802.2 frames thus 
#		  greatly reducing system load. However some
#		  bad voodo magic is required to get it to
#		  send properly.
#
#  linux-old-nit.c:  For older kernels and those with problems.
#                    this is the simplest possible form of driver
#                    it receives every frame tranmitted of received
#                    from the host and places a large extra load on
#                    busy machines.
#                    
#  bpf-nit.c:  For NetBSD and possibly other BPF implementations
#              this version seems to do no filtering, so it receives
#              every frame - increasing system load.
#                    
#  llc-nit.c implements the LLC 802.2 layer ontop of the raw packet (nit)
#  layer and is needed in all cases
#
#  Newer driver
NIT=linux-nit.c
#  Older driver
#NIT=linux-old-nit.c
#  BPF driver for NetBSD (may old work on SunOS, havent checked)
#NIT=bpf-nit.c

DRIVER=llc-nit.c ${NIT}

# Native LLC drivers, to use these you require a kernel with native
# llc support, for linux 2.2 you can use the patches in ./kernel
# for linux 2.3 and 2.4 you can use the LLC stack that comes as 
# part of the linux-sna package available at www.linux-sna.org 
# 
# To use this driver comment out the DRIVER line above and
# uncomment this one
# DRIVER=llc-linux.c

DEFINES=

# where do you want all this stuff

DESTDIR=/usr/local

# Stuff
CC	 = gcc
INCLUDES = 
OPT	 = -O
CFLAGS   = ${OPT} ${INCLUDES} ${DEFINES}
LIBS     = 
LDFLAGS  =

# Where to find yacc and lex
YACC=yacc
LEX=lex

# Where to find BSD compatible install
INSTALL=install

################# NO USER SERVICABLE PARTS BELOW HERE

VERSION=1.8

COFLAGS = -l

default:do-it-all

ifeq (.depend,$(wildcard .depend))
include .depend
do-it-all: all
	@echo " " Now type make install to install rpld
	@echo " " or make nics to assemble the adapter utilities
	@echo " " or make realtime to capture and analyse RPL traffic

else
do-it-all: depend
	@echo " " Now type make again to build rpld
endif

BINDIR= ${DESTDIR}/sbin
NROFF=  groff -Tascii
NRCLN = sed 's/.//g'
MANDOC= -mandoc
BINOWN= root
BINGRP= kmem
BINMODE=555

MANOWN= bin
MANGRP= bin
MANMODE=444

MANROOT=${DESTDIR}/man/man
MAN8=   ${MANROOT}8
MAN8EXT=8
MAN8SRC=man
MAN5=   ${MANROOT}5
MAN5EXT=5
MAN5SRC=man


PROTOSRC = protocol.c rpld.c util.c rpl.c client.c config.c  
HSRCS=rpl.h project.h rpl.h llc.h client.h  nit.h

CSRCS=${PROTOSRC} ${DRIVER}

YSRCS=rpld_conf.y
LSRCS=rpld_conf.lex
MANSRCS=rpld.man rpld.conf.man

ALLSRCS=${CSRCS}

RCSCFILES=${CSRCS} ${HSRCS} linux-nit.c linux-old-nit.c llc-linux.c bpf-nit.c
RCSFILES=${RCSCFILES} ${YSRCS} ${LSRCS} ${MANSRCS} ana.c


PROTOH=prototypes.h

PROG=rpld

OBJS=${CSRCS:%.c=%.o} ${YSRCS:%.y=%.yy.o} ${LSRCS:%.lex=%.tab.o}

YGUFF=${YSRCS:%.y=%.yy.c} ${LSRCS:%.lex=%.tab.c} ${LSRCS:%.lex=%.tab.h}

all:${PROG} ana doc




install: install-prog install-docs
	@echo " " you can find a sample configuration file
	@echo " " in this directory called rpld.conf.sample
	@echo " " your config file should be placed in /etc/rpld.conf

MEN=rpld.conf.5 rpld.8
TXTMEN=${MEN:%=doc/%}

doc:${MEN} 

doc/rpld.8:rpld.man
	${NROFF} ${MANDOC} $< | ${NRCLN} > $@
doc/rpld.conf.5:rpld.conf.man
	${NROFF} ${MANDOC} $< | ${NRCLN} > $@

%.${MAN8EXT}:%.${MAN8SRC}
	cp $< $@

%.${MAN5EXT}:%.${MAN5SRC}
	cp $< $@

install-prog:${PROG}
	${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} ${PROG} ${BINDIR}

install-docs: doc
	${INSTALL} -c -o ${MANOWN} -g ${MANGRP} -m ${MANMODE} rpld.${MAN8EXT} ${MAN8}/rpld.${MAN8EXT}
	${INSTALL} -c -o ${MANOWN} -g ${MANGRP} -m ${MANMODE} rpld.conf.${MAN5EXT} ${MAN5}/rpld.conf.${MAN5EXT}

ana:ana.c ${NIT}
#linux-old-nit.c

realtime: ana
	./ana

#capture: 
#	tcpdump -x -s 2048 ether[14]=0xfc and ether[15]=0xfc -w capture.dat

#replay: ana capture.dat
#	tcpdump -x -r capture.dat | ana


nics: nics.doesntexist

nics.doesntexist:
	${MAKE} -C nics

${PROG}:${OBJS}
	${CC} ${CFLAGS} ${LDFLAGS} -o ${PROG} ${OBJS} ${LIBS}

clean: nodep
	/bin/rm -rf ${OBJS} *% *~ *.o *.BAK core a.out ${PROG}
	/bin/rm -rf ${YSRCS:%.y=%.yy.c} ${LSRCS:%.lex=%.tab.c}
	/bin/rm -rf ${LSRCS:%.lex=%.tab.h}
	/bin/rm -rf ana capture.dat
	/bin/rm -rf nics.stamp
	/bin/rm -rf ${MEN} Makefile.bak
	${MAKE} -C nics clean

proto: ${PROTOSRCS} ${HSRCS} ${LSRCS:%.lex=%.tab.h}
	echo -n > ${PROTOH}
	echo -n > ${PROTOH}.tmp
	for i in ${PROTOSRC}; do cproto -e -v $$i | grep -v inline >> ${PROTOH}.tmp  ; done
	/bin/mv -f ${PROTOH}.tmp ${PROTOH}



depend: ${RCSFILES} ${YSRCS:%.y=%.tab.h} 
	makedepend -f- ${INCLUDES} ${ALLSRCS} > .depend

nodep:
	/bin/rm -rf .depend

tidy:
	ci -l -m\# ${RCSFILES}
	indent -ts0 -i2 ${RCSCFILES}
	ci -l -m\# ana.c
	indent -ts0 -i2 ana.c
	/bin/rm -rf nics.stamp
	${MAKE} -C nics tidy
	ci -l -m\# Makefile

checkin:
	ci -m\# ${RCSFILES}
checkout:
	ci -l ${RCSFILES}

MYDIR=rpld-${VERSION}

distrib: 
	${MAKE} tidy
	${MAKE} proto
	${MAKE} doc
	${MAKE} clean
	${MAKE} yguff
	${MAKE} ${TXTMEN}
	${MAKE} -C nics
	cd ..; tar cvfzX ${MYDIR}/DISTRIB/${MYDIR}.tar.gz ${MYDIR}/.xclude ${MYDIR}

yguff:${YGUFF}
	

%.tab.c:%.y
	${YACC} -d -b ${@:%.tab.c=%} $<

%.tab.h:%.y
	${YACC} -d -b ${@:%.tab.h=%} $<

%.yy.c:%.lex
	${LEX} -o$@ $<

config.o: rpld_conf.tab.h

# DO NOT DELETE
