~ubuntu-branches/ubuntu/jaunty/ndiswrapper/jaunty

« back to all changes in this revision

Viewing changes to driver/Makefile

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2008-11-21 14:17:35 UTC
  • mfrom: (1.2.11 upstream) (2.1.3 lenny)
  • Revision ID: james.westby@ubuntu.com-20081121141735-hzymcfoy3up8hego
Tags: 1.53-2ubuntu1
* 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:
1
 
DISTFILES=divdi3.c hal.c iw_ndis.c iw_ndis.h loader.c loader.h \
2
 
                longlong.h Makefile crt.c ndis.c ndis.h \
3
 
                ndiswrapper.h ntoskernel.c ntoskernel.h ntoskernel_io.c \
4
 
                pe_linker.c pe_linker.h pnp.c pnp.h proc.c rtl.c usb.c usb.h \
5
 
                winnt_types.h workqueue.c wrapmem.h wrapmem.c wrapper.c \
6
 
                wrapndis.h wrapndis.c lin2win.h win2lin_stubs.S
 
1
# Name of the module
 
2
MODNAME = ndiswrapper
 
3
 
 
4
DISTFILES = \
 
5
        Makefile crt.c divdi3.c hal.c iw_ndis.c iw_ndis.h lin2win.h loader.c \
 
6
        loader.h longlong.h mkexport.sh mkstubs.sh ndis.c ndis.h \
 
7
        ndiswrapper.h ntoskernel.c ntoskernel.h ntoskernel_io.c pe_linker.c \
 
8
        pe_linker.h pnp.c pnp.h proc.c rtl.c usb.c usb.h win2lin_stubs.S \
 
9
        winnt_types.h workqueue.c wrapmem.h wrapmem.c wrapper.c wrapper.h \
 
10
        wrapndis.c wrapndis.h
7
11
 
8
12
# By default, we try to compile the modules for the currently running
9
13
# kernel.  But it's the first approximation, as we will re-read the
15
19
# a separate directory.
16
20
KBUILD ?= $(shell readlink -f /lib/modules/$(KVERS)/build)
17
21
 
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
22
ifeq (,$(KBUILD))
24
23
$(error Kernel tree not found - please set KBUILD to configured kernel)
25
24
endif
36
35
endif
37
36
 
38
37
KVERS := $(shell sed -ne 's/"//g;s/^\#define UTS_RELEASE //p' $(VERSION_H))
39
 
KPSUB := $(shell echo $(KVERS) | sed -e 's/\([^\.]*\)\.\([^\.]*\)\..*/\1\2/')
40
 
 
41
 
# distros use different paths for kernel include files
42
 
 
43
 
KSRC ?= $(shell if \
44
 
        [ -f /lib/modules/$(KVERS)/source/include/linux/kernel.h ]; then \
45
 
                echo /lib/modules/$(KVERS)/source ; \
46
 
        else \
47
 
                echo $(KBUILD); \
48
 
        fi)
49
38
 
50
39
ifdef DIST_DESTDIR
51
40
DESTDIR = $(DIST_DESTDIR)
57
46
 
58
47
SRC_DIR=$(shell pwd)
59
48
 
60
 
KREV := $(shell echo $(KVERS) | sed -e 's/[^\.]*\.[^\.]*\.\([0-9]*\).*/\1/')
61
 
 
62
49
KCONFIG := $(KBUILD)/.config
63
50
ifeq (,$(wildcard $(KCONFIG)))
64
51
$(error No .config found in $(KBUILD), please set KBUILD to configured kernel)
65
52
endif
66
53
include $(KBUILD)/.config
67
54
 
68
 
MOD_CFLAGS += $(shell [ -f $(KSRC)/include/linux/modversions.h ] && \
69
 
                  echo -DEXPORT_SYMTAB -DMODVERSIONS \
70
 
                  -include $(KSRC)/include/linux/modversions.h)
71
 
 
72
 
ifndef DISABLE_USB
73
 
MOD_CFLAGS += $(shell if grep -q 'struct module \*owner;' \
74
 
                   $(KSRC)/include/linux/usb.h ; then \
75
 
                        echo -DUSB_DRIVER_OWNER; \
76
 
                  fi)
