#
# Makefile for linux/drivers/net/bcm
#

BCMTGT=bnx2

# PREFIX may be set by the RPM build to set the effective root.
PREFIX=

# Verify our required files are in the provided linux source directory.
ifeq ($(shell cd $(BCMEXTSRCDIR)/include/linux; if [ `ls kernel.h netdevice.h 2>/dev/null | wc -l` = 2 ]; then echo "pass"; fi),)

	# Nope.  Perhaps DKMS gave us the "build" directory by mistake.
	# If so, check for a "source" directory nearby.
	BCMTESTDIR := $(shell cd $(BCMEXTSRCDIR)/../source; pwd)
	ifeq ($(shell cd $(BCMTESTDIR)/include/linux; if [ `ls kernel.h netdevice.h 2> /dev/null | wc -l` = 2 ]; then echo "pass"; fi),)

		# Force a hard failure if no source.
		$(error Cannot find linux source)

	else

		# It worked!
		BCMLINSRC := $(BCMTESTDIR)

	endif

else

	# Yes!  Assign it.
	BCMLINSRC := $(BCMEXTSRCDIR)

endif


ifneq ($(shell grep netdump_mode $(BCMLINSRC)/include/linux/kernel.h > /dev/null 2>&1 && echo rh),)
	EXTRA_CFLAGS = -DRED_HAT_LINUX_KERNEL
endif

ifeq ($(BNX2_BOOT_DISK),1)
	EXTRA_CFLAGS += -DBNX2_BOOT_DISK
endif

ifeq ($(shell grep netif_poll_disable $(BCMLINSRC)/include/linux/netdevice.h > /dev/null 2>&1 && echo newnetif),)
	EXTRA_CFLAGS += -DOLD_NETIF
endif

ifeq ($(shell ls $(BCMLINSRC)/include/net/netevent.h > /dev/null 2>&1 && echo ne),ne)
	EXTRA_CFLAGS += -DHAVE_NETEVENT
endif

ifneq ($(shell grep skb_transport_offset $(BCMLINSRC)/include/linux/skbuff.h > /dev/null 2>&1 && echo sk),)
	EXTRA_CFLAGS += -DNEW_SKB
endif

ifneq ($(shell grep "static inline struct iphdr \*ip_hdr" $(BCMLINSRC)/include/linux/ip.h > /dev/null 2>&1 && echo ip),)
	EXTRA_CFLAGS += -DHAVE_IP_HDR
endif

ifneq ($(shell grep "__le32" $(BCMLINSRC)/include/linux/types.h > /dev/null 2>&1 && echo le32),)
	EXTRA_CFLAGS += -DHAVE_LE32
endif

BCM_CNIC:=$(shell echo $(KERNELRELEASE) | cut -c5- | cut -d. -f1 | cut -d- -f1 | awk '{ if ($$1 > 15) print "1"; else print "0"}')

# Check if 2.4 kernel or 2.5+ kernel.
BCM_KVER:=$(shell echo $(KERNELRELEASE) | cut -c1-3 | sed 's/2\.[56]/2\.6/')

ifeq ($(BCM_KVER), 2.6)

obj-m := $(BCMTGT).o

ifeq ($(BCM_CNIC),1)
obj-m += cnic.o
endif

default:
	make -C $(BCMEXTSRCDIR) SUBDIRS=$(SUBDIRS) modules

else

obj-m := $(BCMTGT).o

include $(TOPDIR)/Rules.make

endif
