###############################################################################
#                                                                             #
#   Copyright 2005 University of Cambridge Computer Laboratory.               #
#                                                                             #
#   This file is part of Nprobe.                                              #
#                                                                             #
#   Nprobe is free software; you can redistribute it and/or modify            #
#   it under the terms of the GNU General Public License as published by      #
#   the Free Software Foundation; either version 2 of the License, or         #
#   (at your option) any later version.                                       #
#                                                                             #
#   Nprobe is distributed in the hope that it will be useful,                 #
#   but WITHOUT ANY WARRANTY; without even the implied warranty of            #
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
#   GNU General Public License for more details.                              #
#                                                                             #
#   You should have received a copy of the GNU General Public License         #
#   along with Nprobe; if not, write to the Free Software                     #
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA #
#                                                                             #
###############################################################################


CONFIG_DEF = -DCAM_CONFIG
#CONFIG_DEF = -DCL_CONFIG
#CONFIG_DEF = -DNTL_CONFIG

######################################################

USEPROBE  = nprobe
USEDRIVER = acenic_np
USEDRIVER3COM = 3c59x_np

SRCS	 = *.c

#DRIVERS = acenic_np.o
DRIVERS  =

TARGETS   = $(DRIVERS) mon timer
KCC       = gcc -pipe
KCCFLAGS  = -D__KERNEL__ -I./linux/include -DMODULE -nostdinc
KCCFLAGS += -I../timers
KCCFLAGS += -iwithprefix include -DKBUILD_BASENAME=$(subst .c,,$<)
KCCFLAGS += -Wall -Wstrict-prototypes -Wno-trigraphs
KCCFLAGS += -O2 -fno-strict-aliasing -fno-common -fomit-frame-pointer
KCCFLAGS += -mpreferred-stack-boundary=2 -march=i686
ifeq ($(LINUXVER), 2.4)
TARGETS  += nprobe.o
KCCFLAGS += -DMODVERSIONS -include linux/include/linux/modversions.h -DLINUX24
CFLAGS   += -DLINUX24
else
TARGETS	 += nprobe.ko
KCCFLAGS += -Ilinux/include/asm-i386/mach-generic -Ilinux/include/asm-i386/mach-default -msoft-float -mregparm=3 -DKBUILD_MODNAME=nprobe
endif

all: $(TARGETS)

mon: mon.o sk98_timers.o
	gcc -Wall -g -lm -o $@ $^

mon.o: mon.c
	gcc $(CFLAGS) -Wall -g -I./linux/include -I../timers -DCAM_CONFIG -o $@ -c $<
sk98_timers.o: ../timers/sk98_timers.c
	gcc $(CFLAGS) -Wall -g -I./linux/include -I. -I../timers -DCAM_CONFIG -o $@ -c $<

timer: timer.c
	gcc -Wall -o timer timer.c

3c59x_np.o: 3c59x_np.c 
	$(KCC) $(KCCFLAGS) $(CONFIG_DEF) -o $@ -c $<

acenic_np.o: acenic_np.c acenic_np.h acenic_firmware.h
	$(KCC) $(KCCFLAGS) $(CONFIG_DEF) -o $@ -c $<

proc.o: proc.c
	$(KCC) $(KCCFLAGS) $(CONFIG_DEF) -o proc.o -c proc.c 

memhack.o: memhack.c
	$(KCC) $(KCCFLAGS) $(CONFIG_DEF) -o memhack.o -c memhack.c

nfuncs.o: nfuncs.c
	$(KCC) $(KCCFLAGS) -DEXPORT_SYMTAB $(CONFIG_DEF) -o nfuncs.o -c nfuncs.c

nprobe.o: probe.c proc.o memhack.o nfuncs.o
	$(KCC) $(KCCFLAGS) $(CONFIG_DEF) -o probe.o -c probe.c	
	ld -m elf_i386 -r -o nprobe.o  probe.o proc.o memhack.o nfuncs.o

nprobe.mod.o: nprobe.mod.c
	$(KCC) $(KCCFLAGS) $(CONFIG_DEF) -o nprobe.mod.o -c nprobe.mod.c

nprobe.ko: nprobe.mod.o nprobe.o
	ld -m elf_i386 -r -o $@ nprobe.o nprobe.mod.o

#mon: mon.o mon.c
#	$(CC)asdf  -o $@ $< 


unload:	
	really ifconfig eth1 down || true
	really ifconfig eth2 down || true
	really rmmod $(USEDRIVER) || true
	really rmmod $(USEPROBE) || true
	really rmmod acenic || true

load:	unload
	really insmod ./$(USEPROBE).o
	really insmod ./$(USEDRIVER).o
	cat /proc/modules
	tail /var/log/messages

unload3com:	
	really rmmod $(USEDRIVER3COM) || true
	really rmmod $(USEPROBE) || true

load3com:	unload3com
	really insmod ./$(USEPROBE).o
	really insmod ./$(USEDRIVER3COM).o
	cat /proc/modules
	tail /var/log/messages

start:	
	really ./mon

stop:
	really
	#really ifconfig eth1 down || true

go:
	really
	#really ifconfig eth1 up promisc


monitor:
	watch -n 1 cat /proc/atm/nic* /proc/atm/devices /proc/nprobe

clean:
	rm -f *.o mon timer

depend:
	makedepend -I. -I./linux/include $(SRCS)

# DO NOT DELETE THIS LINE -- make depend depends on it.

