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 ###########################################################################
43 $(error Linux kernel source not found)
45 ifeq (/lib/modules/$(shell uname -r)/source, $(KSRC))
46 KOBJ := /lib/modules/$(shell uname -r)/build
52 # version 2.4 or 2.6? (we assume 2.2 isn't in use anymore
53 K_VERSION:=$(shell if grep -q 'PATCHLEVEL = 4' $(KSRC)/Makefile; then echo 2.4; else echo 2.6; fi)
55 ifneq ($(K_VERSION),2.6)
56 $(error Linux kernel source not not 2.6)
59 # check for version.h and autoconf.h for running kernel in /boot (SUSE)
60 ifneq (,$(wildcard /boot/vmlinuz.version.h))
61 VERSION_FILE := /boot/vmlinuz.version.h
62 CONFIG_FILE := /boot/vmlinuz.autoconf.h
63 KVER := $(shell $(CC) $(EXTRA_CFLAGS) -E -dM $(VERSION_FILE) | \
64 grep UTS_RELEASE | awk '{ print $$3 }' | sed 's/\"//g')
65 ifeq ($(KVER),$(shell uname -r))
66 # set up include path to override headers from kernel source
67 x:=$(shell rm -rf include)
68 x:=$(shell mkdir -p include/linux)
69 x:=$(shell cp /boot/vmlinuz.version.h include/linux/version.h)
70 x:=$(shell cp /boot/vmlinuz.autoconf.h include/linux/autoconf.h)
71 EXTRA_CFLAGS += -I./include
73 ifneq (,$(wildcard $(KOBJ)/include/linux/utsrelease.h))
74 VERSION_FILE := $(KOBJ)/include/linux/utsrelease.h
76 VERSION_FILE := $(KOBJ)/include/linux/version.h
78 CONFIG_FILE := $(KSRC)/include/linux/autoconf.h
81 ifneq (,$(wildcard $(KOBJ)/include/linux/utsrelease.h))
82 VERSION_FILE := $(KOBJ)/include/linux/utsrelease.h
84 VERSION_FILE := $(KOBJ)/include/linux/version.h
86 CONFIG_FILE := $(KSRC)/include/linux/autoconf.h
89 ifeq (,$(wildcard $(VERSION_FILE)))
90 $(error Linux kernel source not configured - missing version.h)
93 ifeq (,$(wildcard $(CONFIG_FILE)))
94 $(error Linux kernel source not configured - missing autoconf.h)
98 test_cc = $(shell $(cc) --version > /dev/null 2>&1 && echo $(cc))
99 CC := $(foreach cc, $(CC), $(test_cc))
100 CC := $(firstword $(CC))
102 $(error Compiler not found)
105 # we need to know what platform the driver is being built on
106 # some additional features are only built on Intel platforms
108 # Set the architecture if it hasn't been already set for cross-compilation
109 ARCH := $(shell uname -m | sed 's/i.86/i386/')
112 EXTRA_CFLAGS += -ffixed-8 -mno-fp-regs
114 ifeq ($(ARCH),x86_64)
115 EXTRA_CFLAGS += -mcmodel=kernel -mno-red-zone
118 EXTRA_CFLAGS += -msoft-float
121 EXTRA_CFLAGS += -m64 -msoft-float
122 LDFLAGS += -melf64ppc
125 # standard flags for module builds
126 EXTRA_CFLAGS += -DLINUX -D__KERNEL__ -DMODULE -O2 -pipe -Wall
127 NOSTDINC_FLAGS += -I$(srcdir)/compat-2.6 -I$(srcdir)/compat-2.6/include
128 EXTRA_CFLAGS += $(shell [ -f $(KSRC)/include/linux/modversions.h ] && \
129 echo "-DMODVERSIONS -DEXPORT_SYMTAB \
130 -include $(KSRC)/include/linux/modversions.h")
132 RHC := $(KSRC)/include/linux/rhconfig.h
133 ifneq (,$(wildcard $(RHC)))
134 # 7.3 typo in rhconfig.h
135 ifneq (,$(shell $(CC) $(EXTRA_CFLAGS) -E -dM $(RHC) | grep __module__bigmem))
136 EXTRA_CFLAGS += -D__module_bigmem
140 # get the kernel version - we use this to find the correct install path
141 KVER := $(shell $(CC) $(EXTRA_CFLAGS) -E -dM $(VERSION_FILE) | grep UTS_RELEASE | \
142 awk '{ print $$3 }' | sed 's/\"//g')
144 # assume source symlink is the same as build, otherwise adjust KOBJ
145 ifneq (,$(wildcard /lib/modules/$(KVER)/build))
146 ifneq ($(KSRC),$(shell cd /lib/modules/$(KVER)/build ; pwd -P))
147 KOBJ=/lib/modules/$(KVER)/build
151 KKVER := $(shell echo $(KVER) | \
152 awk '{ if ($$0 ~ /2\.[6]\./) print "1"; else print "0"}')
154 $(error *** Aborting the build. \
155 *** This driver is not supported on kernel versions older than 2.6.0)
158 # look for SMP in config.h
159 SMP := $(shell $(CC) $(EXTRA_CFLAGS) -E -dM $(CONFIG_FILE) | \
160 grep -w CONFIG_SMP | awk '{ print $$3 }')
165 #ifneq ($(SMP),$(shell uname -a | grep SMP > /dev/null 2>&1 && echo 1 || echo 0))
168 # $(warning *** Warning: kernel source configuration (SMP))
169 # $(warning *** does not match running kernel (UP))
171 # $(warning *** Warning: kernel source configuration (UP))
172 # $(warning *** does not match running kernel (SMP))
174 # $(warning *** Continuing with build,)
175 # $(warning *** resulting driver may not be what you want)
180 EXTRA_CFLAGS += -D__SMP__
183 ###########################################################################
184 # Makefile for 2.6.x kernel
186 TARGET = openflow_mod.ko unit_mod.ko
189 $(foreach UNIT_CFILE, $(UNIT_CFILES), $(shell ln -s $(patsubst %,../t/%,$(UNIT_CFILE)) $(UNIT_CFILE)))
191 ifneq ($(PATCHLEVEL),)
192 EXTRA_CFLAGS += $(CFLAGS_EXTRA)
193 obj-m += openflow_mod.o unit_mod.o
194 openflow_mod-objs := $(CFILES:.c=.o)
195 unit_mod-objs := $(UNIT_CFILES:.c=.o)
198 ifeq ($(KOBJ),$(KSRC))
199 $(MAKE) -C $(KSRC) SUBDIRS=$(shell pwd) modules
201 $(MAKE) -C $(KSRC) O=$(KOBJ) SUBDIRS=$(shell pwd) modules
205 # depmod version for rpm builds
206 DEPVER := $(shell /sbin/depmod -V 2>/dev/null | \
207 awk 'BEGIN {FS="."} NR==1 {print $$2}')
212 rm -rf $(TARGET) $(TARGET:.ko=.o) $(TARGET:.ko=.mod.c) \
213 $(TARGET:.ko=.mod.o) $(CFILES:.c=.o) $(MANFILE).gz .*cmd \
214 .tmp_versions t/ *.o tmp/