#--------------------------------------------------------------------------------
# Copyright (c) 1999 - 2001, Intel Corporation 
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without 
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, 
#    this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
#    this list of conditions and the following disclaimer in the documentation 
#    and/or other materials provided with the distribution.
#
# 3. Neither the name of Intel Corporation nor the names of its contributors 
#    may be used to endorse or promote products derived from this software 
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
#
#--------------------------------------------------------------------------------
#   /***************************************************************************
#   **                                                                        **
#   ** INTEL CORPORATION                                                      **
#   **                                                                        **
#   ** This software is supplied under the terms of the license included      **
#   ** above.  All use of this software must be in accordance with the terms  **
#   ** of that license.                                                       **
#   **                                                                        **
#   **  Abstract:                                                             **
#   **    Makefile for Intel(R) PRO/100 LAN Adapter driver for Linux.         **
#   **                                                                        **
#   **  Environment:                                                          **
#   **    Kernel Mode (linux 2.2.x and above)                                 **
#   **                                                                        **
#   ***************************************************************************/

CC = gcc
AS = as
LD = ld
SHELL = sh
ifneq (,$(wildcard /usr/src/linux))

       INCLUDEDIR = /usr/src/linux/include
else
       INCLUDEDIR = /usr/src/linux-2.4/include
endif


VERSION_FILE = $(INCLUDEDIR)/linux/version.h
CONFIG_FILE = $(INCLUDEDIR)/linux/config.h


ifneq (,$(findstring egcs-2.91.66, $(shell cat /proc/version)))
		CC = $(shell which kgcc > /dev/null 2>&1 && echo kgcc || echo gcc)
	else
		CC = gcc
	endif




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

ifneq (,$(wildcard /lib/modules/$(KVERSION)/kernel))
	INSTDIR = /lib/modules/$(KVERSION)/kernel/drivers/net
else
	INSTDIR = /lib/modules/$(KVERSION)/net
endif
# Driver source files
TARGET = e100.o
CFILES = e100.c
HFILES = e100.h


# Required Flags
CFLAGS = -D__KERNEL__ -DMODULE -DLINUX -DEXPORT_SYMTAB -D__NO_VERSION__
CFLAGS += -I$(INCLUDEDIR) -I.
CFLAGS += -O2 -pipe

# Optional optimization flags
# LOCALDEF = -DMODULE -D__KERNEL__ -DLINUX -DCPU=686 -DCONFIG_MOD=y \
# -Wstrict-prototypes -fomit-frame-pointer -pipe -fno-strength-reduce -m486 \
# -malign-loops=2 -malign-jumps=2 -malign-functions=2
#CFLAGS += -Wall

# Check for SMP kernel
DEFAULT_SMP = 0
ifndef SMP
        SMP = $(shell test -e $(CONFIG_FILE) || echo -n $(DEFAULT_SMP))
        ifneq ($(SMP), $(DEFAULT_SMP))
                SMP = $(shell $(CC) -E -dM $(CONFIG_FILE) | grep CONFIG_SMP | awk '{ print $$3; }')
                ifneq ($(SMP), 1)
                        SMP = 0
                endif
        endif
endif
ifeq ($(SMP), 1)
	CFLAGS += -D__SMP__
endif

# Check for module versioning configured in the kernel sources
CFLAGS += $(shell [ -f $(INCLUDEDIR)/linux/modversions.h ] && echo -DMODVERSIONS)

# Adding proc FS support
CFLAGS += -DCONFIG_PROC_FS

# Adding IANS support
IA64 = $(findstring ia64, $(shell uname -m))
ifeq ($(IA64), ia64)
	ANS = NO
endif


ifneq ($(ANS), NO)
	CFLAGS += -DIANS -DIANS_BASE_VLAN_TAGGING -DIANS_BASE_VLAN_ID
	CFILES += $(wildcard ans*.c)
	HFILES += $(wildcard ans*.h base_comm.h)
endif

# Basic make rules go here

all: $(TARGET)

$(TARGET): $(filter-out $(TARGET), $(CFILES:.c=.o)) e100_main.o
	$(LD) -r $^ -o $@
	rm e100_main.o

e100_main.o: e100.c 
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $^ -o $@

install: $(TARGET)
	mkdir -p $(INSTDIR)
	install -m 644 $(TARGET) $(INSTDIR)
	depmod -a

uninstall:
	if [ -f $(INSTDIR)/$(TARGET) ]; then \
	    rm $(INSTDIR)/$(TARGET); fi
	depmod -a

clean:
	rm -f *.o *~ core

