Initial import
[sliver-openvswitch.git] / datapath / linux-2.6-uml / kbuild.inc
1 # The remainder of this file is from Intel's e1000 distribution,
2 # with the following license:
3
4 ################################################################################
5 #
6 # Intel PRO/1000 Linux driver
7 # Copyright(c) 1999 - 2007 Intel Corporation.
8 #
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.
12 #
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
16 # more details.
17 #
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.
21 #
22 # The full GNU General Public License is included in this distribution in
23 # the file called "COPYING".
24 #
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
29 #
30 ################################################################################
31 ifeq (,$(BUILD_KERNEL))
32 BUILD_KERNEL=$(shell uname -r)
33 endif
34
35 ###########################################################################
36 # Environment tests
37
38 CC := gcc cc
39 CFLAGS += $(CFLAGS_EXTRA)
40
41 ifeq (,$(KSRC))
42   $(error Linux kernel source not found)
43 else
44 ifeq (/lib/modules/$(shell uname -r)/source, $(KSRC))
45   KOBJ :=  /lib/modules/$(shell uname -r)/build
46 else
47   KOBJ :=  $(KSRC)
48 endif
49 endif
50
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)
53
54 ifneq ($(K_VERSION),2.6)
55   $(error Linux kernel source not not 2.6)
56 endif
57
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)
70     CFLAGS += -I./include
71   else
72     ifneq (,$(wildcard $(KOBJ)/include/linux/utsrelease.h))
73       VERSION_FILE := $(KOBJ)/include/linux/utsrelease.h
74     else
75       VERSION_FILE := $(KOBJ)/include/linux/version.h
76     endif
77     CONFIG_FILE  := $(KSRC)/include/linux/autoconf.h
78   endif
79 else
80   ifneq (,$(wildcard $(KOBJ)/include/linux/utsrelease.h))
81     VERSION_FILE := $(KOBJ)/include/linux/utsrelease.h
82   else
83     VERSION_FILE := $(KOBJ)/include/linux/version.h
84   endif
85   CONFIG_FILE  := $(KSRC)/include/linux/autoconf.h
86 endif
87
88 ifeq (,$(wildcard $(VERSION_FILE)))
89   $(error Linux kernel source not configured - missing version.h)
90 endif
91
92 ifeq (,$(wildcard $(CONFIG_FILE)))
93   $(error Linux kernel source not configured - missing autoconf.h)
94 endif
95
96
97 test_cc = $(shell $(cc) --version > /dev/null 2>&1 && echo $(cc))
98 CC := $(foreach cc, $(CC), $(test_cc))
99 CC := $(firstword $(CC))
100 ifeq (,$(CC))
101   $(error Compiler not found)
102 endif
103
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/')
107 ifeq ($(ARCH),alpha)
108   CFLAGS += -ffixed-8 -mno-fp-regs
109 endif
110 ifeq ($(ARCH),x86_64)
111   CFLAGS += -mcmodel=kernel -mno-red-zone
112 endif
113 ifeq ($(ARCH),ppc)
114   CFLAGS += -msoft-float
115 endif
116 ifeq ($(ARCH),ppc64)
117   CFLAGS += -m64 -msoft-float
118   LDFLAGS += -melf64ppc
119 endif
120
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")
127
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
133   endif
134 endif
135
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')
139
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
144 endif
145 endif
146
147 KKVER := $(shell echo $(KVER) | \
148          awk '{ if ($$0 ~ /2\.[6]\./) print "1"; else print "0"}')
149 ifeq ($(KKVER), 0)
150   $(error *** Aborting the build. \
151           *** This driver is not supported on kernel versions older than 2.6.0)
152 endif
153
154 # look for SMP in config.h
155 SMP := $(shell $(CC) $(CFLAGS) -E -dM $(CONFIG_FILE) | \
156          grep -w CONFIG_SMP | awk '{ print $$3 }')
157 ifneq ($(SMP),1)
158   SMP := 0
159 endif
160
161 #ifneq ($(SMP),$(shell uname -a | grep SMP > /dev/null 2>&1 && echo 1 || echo 0))
162 #  $(warning ***)
163 #  ifeq ($(SMP),1)
164 #    $(warning *** Warning: kernel source configuration (SMP))
165 #    $(warning *** does not match running kernel (UP))
166 #  else
167 #    $(warning *** Warning: kernel source configuration (UP))
168 #    $(warning *** does not match running kernel (SMP))
169 #  endif
170 #  $(warning *** Continuing with build,)
171 #  $(warning *** resulting driver may not be what you want)
172 #  $(warning ***)
173 #endif
174
175 ifeq ($(SMP),1)
176   CFLAGS += -D__SMP__
177 endif
178
179 ###########################################################################
180 # Makefile for 2.6.x kernel
181 all: $(TARGET)
182 TARGET = openflow_mod.ko unit_mod.ko
183
184 $(UNIT_CFILES): 
185         $(foreach UNIT_CFILE, $(UNIT_CFILES), $(shell ln -s $(patsubst %,../t/%,$(UNIT_CFILE)) $(UNIT_CFILE)))
186
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)
192 else
193 default:
194 ifeq ($(KOBJ),$(KSRC))
195         $(MAKE) -C $(KSRC) SUBDIRS=$(shell pwd) modules
196 else
197         $(MAKE) -C $(KSRC) O=$(KOBJ) SUBDIRS=$(shell pwd) modules
198 endif
199 endif
200
201 # depmod version for rpm builds
202 DEPVER := $(shell /sbin/depmod -V 2>/dev/null | \
203           awk 'BEGIN {FS="."} NR==1 {print $$2}')
204
205 .PHONY: clean
206
207 clean:
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/