#***************************************************************************
# 
# Makefile for 3Com's Linux driver for 3c990 series Network Interface Cards 
#
#***************************************************************************

#
# Source file name
#
SRC = 3c990.c

#
# Target file name
#
TARGET = 3c990.o

#
# Include file name
#
INCLUDE = 3c990img.h 3c990.h

#
# Compiler 
#
CC = gcc

#
# Compiler flags
#
CFLAGS = -c -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O2 

#
# MODVersions setting
#
CFLAGS += $(shell [ -f $(INCLUDE_DIR)/linux/modversions.h ] && echo -DMODVERSIONS)

#
# Include directory
#
ifneq (,$(wildcard /usr/src/linux))
INCLUDE_DIR = /usr/src/linux/include
else
INCLUDE_DIR = /usr/src/linux-2.4/include
endif

#
# Version file 
#
VERSION_FILE = $(INCLUDE_DIR)/linux/version.h

# Get the kernel version from version.h
KERNEL_VER = $(shell gcc -E -dM $(VERSION_FILE) | grep UTS | awk '{ print $$3; }' | sed -e 's/\"//g')

ifneq (,$(wildcard /lib/modules/$(KERNEL_VER)/kernel))
	INSTALL_DIR = /lib/modules/$(KERNEL_VER)/kernel/drivers/net
else
	INSTALL_DIR = /lib/modules/$(KERNEL_VER)/net
endif

#
# SMP Configuration
#
CONFIG_FILE = $(INCLUDE_DIR)/linux/autoconf.h
SMP_FLAG = $(shell gcc -E -dM $(CONFIG_FILE) | grep CONFIG_SMP | awk '{print $$3; }')

ifeq ($(SMP_FLAG), 1)
	CFLAGS += -D__SMP__
endif

#
# Target generation
# 
$(TARGET): $(SRC) $(INCLUDE)
	gcc $(CFLAGS) -I$(INCLUDE_DIR) $(MOD_VERSION) $(SRC) 

#
# Module installation
# 
install: $(TARGET)
	@echo "Found kernel version $(KERNEL_VER)"
	@echo "Install directory is $(INSTALL_DIR)"
	mkdir -p $(INSTALL_DIR)
	install -m 644 $(TARGET) $(INSTALL_DIR)
	depmod -a


#
# Module uninstallation
#
uninstall:
	@echo "Removing Module from $(INSTALL_DIR)"
	rm -f $(INSTALL_DIR)/$(TARGET)
	depmod -a

#
# Module loading
#
load: $(TARGET)
	insmod $(TARGET)

#
# Cleanup
#
clean:
	rm -f *.o


