1 # The remainder of this file is from Intel's e1000 distribution,
2 # with the following license:
4 ################################################################################
6 # Intel PRO/1000 Linux driver
7 # Copyright(c) 1999 - 2007 Intel Corporation.
9 # This program is free software; you can redistribute it and/or modify it
10 # under the terms and conditions of the GNU General Public License,
11 # version 2, as published by the Free Software Foundation.
13 # This program is distributed in the hope it will be useful, but WITHOUT
14 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 # You should have received a copy of the GNU General Public License along with
19 # this program; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
22 # The full GNU General Public License is included in this distribution in
23 # the file called "COPYING".
25 # Contact Information:
26 # Linux NICS <linux.nics@intel.com>
27 # e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
28 # Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 ################################################################################
31 ifeq (,$(BUILD_KERNEL))
32 BUILD_KERNEL=$(shell uname -r)
35 ###########################################################################
39 # All the places we look for kernel source
40 KSP := /lib/modules/$(BUILD_KERNEL)/build \
41 /lib/modules/$(BUILD_KERNEL)/source \
42 /usr/src/linux-$(BUILD_KERNEL) \
43 /usr/src/linux-$($(BUILD_KERNEL) | sed 's/-.*//') \
44 /usr/src/kernel-headers-$(BUILD_KERNEL) \
45 /usr/src/kernel-source-$(BUILD_KERNEL) \
46 /usr/src/linux-$($(BUILD_KERNEL) | sed 's/\([0-9]*\.[0-9]*\)\..*/\1/') \
49 # prune the list down to only values that exist
50 # and have an include/linux sub-directory
51 test_dir = $(shell [ -e $(dir)/include/linux ] && echo $(dir))
52 KSP := $(foreach dir, $(KSP), $(test_dir))
54 # we will use this first valid entry in the search path
56 KSRC := $(firstword $(KSP))
59 CFLAGS += $(CFLAGS_EXTRA)
62 $(error Linux kernel source not found)
64 ifeq (/lib/modules/$(shell uname -r)/source, $(KSRC))
65 KOBJ := /lib/modules/$(shell uname -r)/build
72 K_VERSION:=$(shell if grep -q 'PATCHLEVEL = 4' $(KSRC)/Makefile; then echo 2.4; else echo 2.6; fi)
74 ifneq ($(K_VERSION),2.4)
75 $(error Linux kernel source in $(KSRC) not 2.4)
78 # check for version.h and autoconf.h for running kernel in /boot (SUSE)
79 ifneq (,$(wildcard /boot/vmlinuz.version.h))
80 VERSION_FILE := /boot/vmlinuz.version.h
81 CONFIG_FILE := /boot/vmlinuz.autoconf.h
82 KVER := $(shell $(CC) $(CFLAGS) -E -dM $(VERSION_FILE) | \
83 grep UTS_RELEASE | awk '{ print $$3 }' | sed 's/\"//g')
84 ifeq ($(KVER),$(shell uname -r))
85 # set up include path to override headers from kernel source
86 x:=$(shell rm -rf include)
87 x:=$(shell mkdir -p include/linux)
88 x:=$(shell cp /boot/vmlinuz.version.h include/linux/version.h)
89 x:=$(shell cp /boot/vmlinuz.autoconf.h include/linux/autoconf.h)
92 ifneq (,$(wildcard $(KOBJ)/include/linux/utsrelease.h))
93 VERSION_FILE := $(KOBJ)/include/linux/utsrelease.h
95 VERSION_FILE := $(KOBJ)/include/linux/version.h
97 CONFIG_FILE := $(KSRC)/include/linux/autoconf.h
100 ifneq (,$(wildcard $(KOBJ)/include/linux/utsrelease.h))
101 VERSION_FILE := $(KOBJ)/include/linux/utsrelease.h
103 VERSION_FILE := $(KOBJ)/include/linux/version.h
105 CONFIG_FILE := $(KSRC)/include/linux/autoconf.h
108 ifeq (,$(wildcard $(VERSION_FILE)))
109 $(error Linux kernel source not configured - missing version.h)
112 ifeq (,$(wildcard $(CONFIG_FILE)))
113 $(error Linux kernel source not configured - missing autoconf.h)
117 ifeq ($(K_VERSION),2.6)
120 # Older kernels require GCC 2.95
121 K_SUBLEVEL:=$(shell sed -n 's/SUBLEVEL = // p' $(KSRC)/Makefile)
122 ifeq ($(K_SUBLEVEL),20)
125 CC := gcc-3.4 gcc-3.3 gcc-2.95
128 test_cc = $(shell $(cc) --version > /dev/null 2>&1 && echo $(cc))
129 CC := $(foreach cc, $(CC), $(test_cc))
130 CC := $(firstword $(CC))
132 $(error Compiler not found)
135 # we need to know what platform the driver is being built on
136 # some additional features are only built on Intel platforms
138 # Set the architecture if it hasn't been already set for cross-compilation
139 ARCH := $(shell uname -m | sed 's/i.86/i386/')
142 CFLAGS += -ffixed-8 -mno-fp-regs
144 ifeq ($(ARCH),x86_64)
145 CFLAGS += -mcmodel=kernel -mno-red-zone
148 CFLAGS += -msoft-float
151 CFLAGS += -m64 -msoft-float
152 LDFLAGS += -melf64ppc
155 # standard flags for module builds
156 CFLAGS += -DLINUX -D__KERNEL__ -DMODULE -O2 -pipe -Wall
157 CFLAGS += -I$(KSRC)/include -I.
158 CFLAGS += -I$(srcdir)/compat-2.4 -I$(srcdir)/compat-2.4/include
159 CFLAGS += $(shell [ -f $(KSRC)/include/linux/modversions.h ] && \
160 echo "-DMODVERSIONS -DEXPORT_SYMTAB \
161 -include $(KSRC)/include/linux/modversions.h")
163 RHC := $(KSRC)/include/linux/rhconfig.h
164 ifneq (,$(wildcard $(RHC)))
165 # 7.3 typo in rhconfig.h
166 ifneq (,$(shell $(CC) $(CFLAGS) -E -dM $(RHC) | grep __module__bigmem))
167 CFLAGS += -D__module_bigmem
171 # get the kernel version - we use this to find the correct install path
172 KVER := $(shell $(CC) $(CFLAGS) -E -dM $(VERSION_FILE) | grep UTS_RELEASE | \
173 awk '{ print $$3 }' | sed 's/\"//g')
175 # assume source symlink is the same as build, otherwise adjust KOBJ
176 ifneq (,$(wildcard /lib/modules/$(KVER)/build))
177 ifneq ($(KSRC),$(shell cd /lib/modules/$(KVER)/build ; pwd -P))
178 KOBJ=/lib/modules/$(KVER)/build
182 KKVER := $(shell echo $(KVER) | \
183 awk '{ if ($$0 ~ /2\.[4-9]\./) print "1"; else print "0"}')
185 $(error *** Aborting the build. \
186 *** This driver is not supported on kernel versions older than 2.4.0)
189 # look for SMP in config.h
190 SMP := $(shell $(CC) $(CFLAGS) -E -dM $(CONFIG_FILE) | \
191 grep -w CONFIG_SMP | awk '{ print $$3 }')
196 #ifneq ($(SMP),$(shell uname -a | grep SMP > /dev/null 2>&1 && echo 1 || echo 0))
199 # $(warning *** Warning: kernel source configuration (SMP))
200 # $(warning *** does not match running kernel (UP))
202 # $(warning *** Warning: kernel source configuration (UP))
203 # $(warning *** does not match running kernel (SMP))
205 # $(warning *** Continuing with build,)
206 # $(warning *** resulting driver may not be what you want)
214 ###########################################################################
217 # Makefile for 2.4.x kernel
218 TARGET = openflow_mod.o unit_mod.o compat24_mod.o
220 CFLAGS += -Wno-sign-compare -fno-strict-aliasing
221 CFLAGS := -I $(srcdir)/compat-2.4/include $(CFLAGS)
222 CFLAGS := -I $(srcdir)/compat-2.4/include-$(ARCH) $(CFLAGS)
226 openflow_mod.o: $(filter-out $(TARGET), $(CFILES:.c=.o))
227 $(LD) $(LDFLAGS) -r $^ -o $@
228 unit_mod.o: $(UNIT_CFILES:.c=.o)
229 $(LD) $(LDFLAGS) -r $^ -o $@
230 compat24_mod.o: $(COMPAT24_CFILES:.c=.o)
231 $(LD) $(LDFLAGS) -r $^ -o $@
233 ALL_CFILES = $(FILES) $(UNIT_CFILES) $(COMPAT24_CFILES)
234 $(ALL_CFILES:.c=.o): $(HFILES) Makefile
236 # depmod version for rpm builds
237 DEPVER := $(shell /sbin/depmod -V 2>/dev/null | \
238 awk 'BEGIN {FS="."} NR==1 {print $$2}')
243 rm -rf $(TARGET) $(TARGET:.ko=.o) $(TARGET:.ko=.mod.c)\
244 $(TARGET:.ko=.mod.o) $(CFILES:.c=.o) $(COMPAT24_CFILES:.c=.o)\
245 $(UNIT_CFILES:.c=.o) $(MANFILE).gz .*cmd .tmp_versions\
246 compat24_mod.o unit_mod.o tmp/ \