为下面这段代码写一个makefile文件,要求把all/install/uninstall 写入 Makefile 文件中。#include <linux/init.h> #include <linux/module.h> #include <linux/workqueue.h> #include <linux/sched.h> #include <linux/delay.h> #include <linux/timekeeping.h> MODULE_LICENSE("GPL"); static struct workqueue_struct* workqueue; static struct work_struct work1; static struct delayed_work work2; static int times; module_param(times, int, 5); int get_time(char* buff, int len) { struct timespec64 ts; struct tm tm_res; char time_string[40]; ktime_get_real_ts64(&ts); time64_to_tm(ts.tv_sec, 0, &tm_res); buff=tm_res.tm_year + 1900, tm_res.tm_mon + 1, tm_res.tm_mday,tm_res.tm_hour, tm_res.tm_min, tm_res.tm_sec; return 0; } static void real_time_work(struct work_struct* work) { char buff[40]; get_time(buff, sizeof(buff)); printk(KERN_INFO "%s\n",buff); } static void delayed_work(struct work_struct* work) { char buff[40]; get_time(buff, sizeof(buff)); printk(KERN_INFO "this is a delay work :%s\n", buff); } static int __init module_init(void) { printk(KERN_INFO "Initializing workqueue module.\n"); workqueue = create_workqueue("workqueue"); INIT_WORK(&work1, real_time_work); INIT_DELAYED_WORK(&work2, delayed_work); queue_work(workqueue, &work1); queue_delayed_work(workqueue, &work2, msecs_to_jiffies(10000)); return 0; } static void __exit module_exit(void) { printk(KERN_INFO "Exiting workqueue module.\n"); flush_workqueue(workqueue); destroy_workqueue(workqueue); } module_init(module_init); module_exit(module_exit);
时间: 2024-03-17 14:44:03 浏览: 69
以下是makefile文件的内容:
```
obj-m := workqueue.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
install:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules_install
depmod -a
uninstall:
rm /lib/modules/$(shell uname -r)/kernel/drivers/misc/workqueue.ko
depmod -a
```
其中,obj-m定义了需要编译的模块文件,即workqueue.o。all指令使用make命令编译模块文件,install指令安装模块文件并更新依赖,uninstall指令删除已安装的模块文件并更新依赖。
阅读全文