The following code is taken from running Linux
BASEINCLUDE ?= /home/ben/work/runninglinuxkernel_4.0
#BASEINCLUDE ?= /lib/modules/`uname -r`/build
mydemo_misc-objs := mydemodrv_misc.o
obj-m := mydemo_misc.o
all :
$(MAKE) -C $(BASEINCLUDE) M=$(PWD) modules;
clean:
$(MAKE) -C $(BASEINCLUDE) SUBDIRS=$(PWD) clean;
rm -f *.ko;
When the target of make is all, -C (BASEINCLUDE) indicates to jump to the kernel source directory to read the Makefile there; M = (BASEINCLUDE) indicates to jump to the kernel source directory to read the Makefile there; M=( B A S E the I N C L the U- D E ) refers to the next hop transferred to the core source code destination record the reading taken that in the M A K E F I L E ; M= (PWD) indicates and then return to the current directory to continue reading and executing the current Makefile.
After compilation, mydemo_misc.ko will eventually be generated.
In addition:
mydemo_misc-objs:=mydemodrv_misc.o in front of mydemo_misc is the name of the compiled file, it should be a fixed wording, the compilation fails after modification