# 
# /*************************************************
# *     rpld - an IBM style RIPL server            *
# *************************************************/
# 
# /* Copyright (c) 1999, James McKenzie.
#  *                      All rights reserved
#  * Copyright (c) 1998, Christopher Lightfoot.
#  *                      All rights reserved
#  *
#  * 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.14 1999/09/15 13:46:58 root Exp $
#
# $Log: Makefile,v $
# Revision 1.14  1999/09/15 13:46:58  root
# #
#
# Revision 1.13  1999/09/15 00:36:29  root
# #
#
# Revision 1.12  1999/09/14 21:45:17  root
# #
#
# Revision 1.11  1999/09/14 21:38:41  root
# #
#
# Revision 1.10  1999/09/14 21:36:03  root
# #
#
# Revision 1.9  1999/09/14 21:32:13  root
# #
#
# Revision 1.8  1999/09/14 21:26:00  root
# #
#
# Revision 1.7  1999/09/14 21:16:25  root
# #
#
# Revision 1.6  1999/09/14 21:14:38  root
# #
#
# Revision 1.5  1999/09/14 21:13:14  root
# #
#
# Revision 1.4  1999/09/14 17:18:27  root
# #
#
# Revision 1.3  1999/09/14 17:12:39  root
# #
#
# Revision 1.2  1999/09/14 16:17:16  root
# #
#
# Revision 1.1  1999/09/13 12:36:20  root
# #
#
#

# EDITME: this is the delay between transmitted packets in us 
# you may need to edit this if your clients are slow 
# if a client drops a packet it will typically wait 1s and then 
# issue a retransmit request causing a delay. 
# do make clean after changing this

DEFINES=-DPACKET_DELAY=0

# where do you want all this stuff

DESTDIR=/usr

# Stuff
CC	 = gcc
INCLUDES = 
CFLAGS   = -O ${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.2

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 capture to capture RPL traffic
	@echo " " or make replay to analyse captured RPL traffic
	@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 -a
MANDOC= -mandoc
INSTALL=install
BINOWN= root
BINGRP= kmem
BINMODE=4555

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 linux-ps.c rpld.c util.c rpl.c llc.c client.c config.c
HSRCS=rpl.h project.h rpl.h linux-ps.h llc.h client.h 

CSRCS=${PROTOSRC} 

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

ALLSRCS=${CSRCS}

RCSCFILES=${CSRCS} ${HSRCS}
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} $< > $@
doc/rpld.conf.5:rpld.conf.man
	${NROFF} ${MANDOC} $< > $@

%.${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

realtime: ana
	tcpdump -l -x -s 2048 ether[14]=0xfc and ether[15]=0xfc | 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}
	for i in ${PROTOSRC}; do cproto $$i | grep -v inline >> ${PROTOH}  ; done



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}
	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

