#
# Makefile 1.0 03/13/2002
#
# To make UP version of driver
#  make
# To make SMP version of driver
#  make all SMP=1

DRIVER=qla2200ip.o qla2300ip.o

HOSTTYPE := $(shell uname -m)

# Comment/uncomment the following line to enable/disable debugging
DEBUGFLAG=y
OSVER=linux-2.4

# Change it here or specify it on the "make" commandline
#(new)INCLUDEDIR = /lib/modules/`uname -r`/build/include
INCLUDEDIR = /usr/src/$(OSVER)/include

ifeq ($(DEBUGFLAG),y)
  DEBFLAGS = -O -g -DUDEBUG
else
  DEBFLAGS = -O2
endif

CFLAGS = -D__KERNEL__ -DMODULE -Wall $(DEBFLAGS)

# Handle GCC version variants 
# From linux kernel
check_gcc = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi)

# set MODVERSIONS if the kernel uses it
VERSUSED = $(shell grep 'define CONFIG_MODVERSIONS' \
                   $(INCLUDEDIR)/linux/autoconf.h | wc -l | sed 's/ //g')
VERSUSED = 1

ifeq ($(VERSUSED),1)
CFLAGS += -DMODVERSIONS -include $(INCLUDEDIR)/linux/modversions.h
endif

CFLAGS += -I$(INCLUDEDIR)

ifeq ($(HOSTTYPE),i386)
CFLAGS += $(call check_gcc,-falign-functions=2 -falign-jumps=2 -falign-loops=2,-malign-functions=2 -malign-jumps=2 -malign-loops=2)
CFLAGS += -Wall -Wstrict-prototypes -fomit-frame-pointer -fno-strength-reduce \
-pipe \
-DCONFIG_X86_LOCAL_APIC -fno-strict-aliasing -fno-common \
-mpreferred-stack-boundary=2 -march=i386
endif

ifeq ($(HOSTTYPE),i486)
CFLAGS += $(call check_gcc,-falign-functions=2 -falign-jumps=2 -falign-loops=2,-malign-functions=2 -malign-jumps=2 -malign-loops=2)
CFLAGS += -Wall -Wstrict-prototypes -fomit-frame-pointer -fno-strength-reduce \
-pipe \
-DCONFIG_X86_LOCAL_APIC -fno-strict-aliasing -fno-common \
-mpreferred-stack-boundary=2 -march=i486
endif

ifeq ($(HOSTTYPE),i586)
CFLAGS += $(call check_gcc,-falign-functions=2 -falign-jumps=2 -falign-loops=2,-malign-functions=2 -malign-jumps=2 -malign-loops=2)
CFLAGS += -Wall -Wstrict-prototypes -fomit-frame-pointer -fno-strength-reduce \
-pipe \
-DCONFIG_X86_LOCAL_APIC -fno-strict-aliasing -fno-common \
-mpreferred-stack-boundary=2 -march=i586
endif

ifeq ($(HOSTTYPE),i686)
CFLAGS += $(call check_gcc,-falign-functions=2 -falign-jumps=2 -falign-loops=2,-malign-functions=2 -malign-jumps=2 -malign-loops=2)
CFLAGS += -Wall -Wstrict-prototypes -fomit-frame-pointer -fno-strength-reduce \
-pipe \
-DCONFIG_X86_LOCAL_APIC -fno-strict-aliasing -fno-common \
-mpreferred-stack-boundary=2 -march=i686
endif

ifeq ($(HOSTTYPE),ia64)
CFLAGS += -Wall -Wstrict-prototypes -fomit-frame-pointer -fno-strength-reduce \
-pipe -DWORD_FW_LOAD
endif

ifeq ($(HOSTTYPE),alpha)
CFLAGS += -D__alpha__ \
-Wall -Wstrict-prototypes -fomit-frame-pointer -fno-strength-reduce \
-pipe  -fno-strict-aliasing -mno-fp-regs -ffixed-8 -mcpu=ev56 -Wa,-mev6
endif

ifeq ("1","$(SMP)")
CFLAGS += -D__SMP__ -DCONFIG_SMP 
endif

COFLAGS = -kv

KERNVER := $(shell uname -r)
LIBMODULES = /lib/modules/$(KERNVER)/kernel/drivers

default: $(DRIVER)

qla2200ip.o : qla_ip.h qla2xip.h qla2xip.c
	$(CC) $(CFLAGS) -DISP2200 -c qla2xip.c -o $@

qla2300ip.o : qla_ip.h qla2xip.h qla2xip.c
	$(CC) $(CFLAGS) -DISP2300 -c qla2xip.c -o $@

all:	clean $(DRIVER)

clean:	
	rm -f $(DRIVER)

install: $(DRIVER)
	install -d -o root -g root $(LIBMODULES)/net/
	install -o root -g root $(DRIVER) $(LIBMODULES)/net/
