makefile 文件的命名会影响编译结果吗?

suxilong123 2017-11-09 10:42:47
大家好,初学Linux 驱动,有个问题不是很明白。

看过陈皓写过的 “跟我一起学 Makefile" 其中说: makefile 的文件可以命名为 “Makefile” 和“makefile”

再练习写hello world 驱动的时候,我将makefile 命名为两种不同的形式, 但发现大写的Makefile 可以编译通过,但是小写的makefile 编译时确出现 以下错误:

make -C /lib/modules/4.10.0-28-generic/build  M=/home/seven/Templates/dirver/helloword modules
make[1]: Entering directory '/usr/src/linux-headers-4.10.0-28-generic'
scripts/Makefile.build:44: /home/seven/Templates/dirver/helloword/Makefile: No such file or directory
make[2]: *** No rule to make target '/home/seven/Templates/dirver/helloword/Makefile'. Stop.
Makefile:1524: recipe for target '_module_/home/seven/Templates/dirver/helloword' failed
make[1]: *** [_module_/home/seven/Templates/dirver/helloword] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.10.0-28-generic'
makefile:5: recipe for target 'modules' failed
make: *** [modules] Error 2


说没有找到Makefile 。

makefile 内如如下:
[code=cfeq ($(KERNELRELEASE),)
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions Module* modules*
.PHONY: modules modules_install clean
else
obj-m := helloworld.o
endif][/code]


...全文
519 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
juno 2017-11-28
  • 打赏
  • 举报
回复
内核中是通过-f参数指定了只读取Makefile这个文件,对于直接运行make,会自动搜索当前目录的文件,任易匹配说行了。
macroliu163 2017-11-27
  • 打赏
  • 举报
回复
Kernel中一般是Makefile, Android中一般叫Android.mk....
沉默的小明兄 2017-11-21
  • 打赏
  • 举报
回复
直接 make 找的是 叫 Makefile, make -f 文件名 ,make工具使用有很多参数。
Acuity. 2017-11-17
  • 打赏
  • 举报
回复
纸上得来终觉浅,绝知此事要躬行。
suxilong123 2017-11-13
  • 打赏
  • 举报
回复
引用 3 楼 xuweiwei1860 的回复:
都可以的 只是同时存在的时候,会优先用Makefile
不对喔, 如果你用makefile 小写的命名 ,编译时 会报错的,显示找不到Makefile ,不信你可以尝试一下
fly 100% 2017-11-13
  • 打赏
  • 举报
回复
都可以的 只是同时存在的时候,会优先用Makefile
suxilong123 2017-11-10
  • 打赏
  • 举报
回复
引用 1 楼 yang05210 的回复:
Makefile 文件的命名会影响编译结果 只能用大写的M,不能用小写的 Makefile 这样命名是对的 makefile 这样命名是错的 因为:Linux系统中是区分大小写的
谢谢! 但是GUN http://www.gnu.org/software/make/manual/make.html#Makefile-Names 里面明明写着 “By default, when make looks for the makefile, it tries the following names, in order: GNUmakefile, makefile and Makefile. ” 而且我看在 一本 “跟我一起写 makfile” 的教程 ,上面也说 可以命名为 makefile 或者Makefile ~~~~ 我认为应该是Linux 内核中有地方规定了, 只是暂时找不到哪里要求的~~~
yang05210 2017-11-09
  • 打赏
  • 举报
回复
Makefile 文件的命名会影响编译结果 只能用大写的M,不能用小写的 Makefile 这样命名是对的 makefile 这样命名是错的 因为:Linux系统中是区分大小写的

21,597

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 驱动开发/核心开发
社区管理员
  • 驱动开发/核心开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