我拿出kernel里的r8169 driver,借鉴了一些makefile,可以成功make以及insmod,但是最近在另一台电脑上却失败了,记录一下这个问题。
PS:我个人暂时没有很系统的学习makefile,仅仅是需要用到的时候百度一下。
这次make之后,遇到了如下的问题:
make -C /lib/modules/5.13.0-44-generic/build SUBDIRS=/home/tover/drivers/test/r8169/realtek clean
make[1]: Entering directory '/usr/src/linux-headers-5.13.0-44-generic'
fs/aufs/Makefile:3: fs/aufs/magic.mk: No such file or directory
make[3]: *** No rule to make target 'fs/aufs/magic.mk'. Stop.
make[2]: *** [scripts/Makefile.clean:68: fs/aufs] Error 2
make[1]: *** [Makefile:1886: _clean_fs] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.13.0-44-generic'
make: *** [Makefile:57: clean] Error 2
我研究了一会fs/aufs/magic.mk,并没有什么特别的发现。
因为我之前在Ubuntu 18.04 kernel version 4.15.0上是可以成功make的,此次在Ubuntu 20.04 kernel version 5.13.0上就失败了。这时我想到了是内核版本的问题,所以我就去查找不同版本的r8168的makefile文件,通过比对,我找到了如下的不同。
旧的版本:
.PHONY:modules
modules:
$(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) modules
.PHONY:clean
clean:
$(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) clean
.PHONY:install
install:
$(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) INSTALL_MOD_DIR=$(RTKDIR) modules_install
新的版本:
modules:
#ifeq ($(call kver_ge,5,0,0),1)
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
#else
# $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) modules
#endif
.PHONY:clean
clean:
#ifeq ($(call kver_ge,5,0,0),1)
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
#else
# $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) clean
#endif
.PHONY:install
install:
#ifeq ($(call kver_ge,5,0,0),1)
$(MAKE) -C $(KERNELDIR) M=$(PWD) INSTALL_MOD_DIR=$(RTKDIR) modules_install
#else
# $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) INSTALL_MOD_DIR=$(RTKDIR) modules_install
#endif
我增加了相应的内容,发现可以成功make了。Google之后发现了原因,较新版本的内核已经不支持利用 SUBDIRS 来编译,转而支持用 M 编译,且对 M 的支持从v2.6就开始了。
Google上的解释如下:
In newer versions, the SUBDIRS argument is totally ignored, so it's trying to compile the whole kernel (or a lot of it, anyway). But no configuration has been done so it fails right away.
并且他给出了Makefile的warning:
make[1]: Entering directory '/usr/src/linux-headers-5.3.0-40-generic'
Makefile:227: ================= WARNING ================
Makefile:228: 'SUBDIRS' will be removed after Linux 5.3
Makefile:229:
Makefile:230: If you are building an individual subdirectory
Makefile:231: in the kernel tree, you can do like this:
Makefile:232: $ make path/to/dir/you/want/to/build/
Makefile:233: (Do not forget the trailing slash)
Makefile:234:
Makefile:235: If you are building an external module,
Makefile:236: Please use 'M=' or 'KBUILD_EXTMOD' instead
Makefile:237: ==========================================
最后贴一下Google的链接
如果觉得这篇文章有用的话,可以点赞、评论或者收藏,万分感谢,goodbye~