I followed the guide to Creating packages for kernel modules
Created Makefile:
include $(TOPDIR)/rules.mk
2 include $(INCLUDE_DIR)/kernel.mk
3
4 PKG_NAME:=Khelloworld
5 PKG_VERSION:=1.0
6 PKG_RELEASE:=1
7
8 PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
9
10 obj-m +=helloK.o
11 KDIR:=/lib/modules/5.4.0-122-generic/build
12 SOURCE_DIR:=/home/shouvik/openwrt/package/Khelloworld/src
13
14 include $(INCLUDE_DIR)/package.mk
15
16 #
17 define KernelPackage/Khelloworld
18 SECTION:=examples
19 CATEGORY:=Examples
20 TITLE:=Hello, World! from Kernel
21 endef
22
23 #
24 define KernelPackage/Khelloworld/description
25 A simple "Hello, World!" -application.
26 endef
27
28 #
29 define Build/Prepare
30 mkdir -p $(PKG_BUILD_DIR)
31 cp $(SOURCE_DIR)/* $(PKG_BUILD_DIR)
32 $(Build/Patch)
33 endef
34
35 #
36 define Build/Compile
37 $(MAKE) -C $(KDIR) M=$(shell pwd) modules
38 endef
39
40 #
41 define KernelPackage/Khelloworld/install
42 $(INSTALL_DIR) $(1)/etc/init.d
43 $(INSTALL_DIR) $(1)/lib/modules/$(LINUX_VERSION)
44 $(INSTALL_DIR) $(1)/usr/bin
45 $(INSTALL_BIN) $(PKG_BUILD_DIR)/Khelloworld $(1)/usr/bin
46 endef
47
48 $(eval $(call KernelPackage,Khelloworld))
Errors I get
make[3]: Entering directory '/usr/src/linux-headers-5.4.0-122-generic'
make[4]: *** No rule to make target '/home/shouvik/openwrt/package/Khelloworld/helloK.o', needed by '__build'. Stop.
Makefile:1762: recipe for target '/home/shouvik/openwrt/package/Khelloworld' failed
make[3]: *** [/home/shouvik/openwrt/package/Khelloworld] Error 2
make[3]: Leaving directory '/usr/src/linux-headers-5.4.0-122-generic'
Makefile:48: recipe for target '/home/shouvik/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_tiny/Khelloworld-1.0/.built' failed
make[2]: *** [/home/shouvik/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_tiny/Khelloworld-1.0/.built] Error 2
make[2]: Leaving directory '/home/shouvik/openwrt/package/Khelloworld'
time: package/Khelloworld/compile#1.51#0.49#1.98
ERROR: package/Khelloworld failed to build.
package/Makefile:114: recipe for target 'package/Khelloworld/compile' failed
make[1]: *** [package/Khelloworld/compile] Error 1
make[1]: Leaving directory '/home/shouvik/openwrt'
/home/shouvik/openwrt/include/toplevel.mk:228: recipe for target 'package/Khelloworld/compile' failed
make: *** [package/Khelloworld/compile] Error 2
What i am missing to add in Makefile ?