是否可以将 CFLAGS 设置为 linux 内核模块 Makefile? [英] Is it possible to set CFLAGS to a linux kernel module Makefile?

查看:29
本文介绍了是否可以将 CFLAGS 设置为 linux 内核模块 Makefile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:通用设备模块的 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

但是没有用.

有什么帮助吗?非常感谢.

Any help? Thanks a lot.

推荐答案

-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

它应该可以工作.将 V=1 添加到您的 $(MAKE) 行以获得详细输出,并且您应该在 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