Linux Device Driver arrangement (2) "profit first, profit first", and tidy up the makefile for compiling the linux device driver program. Java code www.2cto.com all: KERNELDIR? =/Lib/modules/$ (shell uname-r)/build PWD :=$ (shell pwd) $ (MAKE)-C $ (KERNELDIR) M =$ (PWD) modules clean: $ (MAKE)-C $ (KERNELDIR) M = $ (PWD) clean note: In the makefile file, the indent part must be a tab, it cannot be replaced by spaces. /Lib/modules/$ (shell uname-r)/build corresponds to the linux source code tree of the current compiling environment. Use uname-r to check whether the kernel version of the compiling environment is consistent with that of the target environment (that is, the operating system where the driver is to be installed. If they are different, install the linux source code tree consistent with the target environment. Otherwise, the compiled ko file cannot be loaded in the target environment because of its different vermagic values. Another method is to modify include/linux/utsrelease in the kernel source code tree. h (UTS_RELEASE macro) and include/linux/vermagic. VERMAGIC_STRING in h can also compile the ko with vermagic consistent with the target environment. Use modinfo MyLinuxDrv. ko on www.2cto.com to find its corresponding vermagic. Write a device driver code for MyLinuxDrv. c, and save the makefile script in the Makefile file in the same directory. Run make to compile the MyLinuxDrv. ko file. Execute make clean to clear the compiled MyLinuxDrv. ko file and intermediate target file (. o) for recompilation.