77
 
endif
78
 
 
79
55
# returns of structs and unions in registers when possible, like Windows 
80
 
MOD_CFLAGS += -freg-struct-return
 
56
EXTRA_CFLAGS += -freg-struct-return
81
57
 
82
58
# to produce debug trace, add option "DEBUG=<n>" where <n> is 1 to 6
83
59
ifdef DEBUG
84
 
MOD_CFLAGS += -DDEBUG=$(DEBUG) -g
 
60
EXTRA_CFLAGS += -DDEBUG=$(DEBUG) -g
85
61
endif
86
62
 
87
63
# to debug timers, add option "TIMER_DEBUG=1 DEBUG=<n>"
88
64
ifdef TIMER_DEBUG
89
 
MOD_CFLAGS += -DTIMER_DEBUG
 
65
EXTRA_CFLAGS += -DTIMER_DEBUG
90
66
endif
91
67
 
92
68
# to debug event layer, add option "EVENT_DEBUG=1 DEBUG=<n>"
93
69
ifdef EVENT_DEBUG
94
 
MOD_CFLAGS += -DEVENT_DEBUG
 
70
EXTRA_CFLAGS += -DEVENT_DEBUG
95
71
endif
96
72
 
97
73
# to debug USB layer, add option "USB_DEBUG=1 DEBUG=<n>"
98
74
ifdef USB_DEBUG
99
 
MOD_CFLAGS += -DUSB_DEBUG
 
75
EXTRA_CFLAGS += -DUSB_DEBUG
100
76
endif
101
77
 
102
78
# to debug I/O layer, add option "IO_DEBUG=1 DEBUG=<n>"
103
79
ifdef IO_DEBUG
104
 
MOD_CFLAGS += -DIO_DEBUG
 
80
EXTRA_CFLAGS += -DIO_DEBUG
105
81
endif
106
82
 
107
83
# to debug worker threads
108
84
ifdef WORK_DEBUG
109
 
MOD_CFLAGS += -DWORK_DEBUG
 
85
EXTRA_CFLAGS += -DWORK_DEBUG
110
86
endif
111
87
 
112
88
# to debug memory allocation issues
113
89
ifdef ALLOC_DEBUG
114
 
MOD_CFLAGS += -DALLOC_DEBUG=$(ALLOC_DEBUG)
 
90
EXTRA_CFLAGS += -DALLOC_DEBUG=$(ALLOC_DEBUG)
115
91
endif
116
92
 
117
93
# emulate (pseudo) preemption
118
94
ifdef WRAP_PREEMPT
119
 
MOD_CFLAGS += -DWRAP_PREEMPT
 
95
EXTRA_CFLAGS += -DWRAP_PREEMPT
120
96
endif
121
97
 
122
 
.PHONY: prereq_check gen_exports clean dist_clean install stack_check
123
 
 
124
 
all : prereq_check win2lin_stubs.h gen_exports compat.h default stack_check
125
 
 
126
 
OBJS := crt.o hal.o iw_ndis.o loader.o ndis.o ntoskernel.o ntoskernel_io.o \
 
98
OBJS = crt.o hal.o iw_ndis.o loader.o ndis.o ntoskernel.o ntoskernel_io.o \
127
99
        pe_linker.o pnp.o proc.o rtl.o wrapmem.o wrapndis.o wrapper.o
128
100
 
129
 
# by default, USB layer is compiled in if USB support is in kernel;
 
101
EXPORTS = crt_exports.h hal_exports.h ndis_exports.h ntoskernel_exports.h \
 
102
        ntoskernel_io_exports.h rtl_exports.h
 
103
 
 
104
STUB_SRCS = crt.c hal.c ndis.c ntoskernel.c ntoskernel_io.c \
 
105
        pnp.c rtl.c wrapndis.c
 
106
 
 
107
 
 
108
# By default, USB layer is compiled in if USB support is in kernel;
130
109
# to disable USB support in ndiswrapper even if USB support is in kenrel,
131
110
# add option "DISABLE_USB=1"
132
 
 
133
 
ifdef DISABLE_USB
134
 
usb_exports.h:
135
 
 
136
 
