~ubuntu-branches/ubuntu/hardy/ndiswrapper/hardy

« back to all changes in this revision

Viewing changes to driver/Makefile

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-12-07 20:42:35 UTC
  • mfrom: (1.2.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20071207204235-s43f889d3h1u6vrl
Tags: 1.50-1ubuntu1
* Merge with Debian; remaining changes:
  - Build for lpia.
  - debian/control:
    + Update description to point out that the kernel source package is
      not required with the standard Ubuntu kernel.
    + Change the Maintainer address.
  - debian/control:
    + Drop ndiswrapper-source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
                winnt_types.h workqueue.c wrapmem.h wrapmem.c wrapper.c \
6
6
                wrapndis.h wrapndis.c lin2win.h win2lin_stubs.S
7
7
 
 
8
# By default, we try to compile the modules for the currently running
 
9
# kernel.  But it's the first approximation, as we will re-read the
 
10
# version from the kernel sources.
8
11
KVERS ?= $(shell uname -r)
 
12
 
 
13
# KBUILD is the path to the Linux kernel build tree.  It is usually the
 
14
# same as the kernel source tree, except when the kernel was compiled in
 
15
# a separate directory.
 
16
KBUILD ?= $(shell readlink -f /lib/modules/$(KVERS)/build)
 
17
 
 
18
# Some old kernels only install the "source" link
 
19
ifeq (,$(KBUILD))
 
20
KBUILD := $(shell readlink -f /lib/modules/$(KVERS)/source)
 
21
endif
 
22
 
 
23
ifeq (,$(KBUILD))
 
24
$(error Kernel tree not found - please set KBUILD to configured kernel)
 
25
endif
 
26
 
 
27
# Kernel Makefile doesn't always know the exact kernel version, so we
 
28
# get it from the kernel headers instead and pass it to make.
 
29
 
 
30
VERSION_H := $(KBUILD)/include/linux/utsrelease.h
 
31
ifeq (,$(wildcard $(VERSION_H)))
 
32
VERSION_H := $(KBUILD)/include/linux/version.h
 
33
endif
 
34
ifeq (,$(wildcard $(VERSION_H)))
 
35
$(error Cannot find kernel version in $(KBUILD), is it configured?)
 
36
endif
 
37
 
 
38
KVERS := $(shell sed -ne 's/"//g;s/^\#define UTS_RELEASE //p' $(VERSION_H))
9
39
KPSUB := $(shell echo $(KVERS) | sed -e 's/\([^\.]*\)\.\([^\.]*\)\..*/\1\2/')
10
40
 
11
41
# distros use different paths for kernel include files
12
42
 
13
 
KBUILD  ?= /lib/modules/$(KVERS)/build
14
43
KSRC ?= $(shell if \
15
44
        [ -f /lib/modules/$(KVERS)/source/include/linux/kernel.h ]; then \
16
45
                echo /lib/modules/$(KVERS)/source ; \
30
59
 
31
60
KREV := $(shell echo $(KVERS) | sed -e 's/[^\.]*\.[^\.]*\.\([0-9]*\).*/\1/')
32
61
 
33
 
-include $(KBUILD)/.config
 
62
KCONFIG := $(KBUILD)/.config
 
63
ifeq (,$(wildcard $(KCONFIG)))
 
64
$(error No .config found in $(KBUILD), please set KBUILD to configured kernel)
 
65
endif
 
66
include $(KBUILD)/.config
34
67
 
35
 
CFLAGS += $(shell [ -f $(KSRC)/include/linux/modversions.h ] && \
 
68
MOD_CFLAGS += $(shell [ -f $(KSRC)/include/linux/modversions.h ] && \
36
69
                  echo -DEXPORT_SYMTAB -DMODVERSIONS \
37
70
                  -include $(KSRC)/include/linux/modversions.h)
38
71
 
39
72
ifndef DISABLE_USB
40
 
CFLAGS += $(shell if grep -q 'struct module \*owner;' \
 
73
MOD_CFLAGS += $(shell if grep -q 'struct module \*owner;' \
41
74
                   $(KSRC)/include/linux/usb.h ; then \
42
75
                        echo -DUSB_DRIVER_OWNER; \
43
76
                  fi)
44
77
endif
45
78
 
46
79
# returns of structs and unions in registers when possible, like Windows 
47
 
CFLAGS += -freg-struct-return
 
80
MOD_CFLAGS += -freg-struct-return
48
81
 
49
82
# to produce debug trace, add option "DEBUG=<n>" where <n> is 1 to 6
50
83
ifdef DEBUG
51
 
CFLAGS += -DDEBUG=$(DEBUG) -g
 
84
MOD_CFLAGS += -DDEBUG=$(DEBUG) -g
52
85
endif
53
86
 
54
87
# to debug timers, add option "TIMER_DEBUG=1 DEBUG=<n>"
55
88
ifdef TIMER_DEBUG
56
 
CFLAGS += -DTIMER_DEBUG
 
89
MOD_CFLAGS += -DTIMER_DEBUG
57
90
endif
58
91
 
59
92
# to debug event layer, add option "EVENT_DEBUG=1 DEBUG=<n>"
60
93
ifdef EVENT_DEBUG
61
 
CFLAGS += -DEVENT_DEBUG
 
94
MOD_CFLAGS += -DEVENT_DEBUG
62
95
endif
63
96
 
64
97
# to debug USB layer, add option "USB_DEBUG=1 DEBUG=<n>"
65
98
ifdef USB_DEBUG
66
 
CFLAGS += -DUSB_DEBUG
 
99
MOD_CFLAGS += -DUSB_DEBUG
67
100
endif
68
101
 
69
 
# to debug I/O layer, add option "USB_DEBUG=1 DEBUG=<n>"
 
102
# to debug I/O layer, add option "IO_DEBUG=1 DEBUG=<n>"
70
103
ifdef IO_DEBUG
71
 
CFLAGS += -DIO_DEBUG
 
104
MOD_CFLAGS += -DIO_DEBUG
72
105
endif
73
106
 
74
107
# to debug worker threads
75
108
ifdef WORK_DEBUG
76
 
CFLAGS += -DWORK_DEBUG
 
109
MOD_CFLAGS += -DWORK_DEBUG
77
110
endif
78
111
 
79
 
# if ALLOC_DEGUG=1 is defined, memory leak information is printed
80
 
#if ALLOC_DEBUG=2, details about individual allocations leaking is printed
81
 
#if ALLOC_DEBUG=3, tags in ExAllocatePoolWithTag leaking printed
 
112
# to debug memory allocation issues
82
113
ifdef ALLOC_DEBUG
83
 
CFLAGS += -DALLOC_DEBUG=$(ALLOC_DEBUG)
 
114
MOD_CFLAGS += -DALLOC_DEBUG=$(ALLOC_DEBUG)
 
115
endif
 
116
 
 
117
# emulate (pseudo) preemption
 
118
ifdef WRAP_PREEMPT
 
119
MOD_CFLAGS += -DWRAP_PREEMPT
84
120
endif
85
121
 
86
122
.PHONY: prereq_check gen_exports clean dist_clean install stack_check
87
123
 
88
 
all : prereq_check win2lin_stubs.h gen_exports default stack_check
 
124
all : prereq_check win2lin_stubs.h gen_exports compat.h default stack_check
89
125
 
90
126
OBJS := crt.o hal.o iw_ndis.o loader.o ndis.o ntoskernel.o ntoskernel_io.o \
91
127
        pe_linker.o pnp.o proc.o rtl.o wrapmem.o wrapndis.o wrapper.o
97
133
ifdef DISABLE_USB
98
134
usb_exports.h:
99
135
 
100
 
CFLAGS += -DDISABLE_USB
 
136
MOD_CFLAGS += -DDISABLE_USB
101
137
else
102
138
usb_exports.h: usb.c
103
139
 
109
145
endif
110
146
endif
111
147
 
112
 
ifeq ($(KPSUB),24)
113
 
CFLAGS += -DUSE_OWN_WQ
114
 
OBJS += workqueue.o
115
 
endif
116
 
 
117
 
CFLAGS += $(shell if grep -s -A1 'ndiswrapper' $(KSRC)/kernel/module.c | \
 
148
MOD_CFLAGS += $(shell if grep -s -A1 'ndiswrapper' $(KSRC)/kernel/module.c | \
118
149
                        grep -q 'add_taint_module' ; then \
119
150
                        echo -DUSE_OWN_WQ; \
120
151
                  fi)
121
152
 
122
 
ifdef USE_OWN_WQ
123
 
CFLAGS += -DUSE_OWN_WQ
 
153
ifdef WRAP_WQ
 
154
MOD_CFLAGS += -DWRAP_WQ
124
155
OBJS += workqueue.o
125
156
endif
126
157
 
 
158
ifdef NTOS_WQ
 
159
MOD_CFLAGS += -DNTOS_WQ
 
160
endif
 
161
 
127
162
ntoskernel.h: lin2win.h
128
163
 
129
164
ndis.h: ntoskernel.h
221
256
gen_exports: crt_exports.h ndis_exports.h hal_exports.h ntoskernel_exports.h \
222
257
                         ntoskernel_io_exports.h rtl_exports.h usb_exports.h
223
258
 
 
259
compat.h: $(KBUILD)/include/linux/version.h
 
260
        @echo "/* this file is automatically generated */" > $@
 
261
        @if ! grep -qw kzalloc $(KSRC)/include/linux/slab.h; then \
 
262
                echo "static inline void *kzalloc(size_t size, unsigned long flags)"; \
 
263
                echo "{ void *ret = kmalloc(size, flags);"; \
 
264
                echo "if (ret) memset(ret, 0, size); return ret;}"; \
 
265
        fi >> $@
 
266
        @if [ -f $(KSRC)/include/linux/netdevice.h ]; then \
 
267
                echo "#include <linux/netdevice.h>"; \
 
268
        fi >> $@
 
269
        @if ! grep -qw netif_tx_lock $(KSRC)/include/linux/netdevice.h; then \
 
270
                echo "static inline void netif_tx_lock(struct net_device *dev)"; \
 
271
                echo "{ spin_lock(&dev->xmit_lock); }"; \
 
272
                echo "static inline void netif_tx_unlock(struct net_device *dev)"; \
 
273
                echo "{ spin_unlock(&dev->xmit_lock); }"; \
 
274
                echo "static inline void netif_tx_lock_bh(struct net_device *dev)"; \
 
275
                echo "{ spin_lock_bh(&dev->xmit_lock); }"; \
 
276
                echo "static inline void netif_tx_unlock_bh(struct net_device *dev)"; \
 
277
                echo "{ spin_unlock_bh(&dev->xmit_lock); }"; \
 
278
        fi >> $@
 
279
        @if ! grep -qw netif_poll_enable $(KSRC)/include/linux/netdevice.h; then \
 
280
            echo "static inline void netif_poll_enable(struct net_device *dev) {}"; \
 
281
            echo "static inline void netif_poll_disable(struct net_device *dev) {}"; \
 
282
        fi >> $@
 
283
        @if ! grep -qw pci_set_consistent_dma_mask \
 
284
                           $(KSRC)/include/linux/pci.h; then \
 
285
                echo "static inline int pci_set_consistent_dma_mask" ; \
 
286
                echo "(struct pci_dev *dev, u64 mask) { return 0; }" ; \
 
287
        fi >> $@
 
288
        @if ! grep -qw create_workqueue $(KSRC)/include/linux/*.h; then \
 
289
                echo "#define WRAP_WQ 1"; \
 
290
        fi >> $@
 
291
        @if ! grep -qw create_workqueue $(KSRC)/include/linux/*.h; then \
 
292
                echo "#define WRAP_WQ 1"; \
 
293
        fi >> $@
 
294
        @if [ -f $(KSRC)/include/linux/percpu.h ]; then \
 
295
                echo "#include <linux/percpu.h>"; \
 
296
        fi >> $@
 
297
        @if grep -qw proc_net $(KSRC)/include/linux/proc_fs.h; then \
 
298
                echo "#define proc_net_root proc_net"; \
 
299
     else \
 
300
                echo "#define proc_net_root init_net.proc_net"; \
 
301
        fi >> $@
 
302
 
224
303
prereq_check:
225
304
        @if [ ! -f $(KBUILD)/include/linux/version.h ]; then \
226
305
                echo "Can't find kernel build files in $(KBUILD);"; \
237
316
 
238
317
clean:
239
318
        rm -rf $(MODULE) ndiswrapper.o $(OBJS) usb.o win2lin_stubs.o \
240
 
           divdi3.o workqueue.o .*.ko.cmd .*.o.cmd \
 
319
           divdi3.o workqueue.o .*.ko.cmd .*.o.cmd  compat.h \
241
320
           ndiswrapper.mod.[oc] *~ .tmp_versions Modules.symvers Module.symvers
242
321
 
243
322
distclean: clean
244
323
        rm -f *_exports.h .\#* win2lin_stubs.h built-in.o
245
324
 
246
 
ifeq ($(KPSUB),24)
247
 
 
248
 
MODULE := ndiswrapper.o
249
 
CFLAGS  += -DLINUX -D__KERNEL__ -DMODULE -I$(KSRC)/include \
250
 
                  -Wall -Wstrict-prototypes -fomit-frame-pointer    \
251
 
                  -fno-strict-aliasing -pipe -O2
252
 
 
253
 
ifneq ($(CONFIG_X86_64),y)
254
 
CFLAGS += -mpreferred-stack-boundary=2 
 
325
wflags := $(shell if grep -qw "EXTRA_CFLAGS" $(KSRC)/scripts/Makefile.build; \
 
326
                             then echo "EXTRA_CFLAGS"; else echo "CFLAGS"; fi)
 
327
 
 
328
ifeq ($(wflags), CFLAGS)
 
329
CFLAGS += $(MOD_CFLAGS)
 
330
else
 
331
EXTRA_CFLAGS += $(MOD_CFLAGS)
255
332
endif
256
 
default: $(OBJS)
257
 
        $(LD) -r -o $(MODULE) $(OBJS)
258
 
else
259
333
 
260
334
MODULE := ndiswrapper.ko
261
335
obj-m := ndiswrapper.o 
265
339
default:
266
340
        $(MAKE) -C $(KBUILD) SUBDIRS=$(SRC_DIR)
267
341
 
268
 
endif
269
342
 
270
343
stack_check:
271
344
        @if [ "x$(CONFIG_X86_64)" = "x" -a $(KPSUB) -eq 26 ] && \
272
 
             ! grep -q CONFIG_4KSTACKS $(KBUILD)/.config || \
273
345
               grep -q "CONFIG_4KSTACKS=y" $(KBUILD)/.config; then \
274
346
            echo; echo; \
275
347
            echo "*** WARNING: This kernel seems to use 4K stack size"\
279
351
            echo; echo; \
280
352
        fi
281
353
 
282
 
install: prereq_check win2lin_stubs.h gen_exports default stack_check
 
354
install: prereq_check win2lin_stubs.h gen_exports compat.h default stack_check
283
355
        echo $(INST_DIR)
284
356
        mkdir -p $(INST_DIR)
285
357
        install -m 0644 $(MODULE) $(INST_DIR)