From 2646417096919b1dbe494f8713d0de05e8a0202c Mon Sep 17 00:00:00 2001 From: Uttkarsh Date: Wed, 26 Feb 2014 14:00:10 +0530 Subject: [PATCH] Specify header file in makefile --- headerfile_path_kmodule/Makefile | 9 +++++++++ headerfile_path_kmodule/README | 2 ++ .../header_location/simple_header.h | 5 +++++ headerfile_path_kmodule/sample_kernel.c | 18 ++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 headerfile_path_kmodule/Makefile create mode 100644 headerfile_path_kmodule/README create mode 100644 headerfile_path_kmodule/header_location/simple_header.h create mode 100644 headerfile_path_kmodule/sample_kernel.c diff --git a/headerfile_path_kmodule/Makefile b/headerfile_path_kmodule/Makefile new file mode 100644 index 0000000..ec7a4b6 --- /dev/null +++ b/headerfile_path_kmodule/Makefile @@ -0,0 +1,9 @@ +obj-m += sample_kernel.o + +HEADER_LOC=header_location/ +EXTRA_CFLAGS := -I$(PWD)/$(HEADER_LOC) + +all: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules +clean: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean diff --git a/headerfile_path_kmodule/README b/headerfile_path_kmodule/README new file mode 100644 index 0000000..b6d3e30 --- /dev/null +++ b/headerfile_path_kmodule/README @@ -0,0 +1,2 @@ +For specifying header file path, +EXTRA_CLAGS is assigned with the -I option diff --git a/headerfile_path_kmodule/header_location/simple_header.h b/headerfile_path_kmodule/header_location/simple_header.h new file mode 100644 index 0000000..28779ab --- /dev/null +++ b/headerfile_path_kmodule/header_location/simple_header.h @@ -0,0 +1,5 @@ +#ifndef SIMPLE_H +#define SIMPLE_H + +#define LOG_INFO(log_str, args...) printk(KERN_INFO log_str, ## args); +#endif /*SIMPLE_H*/ diff --git a/headerfile_path_kmodule/sample_kernel.c b/headerfile_path_kmodule/sample_kernel.c new file mode 100644 index 0000000..a14afac --- /dev/null +++ b/headerfile_path_kmodule/sample_kernel.c @@ -0,0 +1,18 @@ +#include +#include +#include "simple_header.h" + +MODULE_LICENSE("GPL"); + +int init(void) +{ + LOG_INFO("<1>Hello world 1.\n"); + return 0; +} + +void cleanup(void) +{ + printk(KERN_ALERT "Goodbye world 1.\n"); +} +module_init(init); +module_exit(cleanup);