MOD_CFLAGS += -DDISABLE_USB
137
 
else
138
 
usb_exports.h: usb.c
139
 
 
 
111
ifndef DISABLE_USB
140
112
ifeq ($(CONFIG_USB),y)
141
 
OBJS += usb.o
 
113
ENABLE_USB = 1
142
114
endif
143
115
ifeq ($(CONFIG_USB),m)
 
116
ENABLE_USB = 1
 
117
endif
 
118
endif
 
119
 
 
120
ifdef ENABLE_USB
 
121
EXPORTS += usb_exports.h
 
122
STUB_SRCS += usb.c
144
123
OBJS += usb.o
145
 
endif
146
 
endif
147
 
 
148
 
MOD_CFLAGS += $(shell if grep -s -A1 'ndiswrapper' $(KSRC)/kernel/module.c | \
149
 
                        grep -q 'add_taint_module' ; then \
150
 
                        echo -DUSE_OWN_WQ; \
151
 
                  fi)
 
124
EXTRA_CFLAGS += -DENABLE_USB
 
125
endif
152
126
 
153
127
ifdef WRAP_WQ
154
 
MOD_CFLAGS += -DWRAP_WQ
 
128
EXTRA_CFLAGS += -DWRAP_WQ
155
129
OBJS += workqueue.o
156
130
endif
157
131
 
158
 
ifdef NTOS_WQ
159
 
MOD_CFLAGS += -DNTOS_WQ
160
 
endif
161
 
 
162
 
ntoskernel.h: lin2win.h
163
 
 
164
 
ndis.h: ntoskernel.h
165
 
 
166
 
iw_ndis.h: ntoskernel.h
167
 
 
168
 
pnp.h: ntoskernel.h ndis.h
169
 
 
170
 
wrapndis.h: ndis.h pnp.h
171
 
 
172
 
usb.h: ntoskernel.h
173
 
 
174
 
divdi3.o: divdi3.c longlong.h
175
 
 
176
 
hal.o: hal.c ntoskernel.h
177
 
 
178
 
iw_ndis.o: iw_ndis.c iw_ndis.h wrapndis.h
179
 
 
180
 
loader.o: loader.c loader.h ndis.h wrapndis.h
181
 
 
182
 
crt.o: crt.c ndis.h
183
 
 
184
 
ndis.o: ndis.c ndis.h iw_ndis.h wrapndis.h
185
 
 
186
 
wrapndis.o: wrapndis.c wrapndis.h
187
 
 
188
 
ntoskernel.o: ntoskernel.c ndis.h usb.h
189
 
 
190
 
ntoskernel_io.o: ntoskernel_io.c ndis.h usb.h
191
 
 
192
 
pe_linker.o: pe_linker.c
193
 
 
194
 
pnp.o: pnp.c
195
 
 
196
 
proc.o: proc.c ndis.h iw_ndis.h wrapndis.h
197
 
 
198
 
rtl.o: rtl.c ndis.h
199
 
 
200
 
usb.o: usb.c usb.h ndis.h
201
 
 
202
 
wrapper.o: wrapper.c wrapndis.h iw_ndis.h ntoskernel.h loader.h
 
132
 
 
133
all: config_check modules
 
134
 
 
135
# generate exports symbol table from C files
 
136
quiet_cmd_mkexport = MKEXPORT $@
 
137
cmd_mkexport = $(SHELL) $(obj)/mkexport.sh $< $@
 
138
 
 
139
%_exports.h: %.c $(obj)/mkexport.sh FORCE
 
140
        $(call if_changed,mkexport)
 
141
 
 
142
extra-y := $(EXPORTS)
203
143
 
204
144
ifeq ($(CONFIG_X86_64),y)
 
145
quiet_cmd_mkstubs = MKSTUBS $@
 
146
cmd_mkstubs = $(SHELL) $(obj)/mkstubs.sh $(addprefix $(src)/,$(STUB_SRCS)) >$@
 
147
 
 
148
$(obj)/win2lin_stubs.h: $(addprefix $(src)/,$(STUB_SRCS)) FORCE
 
149
        $(call if_changed,mkstubs)
 
