c - How do I specify which of two kernel modules to compile with a Makefile?
问题描述
I have a Makefile that compiles two Linux kernel modules (mod1.c
and mod2.c
).
obj-m = mod1.o mod2.o
KDIR=/lib/modules/$(shell uname -r)/build/
PWD=$(shell pwd)
# build the modules
default:
$(MAKE) -C $(KDIR) M=$(PWD) modules
#cleanup
clean:
rm -rf *.ko *.o *.mod* .*.cmd modules.order Module.symvers .tmp_versions
This works fine to build both kernel modules when I run make
, but I would like to be able to specify which module to build. For example, make mod1
to compile mod1.c
and make mod2
to compile mod2.c
.
The thing that I am unsure of is how to handle obj-m
. Otherwise, specifying which program to compile is well described online.
解决方案
The kernel uses variables to set kernel modules on/off:
CROSS_COMPILE ?= /path/to/compiler/arm-linux-gnueabihf-
T1 ?= n
T2 ?= n
obj-$(T1) += test1.o
obj-$(T2) += test2.o
LINUX_SOURCE_DIR=/path/to/linux
all:
$(MAKE) -C $(LINUX_SOURCE_DIR) M=$(PWD) modules ARCH=arm
test1:
$(MAKE) T1=m
test2:
$(MAKE) T2=m
clean:
rm *o modules.order Module.symvers *mod.c
You can use this as make T1=m
or make test2
.
推荐阅读
- php - 如何使用限制和某种分数选择随机行?
- javascript - 如何使用 redux-form 以编程方式更新字段的状态
- ruby-on-rails - 当sidekiq崩溃时如何重新启动它?
- python - 在 HTML div 中显示有关 matplotlib pick_event 拾取点的信息
- python - pyqt5 / qtdesigner 文本框默认标签
- php - 如何将 JSON 字符串转换为数组
- javascript - 如果屏幕宽度超过 516px,Javascript 函数不起作用?
- java - 构造函数打印出 NULL 而不是对象值
- mysql - 不计算重叠的时间范围相加两次
- php - Google Calendar API 没有描述