最近学习linux的驱动编写,在网上普遍用类似以下的Makefile
obj-m += target.o
KERNEL_DIR:=/path/to/the/kernel/source/dir
target.ko : source.c
make -C $(KERNEL_DIR) M=$(PWD) modules
一直以为“M=”是make程序的参数,今天读内核的Makefile才知道原来是在这里面定义的,如下
# Use make M=dir to specify directory of external module to build
# Old syntax make ... SUBDIRS=$PWD is still supported
# Setting the environment variable KBUILD_EXTMOD take precedence
ifdef SUBDIRS
KBUILD_EXTMOD ?= $(SUBDIRS)
endif
ifdef M
ifeq ("$(origin M)", "command line")
KBUILD_EXTMOD := $(M)
endif
endif
对make还是不熟,估计make的参数传递是传统的命令行传递格式,如-foo bar这样的,而Makefile的参数传递是以foo=bar这样的。
以上。