5
5
winnt_types.h workqueue.c wrapmem.h wrapmem.c wrapper.c \
6
6
wrapndis.h wrapndis.c lin2win.h win2lin_stubs.S
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)
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)
18
# Some old kernels only install the "source" link
20
KBUILD := $(shell readlink -f /lib/modules/$(KVERS)/source)
24
$(error Kernel tree not found - please set KBUILD to configured kernel)
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.
30
VERSION_H := $(KBUILD)/include/linux/utsrelease.h
31
ifeq (,$(wildcard $(VERSION_H)))
32
VERSION_H := $(KBUILD)/include/linux/version.h
34
ifeq (,$(wildcard $(VERSION_H)))
35
$(error Cannot find kernel version in $(KBUILD), is it configured?)
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/')
11
41
# distros use different paths for kernel include files
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 ; \
31
60
KREV := $(shell echo $(KVERS) | sed -e 's/[^\.]*\.[^\.]*\.\([0-9]*\).*/\1/')
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)
66
include $(KBUILD)/.config
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)
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; \
46
79
# returns of structs and unions in registers when possible, like Windows
47
CFLAGS += -freg-struct-return
80
MOD_CFLAGS += -freg-struct-return
49
82
# to produce debug trace, add option "DEBUG=<n>" where <n> is 1 to 6
51
CFLAGS += -DDEBUG=$(DEBUG) -g
84
MOD_CFLAGS += -DDEBUG=$(DEBUG) -g
54
87
# to debug timers, add option "TIMER_DEBUG=1 DEBUG=<n>"
56
CFLAGS += -DTIMER_DEBUG
89
MOD_CFLAGS += -DTIMER_DEBUG
59
92
# to debug event layer, add option "EVENT_DEBUG=1 DEBUG=<n>"
61
CFLAGS += -DEVENT_DEBUG
94
MOD_CFLAGS += -DEVENT_DEBUG
64
97
# to debug USB layer, add option "USB_DEBUG=1 DEBUG=<n>"
99
MOD_CFLAGS += -DUSB_DEBUG
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>"
104
MOD_CFLAGS += -DIO_DEBUG
74
107
# to debug worker threads
76
CFLAGS += -DWORK_DEBUG
109
MOD_CFLAGS += -DWORK_DEBUG
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
83
CFLAGS += -DALLOC_DEBUG=$(ALLOC_DEBUG)
114
MOD_CFLAGS += -DALLOC_DEBUG=$(ALLOC_DEBUG)
117
# emulate (pseudo) preemption
119
MOD_CFLAGS += -DWRAP_PREEMPT
86
122
.PHONY: prereq_check gen_exports clean dist_clean install stack_check
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
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
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
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;}"; \
266
@if [ -f $(KSRC)/include/linux/netdevice.h ]; then \
267
echo "#include <linux/netdevice.h>"; \
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); }"; \
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) {}"; \
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; }" ; \
288
@if ! grep -qw create_workqueue $(KSRC)/include/linux/*.h; then \
289
echo "#define WRAP_WQ 1"; \
291
@if ! grep -qw create_workqueue $(KSRC)/include/linux/*.h; then \
292
echo "#define WRAP_WQ 1"; \
294
@if [ -f $(KSRC)/include/linux/percpu.h ]; then \
295
echo "#include <linux/percpu.h>"; \
297
@if grep -qw proc_net $(KSRC)/include/linux/proc_fs.h; then \
298
echo "#define proc_net_root proc_net"; \
300
echo "#define proc_net_root init_net.proc_net"; \
225
304
@if [ ! -f $(KBUILD)/include/linux/version.h ]; then \
226
305
echo "Can't find kernel build files in $(KBUILD);"; \
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
244
323
rm -f *_exports.h .\#* win2lin_stubs.h built-in.o
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
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)
328
ifeq ($(wflags), CFLAGS)
329
CFLAGS += $(MOD_CFLAGS)
331
EXTRA_CFLAGS += $(MOD_CFLAGS)
257
$(LD) -r -o $(MODULE) $(OBJS)
260
334
MODULE := ndiswrapper.ko
261
335
obj-m := ndiswrapper.o