NVIDIA 340.107 build against kernel 4.4 fails

Trying to cross-compile two Nvidia drivers against Linux kernel 4.4.70:

  • Nvidia 384.59 - everything builds fine
  • Nvidia 340.107 (needed for GeForce 9500 GT card)- build fails (using the same build command)

The constraints are that i can’t switch to a different kernel version and do need to support GeForce 9500 card.
The forum search reveals references to patches for other kernel versions (4.11 etc), but couldn’t find anything for 4.4.
It would be greatly appreciated if someone can point out whether Nvidia 340.107 and kernel 4.4 are a viable combination - with or without the patches.

+ make -C /usr/src/mk7i-linux-4.4.70-53ali/src ARCH=x86 CROSS_COMPILE=mk7i- modules_prepare
make: Entering directory `/usr/src/mk7i-linux-4.4.70-53ali/src'
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  CHK     include/generated/bounds.h
  CHK     include/generated/timeconst.h
  CHK     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
make: Leaving directory `/usr/src/mk7i-linux-4.4.70-53ali/src'
+ cd /usr/src/mk7i-linux-4.4.70-53ali/NVIDIA-Linux-x86-340.107/kernel
+ make -C /usr/src/mk7i-linux-4.4.70-53ali/src M=/usr/src/mk7i-linux-4.4.70-53ali/NVIDIA-Linux-x86-340.107/kernel ARCH=x86 CROSS_COMPILE=mk7i- 'CC=/usr/bin/ccache  mk7i-gcc' 'HOSTCC=/usr/bin/ccache  gcc' 'HOST_CC=/usr/bin/ccache gcc'
make: Entering directory `/usr/src/mk7i-linux-4.4.70-53ali/src'
  LD      /usr/src/mk7i-linux-4.4.70-53ali/NVIDIA-Linux-x86-340.107/kernel/built-in.o
  CC [M]  /usr/src/mk7i-linux-4.4.70-53ali/NVIDIA-Linux-x86-340.107/kernel/nv.o
In file included from /usr/src/mk7i-linux-4.4.70-53ali/NVIDIA-Linux-x86-340.107/kernel/conftest.h:1:0,
                 from /usr/src/mk7i-linux-4.4.70-53ali/NVIDIA-Linux-x86-340.107/kernel/nv-linux.h:15,
                 from /usr/src/mk7i-linux-4.4.70-53ali/NVIDIA-Linux-x86-340.107/kernel/nv.c:13:
/usr/src/mk7i-linux-4.4.70-53ali/NVIDIA-Linux-x86-340.107/kernel/conftest/macros.h:1:2: error: #error INIT_WORK() conftest failed!
 #error INIT_WORK() conftest failed!
  ^
In file included from /usr/src/mk7i-linux-4.4.70-53ali/NVIDIA-Linux-x86-340.107/kernel/conftest.h:2:0,
                 from /usr/src/mk7i-linux-4.4.70-53ali/NVIDIA-Linux-x86-340.107/kernel/nv-linux.h:15,
                 from /usr/src/mk7i-linux-4.4.70-53ali/NVIDIA-Linux-x86-340.107/kernel/nv.c:13:
/usr/src/mk7i-linux-4.4.70-53ali/NVIDIA-Linux-x86-340.107/kernel/conftest/functions.h:2:2: error: #error vmap() conftest failed!
 #error vmap() conftest failed!
  ^
/usr/src/mk7i-linux-4.4.70-53ali/NVIDIA-Linux-x86-340.107/kernel/conftest/functions.h:12:2: error: #error kmem_cache_create() conftest failed!
 #error kmem_cache_create() conftest failed!
  ^
/usr/src/mk7i-linux-4.4.70-53ali/NVIDIA-Linux-x86-340.107/kernel/conftest/functions.h:13:2: error: #error on_each_cpu() conftest failed!
 #error on_each_cpu() conftest failed!
  ^
/usr/src/mk7i-linux-4.4.70-53ali/NVIDIA-Linux-x86-340.107/kernel/conftest/functions.h:14:2: error: #error smp_call_function() conftest failed!
 #error smp_call_function() conftest failed!
  ^
/usr/src/mk7i-linux-4.4.70-53ali/NVIDIA-Linux-x86-340.107/kernel/conftest/functions.h:19:2: error: #error acpi_walk_namespace() conftest failed!
 #error acpi_walk_namespace() conftest failed!
  ^
/usr/src/mk7i-linux-4.4.70-53ali/NVIDIA-Linux-x86-340.107/kernel/conftest/functions.h:21:2: error: #error pci_dma_mapping_error() conftest failed!

it seems kbuild calls conftest.sh script with ARCH=x86 (the 2nd argument) but that’s not handled in the script (as it handles “$ARCH” = “i386”)
The patch at the following URL makes it work https://paste.debian.net/1048008/
nvidia_340.107.txt (1.88 KB)