OBJS := hal.o iw_ndis.o loader.o misc_funcs.o ndis.o \
	ntoskernel.o pe_linker.o proc.o usb.o wrapper.o

CFLAGS += -DNDISWRAPPER_VERSION=\"1.1\" -DEXTRA_VERSION=\"\"

ifeq ($(CONFIG_X86_64),y)
OBJS += x86_64_stubs.o
else
OBJS += divdi3.o
endif

obj-$(CONFIG_NDISWRAPPER) := ndiswrapper.o 
ndiswrapper-objs := $(OBJS)


targets := x86_64_stubs.h hal_exports.h misc_funcs_exports.h ndis_exports.h ntoskerlen_exports.h usb_exports.h


$(obj)/x86_64_stubs.o: $(obj)/x86_64_stubs.h $(src)/x86_64_stubs.S
$(obj)/x86_64_stubs.h: $(src)/hal.c $(src)/misc_funcs.c $(src)/ndis.c $(src)/ntoskernel.c $(src)/usb.c $(src)/wrapper.c
	@if :; then \
                echo "# Do not edit this file; \
                         it is automatically generated"; \
                for file in $^; do \
                        echo; \
                        echo "# generated from $$file"; \
                        sed -n \
                                -e 's/.*WRAP_EXPORT(\([^)]\+\)).*/   \
                                          win_to_lin_stub \1/p'   \
                                -e 's/.*WRAP_FUNC_PTR(\([^)]\+\)).*/   \
                                          win_to_lin_stub \1/p'   \
                                           $$file | sort -u; \
                done; \
        fi > $@


$(obj)/hal.o: $(obj)/hal_exports.h
$(obj)/hal_exports.h: $(src)/hal.c

$(obj)/misc_funcs.o: $(obj)/misc_funcs_exports.h
$(obj)/misc_funcs_exports.h: $(src)/misc_funcs.c

$(obj)/ndis.o: $(obj)/ndis_exports.h
$(obj)/ndis_exports.h: $(src)/ndis.c

$(obj)/ntoskernel.o: $(obj)/ntoskernel_exports.h
$(obj)/ntoskernel_exports.h: $(src)/ntoskernel.c

$(obj)/usb.o: $(obj)/usb_exports.h
$(obj)/usb_exports.h: $(src)/usb.c

$(obj)/wrapper.o: $(obj)/wrapper_exports.h
$(obj)/wrapper_exports.h: $(src)/wrapper.c

$(obj)/%_exports.h: $(src)/%.c
	if :; then \
                echo "/* Do not edit this file; \
                         it is automatically generated from $< */"; \
                echo "#ifdef CONFIG_X86_64"; \
                sed -n \
                        -e 's/.*WRAP_EXPORT(\([^)]\+\)).*/   \
                                   extern void x86_64_\1(void);/p' \
                        -e 's/.*WRAP_FUNC_PTR(\([^)]\+\)).*/   \
                                   extern void x86_64_\1(void);/p' \
                           $< | sort; \
                echo "#endif"; \
                echo "struct wrap_export $(shell basename $< .c)_exports[] = {";\
                sed -n \
                        -e 's/.*WRAP_EXPORT(\(_win_\)\([^)]\+\)).*/     \
                                   WRAP_EXPORT_WIN_FUNC(\2),/p' \
                        -e 's/.*WRAP_EXPORT(\([^)]\+\)).*/   \
                                   WRAP_EXPORT_SYMBOL(\1),/p' \
                        -e 's/.*WRAP_EXPORT_MAP(\("[^"]\+"\)[ ,\n]\+\([^)]\+\)).*/   \
                                   {\1, (WRAP_EXPORT_FUNC)\2},/p' $< | sort; \
                echo "    {NULL, NULL}"; \
                echo "};"; \
        fi > $@
