# $Id: Makefile,v 1.1.1.1 2000/12/05 15:19:35 nap Exp $

# (c) Copyright 2000 M.I.T.
# Permission is hereby granted, without written agreement or
# royalty fee, to use, copy, modify, and distribute this
# software and its documentation for any purpose, provided that
# the above copyright notice and the following three paragraphs
# appear in all copies of this software.

# IN NO EVENT SHALL M.I.T. BE LIABLE TO ANY PARTY FOR DIRECT,
# INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
# ARISING OUT OF THE USE OF THIS SOFTARE AND ITS DOCUMENTATION,
# EVEN IF M.I.T. HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

# M.I.T. SPECIFICALLY DISCLAIMS ANY WARRANTIES INCLUDING, BUT
# NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.

# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND M.I.T. HAS
# NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
# ENHANCEMENTS, OR MODIFICATIONS.


SHELL = /bin/sh

# Configure these:
prefix 		= /usr
pcap_include 	= $(prefix)/include/pcap
pcap_lib 	= $(prefix)/lib
libnet_include 	= $(prefix)/include
libnet_lib 	= $(prefix)/lib
tcpdump_include = $(prefix)/local/tcpdump
man_page_dir    = $(prefix)/man/man1


PROG = netpoke netpoke2

includes = $(wildcard *.h)
sources  = $(PROG:%=%.c) $(includes:%.h=%.c)
depends  = $(sources:%.c=%.d)
objects  = $(sources:%.c=%.o)
modules  = $(includes:%.h=%.o)
purified = $(PROG:%=pure-%)

CC        =  gcc
CPPFLAGS  += -I $(pcap_include) -I $(libnet_include) -I $(tcpdump_include)
#CFLAGS    += -W -Wall
LDFLAGS   += -L $(pcap_lib) -L $(libnet_lib)

#ifndef debug
#    debug = 0
#endif

#ifeq ($(debug),1)
#    CFLAGS += -g
#    LDFLAGS += -g
#else
#    CFLAGS += -O3 -DNDEBUG
#endif

#Linux
LOADLIBES += -lpcap -lnet -lnsl -lm

# may need to specify loadlibes with -L switch, see example below:
# LOADLIBES += -L /dir/libpcapdir -L /dir/libnetdir/lib -lpcap -lnet -lnsl -lm

#.PHONY: all pure print clean

all: $(PROG) insman

insman: 
	-cp netpoke.1 $(man_page_dir)
	-gzip $(man_page_dir)/netpoke.1

pure: $(purified)

clean:
	-rm -f $(PROG) $(purified) $(depends) $(objects) $(modules) *.ps *~
	-pure_remove_old_files
	-rm $(man_page_dir)/netpoke.*

print:
	-enscript -2rp print.ps Makefile $(includes) $(sources)
	-troff -man netpoke.1 | dpost > manpage.ps
	-include $(depends)


%.d: %.c
	$(SHELL) -ec '$(CC) -MM $(CPPFLAGS) $< | sed '\''s/$*.o/& $@/g'\'' > $@'

pure-%: %.o
	purify $(CC) $(LDFLAGS) -o $@ $^ $(LOADLIBES)


%: %.o
	$(CC) $(CPPFLAGS) $@.c $(LDFLAGS) $(LOADLIBES) -g -o $@
#	./netpoke -v -u -V -I "172.*.*.*" -i eth0 -e eth1-D 0f:14:7a:77:ff:dc telnet.dump    
#	./netpoke -E 00:00:0c:04:41:bc -v -u -I ac:10:ac:10:ac:10 -N "172.16.*.*" -e eth0 -i eth1 /home/blin/tcpdump/week5_th/tcpdump -s 0 -r 5 > output

#$(PROG) :$(modules)







