Debian Codegraph @

test/Makefile

raw
1 ################################################################################
2 #
3 #
4 # Copyright(c) 1999 - 2007 Intel Corporation. All rights reserved.
5 #
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the Free
8 # Software Foundation; either version 2 of the License, or (at your option)
9 # any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 # more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # this program; if not, write to the Free Software Foundation, Inc., 59
18 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #
20 # The full GNU General Public License is included in this distribution in the
21 # file called LICENSE.
22 #
23 # Contact Information:
24 # Linux NICS <[email protected]>
25 # Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 #
27 ################################################################################
28 MYDIR =$(shell echo `pwd`)
29
30 ###########################################################################
31 # Driver files
32
33 # core driver files
34 CFILES = dopanic_drv.c
35 HFILES =
36 ifeq (,$(BUILD_KERNEL))
37 BUILD_KERNEL=$(shell uname -r)
38 endif
39
40 ###########################################################################
41 # Environment tests
42
43 # Kernel Search Path
44 # All the places we look for kernel source
45 KSP := /lib/modules/$(BUILD_KERNEL)/source \
46 /lib/modules/$(BUILD_KERNEL)/build \
47 /usr/src/linux-$(BUILD_KERNEL) \
48 /usr/src/linux-$($(BUILD_KERNEL) | sed 's/-.*//') \
49 /usr/src/kernel-headers-$(BUILD_KERNEL) \
50 /usr/src/kernel-source-$(BUILD_KERNEL) \
51 /usr/src/linux-$($(BUILD_KERNEL) | sed 's/\([0-9]*\.[0-9]*\)\..*/\1/') \
52 /usr/src/linux
53
54 # prune the list down to only values that exist
55 # and have an include/linux sub-directory
56 test_dir = $(shell [ -e $(dir)/include/linux ] && echo $(dir))
57 KSP := $(foreach dir, $(KSP), $(test_dir))
58
59 # we will use this first valid entry in the search path
60 ifeq (,$(KSRC))
61 KSRC := $(firstword $(KSP))
62 endif
63
64 ifeq (,$(KSRC))
65 $(error Linux kernel source not found)
66 else
67 ifeq (/lib/modules/$(shell uname -r)/source, $(KSRC))
68 KOBJ := /lib/modules/$(shell uname -r)/build
69 else
70 KOBJ := $(KSRC)
71 endif
72 endif
73
74 # check for version.h and autoconf.h for running kernel in /boot (SUSE)
75 ifneq (,$(wildcard /boot/vmlinuz.version.h))
76 VERSION_FILE := /boot/vmlinuz.version.h
77 CONFIG_FILE := /boot/vmlinuz.autoconf.h
78 KVER := $(shell $(CC) $(CFLAGS) -E -dM $(VERSION_FILE) | \
79 grep UTS_RELEASE | awk '{ print $$3 }' | sed 's/\"//g')
80 ifeq ($(KVER),$(shell uname -r))
81 # set up include path to override headers from kernel source
82 x:=$(shell rm -rf include)
83 x:=$(shell mkdir -p include/linux)
84 x:=$(shell cp /boot/vmlinuz.version.h include/linux/version.h)
85 x:=$(shell cp /boot/vmlinuz.autoconf.h include/linux/autoconf.h)
86 CFLAGS += -I./include
87 else
88 VERSION_FILE := $(KOBJ)/include/linux/version.h
89 CONFIG_FILE := $(KSRC)/include/linux/autoconf.h
90 endif
91 else
92 VERSION_FILE := $(KOBJ)/include/linux/version.h
93 CONFIG_FILE := $(KSRC)/include/linux/autoconf.h
94 endif
95
96 ifeq (,$(wildcard $(VERSION_FILE)))
97 $(error Linux kernel source not configured - missing version.h)
98 endif
99
100 ifeq (,$(wildcard $(CONFIG_FILE)))
101 $(error Linux kernel source not configured - missing config.h)
102 endif
103
104 # pick a compiler
105 ifneq (,$(findstring egcs-2.91.66, $(shell cat /proc/version)))
106 CC := kgcc gcc cc
107 else
108 CC := gcc cc
109 endif
110 test_cc = $(shell $(cc) --version > /dev/null 2>&1 && echo $(cc))
111 CC := $(foreach cc, $(CC), $(test_cc))
112 CC := $(firstword $(CC))
113 ifeq (,$(CC))
114 $(error Compiler not found)
115 endif
116
117 # we need to know what platform the driver is being built on
118 # some additional features are only built on Intel platforms
119 ARCH := $(shell uname -m | sed 's/i.86/i386/')
120 ifeq ($(ARCH),alpha)
121 CFLAGS += -ffixed-8 -mno-fp-regs
122 endif
123 ifeq ($(ARCH),x86_64)
124 CFLAGS += -mcmodel=kernel -mno-red-zone
125 endif
126 ifeq ($(ARCH),ppc)
127 CFLAGS += -msoft-float
128 endif
129 ifeq ($(ARCH),ppc64)
130 CFLAGS += -m64 -msoft-float
131 LDFLAGS += -melf64ppc
132 endif
133
134 # standard flags for module builds
135 CFLAGS += -DLINUX -D__KERNEL__ -DMODULE -O2 -pipe -Wall
136 CFLAGS += -I$(KSRC)/include -I.
137 CFLAGS += $(shell [ -f $(KSRC)/include/linux/modversions.h ] && \
138 echo "-DMODVERSIONS -DEXPORT_SYMTAB \
139 -include $(KSRC)/include/linux/modversions.h")
140
141 CFLAGS += $(CFLAGS_EXTRA)
142 #ifeq (,$(shell echo $(CFLAGS_EXTRA) | grep NAPI))
143 #CFLAGS += -DE1000_NO_NAPI
144 #CFLAGS_EXTRA += -DE1000_NO_NAPI
145 #endif
146
147 RHC := $(KSRC)/include/linux/rhconfig.h
148 ifneq (,$(wildcard $(RHC)))
149 # 7.3 typo in rhconfig.h
150 ifneq (,$(shell $(CC) $(CFLAGS) -E -dM $(RHC) | grep __module__bigmem))
151 CFLAGS += -D__module_bigmem
152 endif
153 endif
154
155 # get the kernel version - we use this to find the correct install path
156 KVER := $(shell $(CC) $(CFLAGS) -E -dM $(VERSION_FILE) | grep UTS_RELEASE | \
157 awk '{ print $$3 }' | sed 's/\"//g')
158
159 KKVER := $(shell echo $(KVER) | \
160 awk '{ if ($$0 ~ /2\.[4-9]\./) print "1"; else print "0"}')
161 # ifeq ($(KKVER), 0)
162 # $(error *** Aborting the build. \
163 # *** This driver is not supported on kernel versions older than 2.4.0)
164 # endif
165
166 # set the install path
167 INSTDIR := /lib/modules/$(KVER)/kernel/drivers/char
168
169 # look for SMP in config.h
170 SMP := $(shell $(CC) $(CFLAGS) -E -dM $(CONFIG_FILE) | \
171 grep CONFIG_SMP | awk '{ print $$3 }')
172 ifneq ($(SMP),1)
173 SMP := 0
174 endif
175
176 ifneq ($(SMP),$(shell uname -a | grep SMP > /dev/null 2>&1 && echo 1 || echo 0))
177 $(warning ***)
178 ifeq ($(SMP),1)
179 $(warning *** Warning: kernel source configuration (SMP))
180 $(warning *** does not match running kernel (UP))
181 else
182 $(warning *** Warning: kernel source configuration (UP))
183 $(warning *** does not match running kernel (SMP))
184 endif
185 $(warning *** Continuing with build,)
186 $(warning *** resulting driver may not be what you want)
187 $(warning ***)
188 endif
189
190 ifeq ($(SMP),1)
191 CFLAGS += -D__SMP__
192 endif
193
194 # Any special handling for this driver
195
196 ###########################################################################
197 # 2.4.x & 2.6.x Specific rules
198
199 K_VERSION:=$(shell uname -r | cut -c1-3 | sed 's/2\.[56]/2\.6/')
200
201 ifeq ($(K_VERSION), 2.6)
202
203 # Makefile for 2.6.x kernel
204 TARGET = dopanic.ko
205
206 # man page
207 MANSECTION = 8
208 MANFILE = $(TARGET:.ko=.$(MANSECTION))
209 # ifeq (,$(wildcard /etc/SuSE-release))
210 # CFLAGS_DOPANIC += -I$(KSRC)/include/asm/mach-generic
211 # CFLAGS_EXTRA += $(CFLAGS_DOPANIC)
212 # endif
213
214 ifneq ($(PATCHLEVEL),)
215 EXTRA_CFLAGS += $(CFLAGS_EXTRA)
216 obj-m += dopanic.o
217 dopanic-objs := $(CFILES:.c=.o)
218 else
219 default:
220 ifeq ($(KOBJ),$(KSRC))
221 make -C $(KSRC) V=1 SUBDIRS=$(shell pwd) modules
222 else
223 make -C $(KSRC) V=1 O=$(KOBJ) SUBDIRS=$(shell pwd) modules
224 endif
225 endif
226
227 else # ifeq ($(K_VERSION),2.6)
228
229 # Makefile for 2.4.x kernel
230 TARGET = dopanic
231
232 # man page
233 MANSECTION = 8
234 MANFILE = $(TARGET:.o=.$(MANSECTION))
235
236 # Get rid of compile warnings in kernel header files from SuSE
237 ifneq (,$(wildcard /etc/SuSE-release))
238 CFLAGS += -Wno-sign-compare -fno-strict-aliasing
239 endif
240
241 # Get rid of compile warnings in kernel header files from fedora
242 ifneq (,$(wildcard /etc/fedora-release))
243 CFLAGS += -fno-strict-aliasing
244 endif
245
246 .SILENT: $(TARGET)
247 $(TARGET): $(filter-out $(TARGET), $(CFILES:.c=.o))
248 $(LD) $(LDFLAGS) -r $^ -o $@
249 echo; echo
250 echo "**************************************************"
251 echo "** $(TARGET) built for $(KVER)"
252 echo -n "** SMP "
253 if [ "$(SMP)" = "1" ]; \
254 then echo "Enabled"; else echo "Disabled"; fi
255 echo "**************************************************"
256 echo
257
258 $(CFILES:.c=.o): $(HFILES) Makefile
259 default:
260 echo "** CFLAGS = $(CFLAGS)"
261 make
262
263 endif # ifeq ($(K_VERSION),2.6)
264
265 ifeq (,$(MANDIR))
266 # find the best place to install the man page
267 MANPATH := $(shell (manpath 2>/dev/null || echo $MANPATH) | sed 's/:/ /g')
268 ifneq (,$(MANPATH))
269 # test based on inclusion in MANPATH
270 test_dir = $(findstring $(dir), $(MANPATH))
271 else
272 # no MANPATH, test based on directory existence
273 test_dir = $(shell [ -e $(dir) ] && echo $(dir))
274 endif
275 # our preferred install path
276 # should /usr/local/man be in here ?
277 MANDIR := /usr/share/man /usr/man
278 MANDIR := $(foreach dir, $(MANDIR), $(test_dir))
279 MANDIR := $(firstword $(MANDIR))
280 endif
281 ifeq (,$(MANDIR))
282 # fallback to /usr/man
283 MANDIR := /usr/man
284 endif
285
286 # depmod version for rpm builds
287 DEPVER := $(shell /sbin/depmod -V 2>/dev/null | \
288 awk 'BEGIN {FS="."} NR==1 {print $$2}')
289
290 ###########################################################################
291 # Build rules
292
293 $(MANFILE).gz: ../$(MANFILE)
294 gzip -c $< > $@
295
296 install: default $(MANFILE).gz
297 # remove all old versions of the driver
298 find $(INSTALL_MOD_PATH)/lib/modules/$(KVER) -name $(TARGET) -exec rm -f {} \; || true
299 find $(INSTALL_MOD_PATH)/lib/modules/$(KVER) -name $(TARGET).gz -exec rm -f {} \; || true
300 install -D -m 644 $(TARGET) $(INSTALL_MOD_PATH)$(INSTDIR)/$(TARGET)
301 ifeq (,$(INSTALL_MOD_PATH))
302 /sbin/depmod -a || true
303 else
304 ifeq ($(DEPVER),1 )
305 /sbin/depmod -r $(INSTALL_MOD_PATH) -a || true
306 else
307 /sbin/depmod -b $(INSTALL_MOD_PATH) -a -n > /dev/null || true
308 endif
309 endif
310 install -D -m 644 $(MANFILE).gz $(INSTALL_MOD_PATH)$(MANDIR)/man$(MANSECTION)/$(MANFILE).gz
311 man -c -P'cat > /dev/null' $(MANFILE:.$(MANSECTION)=) || true
312
313 uninstall:
314 if [ -e $(INSTDIR)/$(TARGET) ] ; then \
315 rm -f $(INSTDIR)/$(TARGET) ; \
316 fi
317 /sbin/depmod -a
318 if [ -e $(MANDIR)/man$(MANSECTION)/$(MANFILE).gz ] ; then \
319 rm -f $(MANDIR)/man$(MANSECTION)/$(MANFILE).gz ; \
320 fi
321
322 .PHONY: clean install
323
324 clean:
325 rm -rf $(TARGET) $(TARGET:.ko=.o) $(TARGET:.ko=.mod.c) $(TARGET:.ko=.mod.o) $(CFILES:.c=.o) $(MANFILE).gz .*cmd .tmp_versions