小编Ras*_*sen的帖子

如何将参数从makefile传递到Linux内核模块源代码

我有源代码:

#include <linux/module.h>   
#include <linux/kernel.h>   

int init_module(void)
{
    printk(KERN_INFO "Hello world %i\n", BUILD_NUMBER);
    return 0;
}

void cleanup_module(void)
{
    printk(KERN_INFO "Goodbye world 1.\n");
}
Run Code Online (Sandbox Code Playgroud)

和一个makefile:

obj-m += hello-1.o

BUILD_NUMBER := 42

# How to pass BUILD_NUMBER to hello-1.c ???

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Run Code Online (Sandbox Code Playgroud)

现在如何将BUILD_NUMBER参数从makefile传递给源代码?

linux gcc kernel module makefile

11
推荐指数
1
解决办法
8229
查看次数

标签 统计

gcc ×1

kernel ×1

linux ×1

makefile ×1

module ×1