58
47
SRC_DIR=$(shell pwd)
60
KREV := $(shell echo $(KVERS) | sed -e 's/[^\.]*\.[^\.]*\.\([0-9]*\).*/\1/')
62
49
KCONFIG := $(KBUILD)/.config
63
50
ifeq (,$(wildcard $(KCONFIG)))
64
51
$(error No .config found in $(KBUILD), please set KBUILD to configured kernel)
66
53
include $(KBUILD)/.config
68
MOD_CFLAGS += $(shell [ -f $(KSRC)/include/linux/modversions.h ] && \
69
echo -DEXPORT_SYMTAB -DMODVERSIONS \
70
-include $(KSRC)/include/linux/modversions.h)
73
MOD_CFLAGS += $(shell if grep -q 'struct module \*owner;' \
74
$(KSRC)/include/linux/usb.h ; then \
75
echo -DUSB_DRIVER_OWNER; \
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
82
58
# to produce debug trace, add option "DEBUG=<n>" where <n> is 1 to 6
84
MOD_CFLAGS += -DDEBUG=$(DEBUG) -g
60
EXTRA_CFLAGS += -DDEBUG=$(DEBUG) -g
87
63
# to debug timers, add option "TIMER_DEBUG=1 DEBUG=<n>"
89
MOD_CFLAGS += -DTIMER_DEBUG
65
EXTRA_CFLAGS += -DTIMER_DEBUG
92
68
# to debug event layer, add option "EVENT_DEBUG=1 DEBUG=<n>"
94
MOD_CFLAGS += -DEVENT_DEBUG
70
EXTRA_CFLAGS += -DEVENT_DEBUG
97
73
# to debug USB layer, add option "USB_DEBUG=1 DEBUG=<n>"
99
MOD_CFLAGS += -DUSB_DEBUG
75
EXTRA_CFLAGS += -DUSB_DEBUG
102
78
# to debug I/O layer, add option "IO_DEBUG=1 DEBUG=<n>"
104
MOD_CFLAGS += -DIO_DEBUG
80
EXTRA_CFLAGS += -DIO_DEBUG
107
83
# to debug worker threads
109
MOD_CFLAGS += -DWORK_DEBUG
85
EXTRA_CFLAGS += -DWORK_DEBUG
112
88
# to debug memory allocation issues
114
MOD_CFLAGS += -DALLOC_DEBUG=$(ALLOC_DEBUG)
90
EXTRA_CFLAGS += -DALLOC_DEBUG=$(ALLOC_DEBUG)
117
93
# emulate (pseudo) preemption
118
94
ifdef WRAP_PREEMPT
119
MOD_CFLAGS += -DWRAP_PREEMPT
95
EXTRA_CFLAGS += -DWRAP_PREEMPT
122
.PHONY: prereq_check gen_exports clean dist_clean install stack_check
124
all : prereq_check win2lin_stubs.h gen_exports compat.h default stack_check
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
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
104
STUB_SRCS = crt.c hal.c ndis.c ntoskernel.c ntoskernel_io.c \
105
pnp.c rtl.c wrapndis.c
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"
136
MOD_CFLAGS += -DDISABLE_USB
140
112
ifeq ($(CONFIG_USB),y)
143
115
ifeq ($(CONFIG_USB),m)
121
EXPORTS += usb_exports.h
148
MOD_CFLAGS += $(shell if grep -s -A1 'ndiswrapper' $(KSRC)/kernel/module.c | \
149
grep -q 'add_taint_module' ; then \
124
EXTRA_CFLAGS += -DENABLE_USB
154
MOD_CFLAGS += -DWRAP_WQ
128
EXTRA_CFLAGS += -DWRAP_WQ
155
129
OBJS += workqueue.o
159
MOD_CFLAGS += -DNTOS_WQ
162
ntoskernel.h: lin2win.h
166
iw_ndis.h: ntoskernel.h
168
pnp.h: ntoskernel.h ndis.h
170
wrapndis.h: ndis.h pnp.h
174
divdi3.o: divdi3.c longlong.h
176
hal.o: hal.c ntoskernel.h
178
iw_ndis.o: iw_ndis.c iw_ndis.h wrapndis.h
180
loader.o: loader.c loader.h ndis.h wrapndis.h
184
ndis.o: ndis.c ndis.h iw_ndis.h wrapndis.h
186
wrapndis.o: wrapndis.c wrapndis.h
188
ntoskernel.o: ntoskernel.c ndis.h usb.h
190
ntoskernel_io.o: ntoskernel_io.c ndis.h usb.h
192
pe_linker.o: pe_linker.c
196
proc.o: proc.c ndis.h iw_ndis.h wrapndis.h
200
usb.o: usb.c usb.h ndis.h
202
wrapper.o: wrapper.c wrapndis.h iw_ndis.h ntoskernel.h loader.h
133
all: config_check modules
135
# generate exports symbol table from C files
136
quiet_cmd_mkexport = MKEXPORT $@
137
cmd_mkexport = $(SHELL) $(obj)/mkexport.sh $< $@
139
%_exports.h: %.c $(obj)/mkexport.sh FORCE
140
$(call if_changed,mkexport)
142
extra-y := $(EXPORTS)
204
144
ifeq ($(CONFIG_X86_64),y)
145
quiet_cmd_mkstubs = MKSTUBS $@
146
cmd_mkstubs = $(SHELL) $(obj)/mkstubs.sh $(addprefix $(src)/,$(STUB_SRCS)) >$@
148
$(obj)/win2lin_stubs.h: $(addprefix $(src)/,$(STUB_SRCS)) FORCE
149
$(call if_changed,mkstubs)
151
extra-y += win2lin_stubs.h
205
152
OBJS += win2lin_stubs.o
206
win2lin_stubs.o: win2lin_stubs.h win2lin_stubs.S
209
win2lin_stubs.h: hal.c crt.c ndis.c ntoskernel.c ntoskernel_io.c \
210
pnp.c rtl.c wrapndis.c
212
win2lin_stubs.h: hal.c crt.c ndis.c ntoskernel.c ntoskernel_io.c \
213
pnp.c rtl.c usb.c wrapndis.c
215
@for file in $^; do \
217
echo "# automatically generated from $$file"; \
219
-e 's/.*WIN_FUNC(\([^\,]\+\) *\, *\([0-9]\+\)).*/\
221
-e 's/.*WIN_FUNC_PTR(\([^\,]\+\) *\, *\([0-9]\+\)).*/\
223
$$file | sed -e 's/[ \t ]\+//' | sort -u; \
231
# generate exports symbol table from C files
234
echo "/* automatically generated from $< */"; \
235
echo "#ifdef CONFIG_X86_64"; \
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; \
243
echo "struct wrap_export $(basename $<)_exports[] = {";\
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}"; \
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
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"; \
157
MODULE := $(MODNAME).ko
158
obj-m := $(MODNAME).o
160
$(MODNAME)-objs := $(OBJS)
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";\
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";\
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";\
172
@if [ -z "$(CONFIG_WIRELESS_EXT)$(CONFIG_NET_RADIO)" ]; then \
174
echo "*** WARNING: This kernel lacks wireless extensions."; \
175
echo "Wireless drivers will not work properly."; \
178
@if [ -z "$(CONFIG_X86_64)" ] && [ -n "$(CONFIG_4KSTACKS)" ]; then \
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"; \
188
$(MAKE) -C $(KBUILD) M=$(SRC_DIR)
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
323
rm -f *_exports.h .\#* win2lin_stubs.h built-in.o
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)
334
MODULE := ndiswrapper.ko
335
obj-m := ndiswrapper.o
337
ndiswrapper-objs := $(OBJS)
340
$(MAKE) -C $(KBUILD) SUBDIRS=$(SRC_DIR)
344
@if [ "x$(CONFIG_X86_64)" = "x" -a $(KPSUB) -eq 26 ] && \
345
grep -q "CONFIG_4KSTACKS=y" $(KBUILD)/.config; then \
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";\
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
195
install: config_check modules
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)
364
204
@for file in $(DISTFILES); do \
365
cp $$file $(distdir)/$$file; \
205
cp $$file $(distdir)/$$file; \
208
.PHONY: all modules clean install config_check dist