#!/usr/bin/make
# Makefile for building Linux Broadcom Gigabit ethernet driver as a module.
# $id$

# PREFIX may be set by the RPM build to set the effective root.
PREFIX=
LINUX=/usr/src/linux
ifeq ($(shell which kgcc > /dev/null 2>&1 && echo kgcc),)
CC = gcc
else
CC = kgcc
endif
CFLAGS=-DMODULE -D__KERNEL__ -DDBG=0 -DT3_JUMBO_RCV_RCB_ENTRY_COUNT=256 -DNICE_SUPPORT -DPCIX_TARGET_WORKAROUND=1 -Wall -Wstrict-prototypes -O6 -I$(LINUX)/include

ifeq ($(wildcard ~/rpmdir),)
  rpmdir = /usr/src/redhat
else
  rpmdir = $(wildcard ~/rpmdir)
endif

# If the modversion.h file exists we should pass a flag.
# Most of my drivers have been updated to not need this, but not the other
# kernel source files.
#MODVER_H = $(LINUX)/include/linux/modversions.h
#ifneq ($(wildcard $(MODVER_H)),"")
#  CFLAGS += -DMODVERSIONS
#endif

all: bcm5700.o
tar: bcm5700.tgz

bcm5700.o: bcm5700.c tigon3.c bits.h debug.h lm.h lmcfg.h mm.h queue.h tigon3.h
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $<

install: bcm5700.o
	@if [ -d $(PREFIX)/lib/modules/`uname -r`/kernel ];\
	then install -m 444 bcm5700.o $(PREFIX)/lib/modules/`uname -r`/kernel/drivers/net/;\
	else install -m 444 bcm5700.o $(PREFIX)/lib/modules/`uname -r`/net/;\
	fi
	@if [ "$(PREFIX)" = "" ]; then /sbin/depmod -a ;\
	else echo " *** Run '/sbin/depmod -a' to update the module database.";\
	fi

bcm5700.tgz: Makefile *.[cho] LICENSE RELEASE.TXT
	tar cfvz $@ $^

rpm: bcm5700.tgz bcm5700.spec
	cp -p $< ${rpmdir}/SOURCES/
	rpm -ba bcm5700.spec

.PHONEY: all clean install tar

clean:
	-rm -f bcm5700.o bcm5700.tgz