150
 
 
151
extra-y += win2lin_stubs.h
205
152
OBJS += win2lin_stubs.o
206
 
win2lin_stubs.o: win2lin_stubs.h win2lin_stubs.S
207
 
 
208
 
ifdef DISABLE_USB
209
 
win2lin_stubs.h: hal.c crt.c ndis.c ntoskernel.c ntoskernel_io.c \
210
 
        pnp.c rtl.c wrapndis.c
211
 
else
212
 
win2lin_stubs.h: hal.c crt.c ndis.c ntoskernel.c ntoskernel_io.c \
213
 
        pnp.c rtl.c usb.c wrapndis.c
214
 
endif
215
 
        @for file in $^; do \
216
 
                echo; \
217
 
                echo "# automatically generated from $$file"; \
218
 
                sed -n \
219
 
                        -e 's/.*WIN_FUNC(\([^\,]\+\) *\, *\([0-9]\+\)).*/\
220
 
                           win2lin(\1, \2)/p'   \
221
 
                        -e 's/.*WIN_FUNC_PTR(\([^\,]\+\) *\, *\([0-9]\+\)).*/\
222
 
                           win2lin(\1, \2)/p'   \
223
 
                   $$file | sed -e 's/[ \t      ]\+//' | sort -u; \
224
 
        done > $@
225
 
else
226
 
win2lin_stubs.h:
227
 
 
 
153
else
228
154
OBJS += divdi3.o
229
155
endif
230
156
 
231
 
# generate exports symbol table from C files
232
 
%_exports.h: %.c
233
 
        @if :; then \
234
 
                echo "/* automatically generated from $< */"; \
235
 
                echo "#ifdef CONFIG_X86_64"; \
236
 
                sed -n \
237
 
                        -e 's/.*WIN_FUNC(\([^\,]\+\) *\, *\([0-9]\+\)).*/\
238
 
                           WIN_FUNC_DECL(\1, \2)/p' \
239
 
                        -e 's/.*WIN_FUNC_PTR(\([^\,]\+\) *\, *\([0-9]\+\)).*/\
240
 
                           WIN_FUNC_DECL(\1, \2)/p' \
241
 
                   $< | sed -e 's/[ \t  ]\+//' | sort -u; \
242
 
                echo "#endif"; \
243
 
                echo "struct wrap_export $(basename $<)_exports[] = {";\
244
 
                sed -n \
245
 
                        -e 's/.*WIN_FUNC(_win_\([^\,]\+\) *\, *\([0-9]\+\)).*/\
246
 
                                WIN_WIN_SYMBOL(\1,\2),/p' \
247
 
                        -e 's/.*WIN_FUNC(\([^\,]\+\) *\, *\([0-9]\+\)).*/\
248
 
                                WIN_SYMBOL(\1,\2),/p' \
249
 
                        -e 's/.*WIN_SYMBOL_MAP(\("[^"]\+"\)[ ,\n]\+\([^)]\+\)).*/\
250
 
                                {\1,(generic_func)\2},/p'  \
251
 
                           $< | sed -e 's/[ \t  ]*/   /' | sort -u; \
252
 
                echo "   {NULL, NULL}"; \
253
 
                echo "};"; \
254
 
        fi > $@
255
 
 
256
 
gen_exports: crt_exports.h ndis_exports.h hal_exports.h ntoskernel_exports.h \
257
 
                         ntoskernel_io_exports.h rtl_exports.h usb_exports.h
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
 
 
303
 
prereq_check:
 
157
MODULE := $(MODNAME).ko
 
158
obj-m := $(MODNAME).o
 
159
 
 
160
$(MODNAME)-objs := $(OBJS)
 
161
 
 
162
 
 
163
config_check:
304
164
        @if [ ! -f $(KBUILD)/include/linux/version.h ]; then \
305
 
                echo "Can't find kernel build files in $(KBUILD);"; \
306
 
                echo "  give the path to kernel build directory with " ; \
307
 
                echo "  KBUILD=<path> argument to make";\
308
 
                exit 1;\
309
 
        fi
310
 
        @if [ ! -f $(KSRC)/include/linux/kernel.h ]; then \
311
 
                echo "Can't find kernel build files in $(KSRC);"; \
