问题描述
例如:通用设备模块的Makefile
Eg: a common device module's Makefile
obj-m:=jc.o
default:
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
clean:
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules clean
我考虑是否可以将CFLAGS设置为文件.当我将 default 部分更改为
I consider if I can set CFLAGS to the file. When I change default section to
$(MAKE) -O2 -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
但是没有用.
有帮助吗?非常感谢.
推荐答案
-O2
将是make
(或$(MAKE)
,在使用时)的一个选项.显然,编译器(可能是gcc
)需要此标志,而不是make
.
-O2
would be an option to make
(or $(MAKE)
, as you're using it) in what you tried. Obviously, the compiler (probably gcc
) needs this flag, not make
.
Kbuild理解一个名为CFLAGS_modulename.o
的make变量,用于在编译此单元时添加特定的C标志.在您的情况下,您的模块对象将为jc.o
,因此您可以指定:
Kbuild understands a make variable named CFLAGS_modulename.o
to add specific C flags when compiling this unit. In your case, your module object will be jc.o
, so you can specify:
CFLAGS_jc.o := -O2
,它应该可以工作.在$(MAKE)
行中添加V=1
以得到详细的输出,并且在编译jc.c
时应该会看到-O2
.
and it should work. Add V=1
to your $(MAKE)
lines to get a verbose output and you should see -O2
when jc.c
is being compiled.
您可以在官方文档中找到有关编译模块的更多信息.
You can find more about compiling modules in the official documentation.
这篇关于是否可以将CFLAGS设置为Linux内核模块Makefile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!