summaryrefslogtreecommitdiff
path: root/tests/projects/linux/driver/hello_makefile
diff options
context:
space:
mode:
authorruki <[email protected]>2021-12-11 11:10:20 +0800
committerruki <[email protected]>2021-12-11 11:10:20 +0800
commit6c4c605b19b38bc34fa3a09e2087e11fe2103484 (patch)
treed9567fae5b0439f51a4142eb5a570c4756e4d8ab /tests/projects/linux/driver/hello_makefile
parent76d2f0f84976180935865f3f125ecc8c8b57bd7d (diff)
add hello_makefile
Diffstat (limited to 'tests/projects/linux/driver/hello_makefile')
-rw-r--r--tests/projects/linux/driver/hello_makefile/Makefile15
-rw-r--r--tests/projects/linux/driver/hello_makefile/src/add.c3
-rw-r--r--tests/projects/linux/driver/hello_makefile/src/hello.c23
3 files changed, 41 insertions, 0 deletions
diff --git a/tests/projects/linux/driver/hello_makefile/Makefile b/tests/projects/linux/driver/hello_makefile/Makefile
new file mode 100644
index 000000000..1d5aa92b4
--- /dev/null
+++ b/tests/projects/linux/driver/hello_makefile/Makefile
@@ -0,0 +1,15 @@
+ifneq ($(KERNELRELEASE),)
+ obj-m := hello.o
+ hello-objs := ./src/hello.o ./src/add.o
+else
+ KERN_DIR ?= /usr/src/linux-headers-5.11.0-41-generic/
+ PWD := $(shell pwd)
+
+default:
+ $(MAKE) -C $(KERN_DIR) V=1 M=$(PWD) modules
+endif
+
+clean:
+ rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
+ rm -rf src/*.o src/*~ core src/.depend src/.*.cmd src/*.ko src/*.mod.c src/.tmp_versions
+
diff --git a/tests/projects/linux/driver/hello_makefile/src/add.c b/tests/projects/linux/driver/hello_makefile/src/add.c
new file mode 100644
index 000000000..59aab4983
--- /dev/null
+++ b/tests/projects/linux/driver/hello_makefile/src/add.c
@@ -0,0 +1,3 @@
+int add(int a, int b) {
+ return a + b;
+}
diff --git a/tests/projects/linux/driver/hello_makefile/src/hello.c b/tests/projects/linux/driver/hello_makefile/src/hello.c
new file mode 100644
index 000000000..414a03bb2
--- /dev/null
+++ b/tests/projects/linux/driver/hello_makefile/src/hello.c
@@ -0,0 +1,23 @@
+#include <linux/init.h>
+#include <linux/module.h>
+
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_AUTHOR("Ruki");
+MODULE_DESCRIPTION("A simple Hello World Module");
+MODULE_ALIAS("a simplest module");
+
+int add(int a, int b);
+
+int hello_init(void)
+{
+ printk(KERN_INFO "Hello World: %d\n", add(1, 2));
+ return 0;
+}
+
+void hello_exit(void)
+{
+ printk(KERN_INFO "Goodbye World\n");
+}
+
+module_init(hello_init);
+module_exit(hello_exit);