312
 
                echo "  give the path to kernel build directory with " ; \
313
 
                echo "  KSRC=<path> argument to make";\
314
 
                exit 1;\
315
 
        fi
 
165
                echo; echo; \
 
166
                echo "Cannot find kernel build files in $(KBUILD)"; \
 
167
                echo "Please give the path to kernel build directory with" ; \
 
168
                echo "the KBUILD=<path> argument to make";\
 
169
                echo; echo; \
 
170
                exit 1; \
 
171
        fi
 
172
        @if [ -z "$(CONFIG_WIRELESS_EXT)$(CONFIG_NET_RADIO)" ]; then \
 
173
                echo; echo; \
 
174
                echo "*** WARNING: This kernel lacks wireless extensions."; \
 
175
                echo "Wireless drivers will not work properly."; \
 
176
                echo; echo; \
 
177
        fi
 
178
        @if [ -z "$(CONFIG_X86_64)" ] && [ -n "$(CONFIG_4KSTACKS)" ]; then \
 
179
                echo; echo; \
 
180
                echo "*** WARNING: This kernel uses 4K stack size option"; \
 
181
                echo "(CONFIG_4KSTACKS); many Windows drivers will not work"; \
 
182
                echo "with this option enabled. Disable CONFIG_4KSTACKS"; \
 
183
                echo "in kernel's .config file, recompile and install kernel"; \
 
184
                echo; echo; \
 
185
        fi
 
186
 
 
187
modules:
 
188
        $(MAKE) -C $(KBUILD) M=$(SRC_DIR)
316
189
 
317
190
clean:
318
 
        rm -rf $(MODULE) ndiswrapper.o $(OBJS) usb.o win2lin_stubs.o \
319
 
           divdi3.o workqueue.o .*.ko.cmd .*.o.cmd  compat.h \
320
 
           ndiswrapper.mod.[oc] *~ .tmp_versions Modules.symvers Module.symvers
321
 
 
322
 
distclean: clean
323
 
        rm -f *_exports.h .\#* win2lin_stubs.h built-in.o
324
 
 
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)
332
 
endif
333
 
 
334
 
MODULE := ndiswrapper.ko
335
 
obj-m := ndiswrapper.o 
336
 
 
337
 
ndiswrapper-objs := $(OBJS)
338
 
 
339
 
default:
340
 
        $(MAKE) -C $(KBUILD) SUBDIRS=$(SRC_DIR)
341
 
 
342
 
 
343
 
stack_check:
344
 
        @if [ "x$(CONFIG_X86_64)" = "x" -a $(KPSUB) -eq 26 ] && \
345
 
               grep -q "CONFIG_4KSTACKS=y" $(KBUILD)/.config; then \
346
 
            echo; echo; \
347
 
            echo "*** WARNING: This kernel seems to use 4K stack size"\
348
 
                 "option (CONFIG_4KSTACKS); many Windows drivers will"\
349
 
                 "not work with this option enabled. Disable"\
350
 
                 "CONFIG_4KSTACKS option, recompile and install kernel";\
351
 
            echo; echo; \
352
 
        fi
353
 
 
354
 
install: prereq_check win2lin_stubs.h gen_exports compat.h default stack_check
 
191
        rm -f *.o *.ko .*.cmd *.mod.c *.symvers modules.order *~ .\#*
 
192
        rm -f *_exports.h win2lin_stubs.h
 
193
        rm -rf .tmp_versions
 
194
 
 
195
install: config_check modules
355
196
        echo $(INST_DIR)
356
197
        mkdir -p $(INST_DIR)
357
198
        install -m 0644 $(MODULE) $(INST_DIR)
358
 
        -@/bin/rm -rf $(SRC_DIR)/.tmp_versions
359
199
ifndef DIST_DESTDIR
360
200
        -/sbin/depmod -a $(KVERS) -b $(DESTDIR)
361
201
endif
362
202
 
363
203
dist:
364
204
        @for file in $(DISTFILES); do \
365
 
          cp  $$file $(distdir)/$$file; \
 
205
                cp $$file $(distdir)/$$file; \
366
206
        done
367
207
 
 
208
.PHONY: all modules clean install config_check dist