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 CFLAGS += $(CFLAGS_EXTRA)
42 $(error Linux kernel source not found)
44 ifeq (/lib/modules/$(shell uname -r)/source, $(KSRC))
45 KOBJ := /lib/modules/$(shell uname -r)/build
51 # version 2.4 or 2.6? (we assume 2.2 isn't in use anymore
52 K_VERSION:=$(shell if grep -q 'PATCHLEVEL = 4' $(KSRC)/Makefile; then echo 2.4; else echo 2.6; fi)
54 ifneq ($(K_VERSION),2.6)
55 $(error Linux kernel source not not 2.6)
58 # check for version.h and autoconf.h for running kernel in /boot (SUSE)
59 ifneq (,$(wildcard /boot/vmlinuz.version.h))
60 VERSION_FILE := /boot/vmlinuz.version.h
61 CONFIG_FILE := /boot/vmlinuz.autoconf.h
62 KVER := $(shell $(CC) $(CFLAGS) -E -dM $(VERSION_FILE) | \
63 grep UTS_RELEASE | awk '{ print $$3 }' | sed 's/\"//g')
64 ifeq ($(KVER),$(shell uname -r))
65 # set up include path to override headers from kernel source
66 x:=$(shell rm -rf include)
67 x:=$(shell mkdir -p include/linux)
68 x:=$(shell cp /boot/vmlinuz.version.h include/linux/version.h)
69 x:=$(shell cp /boot/vmlinuz.autoconf.h include/linux/autoconf.h)
72 ifneq (,$(wildcard $(KOBJ)/include/linux/utsrelease.h))
73 VERSION_FILE := $(KOBJ)/include/linux/utsrelease.h
75 VERSION_FILE := $(KOBJ)/include/linux/version.h
77 CONFIG_FILE := $(KSRC)/include/linux/autoconf.h
80 ifneq (,$(wildcard $(KOBJ)/include/linux/utsrelease.h))
81 VERSION_FILE := $(KOBJ)/include/linux/utsrelease.h
83 VERSION_FILE := $(KOBJ)/include/linux/version.h
85 CONFIG_FILE := $(KSRC)/include/linux/autoconf.h
88 ifeq (,$(wildcard $(VERSION_FILE)))
89 $(error Linux kernel source not configured - missing version.h)
92 ifeq (,$(wildcard $(CONFIG_FILE)))
93 $(error Linux kernel source not configured - missing autoconf.h)
97 test_cc = $(shell $(cc) --version > /dev/null 2>&1 && echo $(cc))
98 CC := $(foreach cc, $(CC), $(test_cc))
99 CC := $(firstword $(CC))
101 $(error Compiler not found)
104 # we need to know what platform the driver is being built on
105 # some additional features are only built on Intel platforms
106 ARCH := $(shell uname -m | sed 's/i.86/i386/')
108 CFLAGS += -ffixed-8 -mno-fp-regs
110 ifeq ($(ARCH),x86_64)
111 CFLAGS += -mcmodel=kernel -mno-red-zone
114 CFLAGS += -msoft-float
117 CFLAGS += -m64 -msoft-float
118 LDFLAGS += -melf64ppc
121 # standard flags for module builds
122 CFLAGS += -DLINUX -D__KERNEL__ -DMODULE -O2 -pipe -Wall
123 CFLAGS += -I$(KSRC)/include -I.
124 CFLAGS += $(shell [ -f $(KSRC)/include/linux/modversions.h ] && \
125 echo "-DMODVERSIONS -DEXPORT_SYMTAB \
126 -include $(KSRC)/include/linux/modversions.h")
128 RHC := $(KSRC)/include/linux/rhconfig.h
129 ifneq (,$(wildcard $(RHC)))
130 # 7.3 typo in rhconfig.h
131 ifneq (,$(shell $(CC) $(CFLAGS) -E -dM $(RHC) | grep __module__bigmem))
132 CFLAGS += -D__module_bigmem
136 # get the kernel version - we use this to find the correct install path
137 KVER := $(shell $(CC) $(CFLAGS) -E -dM $(VERSION_FILE) | grep UTS_RELEASE | \
138 awk '{ print $$3 }' | sed 's/\"//g')
140 # assume source symlink is the same as build, otherwise adjust KOBJ
141 ifneq (,$(wildcard /lib/modules/$(KVER)/build))
142 ifneq ($(KSRC),$(shell cd /lib/modules/$(KVER)/build ; pwd -P))
143 KOBJ=/lib/modules/$(KVER)/build
147 KKVER := $(shell echo $(KVER) | \
148 awk '{ if ($$0 ~ /2\.[6]\./) print "1"; else print "0"}')
150 $(error *** Aborting the build. \
151 *** This driver is not supported on kernel versions older than 2.6.0)
154 # look for SMP in config.h
155 SMP := $(shell $(CC) $(CFLAGS) -E -dM $(CONFIG_FILE) | \
156 grep -w CONFIG_SMP | awk '{ print $$3 }')
161 #ifneq ($(SMP),$(shell uname -a | grep SMP > /dev/null 2>&1 && echo 1 || echo 0))
164 # $(warning *** Warning: kernel source configuration (SMP))
165 # $(warning *** does not match running kernel (UP))
167 # $(warning *** Warning: kernel source configuration (UP))
168 # $(warning *** does not match running kernel (SMP))
170 # $(warning *** Continuing with build,)
171 # $(warning *** resulting driver may not be what you want)
179 ###########################################################################
180 # Makefile for 2.6.x kernel
182 TARGET = openflow_mod.ko unit_mod.ko
185 $(foreach UNIT_CFILE, $(UNIT_CFILES), $(shell ln -s $(patsubst %,../t/%,$(UNIT_CFILE)) $(UNIT_CFILE)))
187 ifneq ($(PATCHLEVEL),)
188 EXTRA_CFLAGS += $(CFLAGS_EXTRA)
189 obj-m += openflow_mod.o unit_mod.o
190 openflow_mod-objs := $(CFILES:.c=.o)
191 unit_mod-objs := $(UNIT_CFILES:.c=.o)
194 ifeq ($(KOBJ),$(KSRC))
195 $(MAKE) -C $(KSRC) SUBDIRS=$(shell pwd) modules
197 $(MAKE) -C $(KSRC) O=$(KOBJ) SUBDIRS=$(shell pwd) modules
201 # depmod version for rpm builds
202 DEPVER := $(shell /sbin/depmod -V 2>/dev/null | \
203 awk 'BEGIN {FS="."} NR==1 {print $$2}')
208 rm -rf $(TARGET) $(TARGET:.ko=.o) $(TARGET:.ko=.mod.c) \
209 $(TARGET:.ko=.mod.o) $(CFILES:.c=.o) $(MANFILE).gz .*cmd \
210 .tmp_versions t/ tmp/