#!/usr/bin/make all
# Makefile for building updated Linux PCI network device drivers as modules.
# Distributed for use with the Scyld driver set.
# $id$
# The makefile is modified based on the makefile written by Donald Becker
# Date : 03/20/2002

# PREFIX may be set by the RPM build to set the effective root.
PREFIX=
# Set KERNVER on the command line to build modules for a kernel other than
# the version that is currently running.

#+Wilson 03/20/2002
PCMCIAKNL=/usr/src/linux/pcmcia/include	
#+Wilson
PCMCIA=/usr/src/pcmcia/include
CC=gcc
CFLAGS=-DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -I$(LINUX)/include

# We go to great effort to work with the myriad ways that distributions
# have gotten confused about where kernel include files should be put.
# There have been over twenty broken "solutions", which is far more painful
# to deal with than just leaving the problem alone.

ifeq ($(KERNVER),)
  KERNVER=$(shell uname -r)
  ifeq ($(PREFIX)/lib/modules/$(KERNVER)/build,)
    LINUX=/usr/src/linux
    MODULEDIR=$(PREFIX)/lib/modules/$(KERNVER)
  else
    LINUX=$(PREFIX)/lib/modules/$(KERNVER)/build
    MODULEDIR=$(PREFIX)/lib/modules/$(KERNVER)/kernel/drivers
  endif
else
  LINUX=/usr/src/linux-$(KERNVER)
  MODULEDIR=$(PREFIX)/lib/modules/$(KERNVER)
endif

# Some architectures require magic gcc flags for kernel compiles.
#  First canoicalize the name:  *86 becomes i386.
ARCH:=$(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
ifeq ($(ARCH),i386)
    CFLAGS+=-pipe -fno-strength-reduce
endif
ifeq ($(ARCH),alpha)
    CFLAGS+=-pipe -mno-fp-regs -ffixed-8 -mcpu=ev5
endif

# Work around Red Hat 7.0 GCC version lossage.
ifneq ($(wildcard /usr/bin/kgcc),)
  CC=kgcc
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

#+-Wilson 03/20/2002
#DRV_OFILES = 3c59x.o eepro100.o epic100.o hamachi.o intel-gige.o \
#        myson803.o natsemi.o ns820.o rtl8139.o starfire.o \
#        sundance.o tulip.o via-rhine.o winbond-840.o yellowfin.o
DRV_OFILES = rtl8139.o
#+-Wilson

# We can only build the ne2k-pci. driver if we have a 8390.h file available.
#ifneq (,$(filter 2.4.%, $(KERNVER))) //-Wilson 03/20/2002
# This is a 2.4 kernel, do not build ne2k-pci.o
#else	//-Wilson 03/20/2002
# This is a 2.2 or earlier kernel, check that we have 8390.h
#-Wilson 03/20/2002
#ifneq (,$(wildcard $(LINUX)/drivers/net/8390.h))
#  DRV_OFILES += ne2k-pci.o
#endif
#endif
#-Wilson

OFILES= $(DRV_OFILES) pci-scan.o
ifeq ($(wildcard $(PCMCIA)/pcmcia/driver_ops.h),$(PCMCIA)/pcmcia/driver_ops.h)
  OFILES += cb_shim.o
  #CARDBUS= 3c575_cb.o epic_cb.o tulip_cb.o realtek_cb.o //-Wilson 03/20/2002
  CARDBUS= realtek_cb.o	
  CARDBUS-FLAGS = -DCARDBUS -I$(LINUX)/include -I/usr/include -I$(PCMCIA)
  CB_SHIM = cb_shim.o
else
  #+Wilson 03/20/2002	
  #ifeq ($(wildcard $(PCMCIA)/pcmcia/driver_ops.h),$(PCMCIA)/pcmcia/driver_ops.h)
  #  OFILES += cb_shim.o
  #  CARDBUS= realtek_cb.o	
  #  CARDBUS-FLAGS = -DCARDBUS -I$(LINUX)/include -I/usr/include -I$(PCMCIA)
  #  CB_SHIM = cb_shim.o
  #endif
  #+Wilson
endif

#+-Wilson 03/20/2002
#all: pci-skeleton.o pci-scan.o $(DRV_OFILES)
all: pci-scan.o $(OFILES)
#tar: netdrivers.tgz	
#+-Wilson

#+-Wilson 03/20/2002
#$(OFILES) pci-scan.o pci-skeleton.o: pci-scan.h kern_compat.h
$(OFILES) pci-scan.o: pci-scan.h kern_compat.h
#+-Wilson

pci-scan.o: pci-scan.h
# We need to pick up 8390.h
#-Wilson 03/20/2002
#ne2k-pci.o: ne2k-pci.c $(LINUX)/drivers/net/8390.h
#	$(CC) $(CPPFLAGS) $(CFLAGS) -I$(LINUX)/drivers/net/ -c $<
#-Wilson

cb_shim.o: cb_shim.c
	 $(CC) $(CARDBUS-FLAGS) $(CFLAGS) -c $< -o $@ 

#-Wilson 03/19/2002
#install: $(OFILES)
#	install -m 444 pci-scan.o $(DRV_OFILES) $(MODULEDIR)/net/
#	@if [ -r cb_shim.o ]; then install -m 444 cb_shim.o $(MODULEDIR)/pcmcia/; fi
#	@if [ "$(PREFIX)" = "" ]; then /sbin/depmod -a $(KERNVER);\
#	else echo " *** Run '/sbin/depmod -a' to update the module database.";\
#	fi
#-Wilson
#+Wilson 03/19/2002
install:
	install -m 444 $(OFILES) /lib/modules/`uname -r`/pcmcia
#+Wilson

#-Wilson 03/20/2002
#netdrivers.tgz: Makefile *.[ch] netdrivers.spec
#	tar cfvz $@ $^

#rpm: netdrivers.tgz
#	rpm -ta $^
#-Wilson

# These are old-style CardBus drivers that don't need pci-scan and cb_shim.
cardbus: $(CARDBUS)
#-Wilson 03/20/2002
#3c575_cb.o: 3c59x.c
#	 $(CC) $(CARDBUS-FLAGS) $(CFLAGS) -c $< -o $@ 
#epic_cb.o: epic100.c
#	 $(CC) $(CARDBUS-FLAGS) $(CFLAGS) -c $< -o $@ 
#-Wilson 
realtek_cb.o: rtl8139.c
	 $(CC) $(CARDBUS-FLAGS) $(CFLAGS) -c $< -o $@ 
#-Wilson 03/20/2002
#tulip_cb.o: tulip.c
#	 $(CC) $(CARDBUS-FLAGS) $(CFLAGS) -c $< -o $@ 
#-Wilson

ChangeLog: Makefile *.[ch] netdrivers.spec
	rcs2log -h scyld.com -u "`echo -en "becker\tDonald Becker\tbecker@scyld.com"`" -u "`echo -en "pzb\tPeter Bowen\tpzb@scyld.com"`" -u "`echo -en "hendriks\tErik Arjan Hendriks\thendriks@scyld.com"`" -u "`echo -en "niles\tFredrick A. (Rick) Niles\tniles@scyld.com"`" -i 5 | sed -e 's@/home/repository/@@g' -e 's@^     \* netdrivers/@  \* netdrivers/@g' > ChangeLog

.PHONEY: all clean install cardbus tar

#+-Wilson 03/20/2002
#clean:
#	-rm -f *.o netdrivers.tgz ChangeLog
clean:
	-rm -f *.o
#+-Wilson
