kernel.mk 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # This file is part of the OpenADK project. OpenADK is copyrighted
  2. # material, please see the LICENCE file in the top-level directory.
  3. LINUX_KMOD_SUFFIX=ko
  4. MODULES_SUBDIR := lib/modules/$(KERNEL_VERSION)
  5. LINUX_BUILD_DIR := $(BUILD_DIR)/linux-$(ARCH)-$(DEVICE)
  6. KMOD_BUILD_DIR := $(LINUX_BUILD_DIR)/linux-modules
  7. MODULES_DIR := $(LINUX_BUILD_DIR)/modules/$(MODULES_SUBDIR)
  8. TARGET_MODULES_DIR := $(LINUX_TARGET_DIR)/$(MODULES_SUBDIR)
  9. KERNEL_PKG:=$(PACKAGE_DIR)/kernel_$(DEVICE)-$(KERNEL_VERSION)_$(CPU_ARCH).$(PKG_SUFFIX)
  10. INSTALL_TARGETS:= $(KERNEL_PKG)
  11. NOINSTALL_TARGETS:=
  12. TARGETS:=
  13. # KMOD_template
  14. #
  15. # Adds a target for creating a package containing
  16. # the specified (kernel-provided) modules.
  17. # Parameters:
  18. # 1: the config symbol name (without leading 'ADK_[K,]PACKAGE_KMOD_')
  19. # this _must_ be equal to the kernel config symbol name
  20. # 2: the name for the package, should be unique
  21. # 3: actual modules to add; absolute path inside $(MODULES_DIR)
  22. # OMIT THE KERNEL-SPECIFIC EXTENSION!
  23. # 4: order of module loading at system startup; the modules in $(3) are (in their order)
  24. # added to this file, if $(6) is non-empty
  25. # 5: the kmod packages this package depends on
  26. #
  27. define KMOD_template
  28. IDEPENDK_$(1):=kernel ($(DEVICE)-$(KERNEL_VERSION)) $(foreach pkg,$(5),", $(pkg)")
  29. PKG_$(1) := $(PACKAGE_DIR)/kmod-$(2)_$(DEVICE)-$(KERNEL_VERSION)-$(KERNEL_RELEASE)_$(CPU_ARCH).$(PKG_SUFFIX)
  30. I_$(1) := $(KMOD_BUILD_DIR)/ipkg/$(2)
  31. ifeq ($$(ADK_KPACKAGE_KMOD_$(1)),m)
  32. TARGETS+=$$(PKG_$(1))
  33. endif
  34. ifeq ($$(ADK_KPACKAGE_KMOD_$(1)),y)
  35. TARGETS+=$$(PKG_$(1))
  36. INSTALL_TARGETS+=$$(PKG_$(1))
  37. endif
  38. $$(PKG_$(1)):
  39. rm -rf $$(I_$(1))
  40. @mkdir -p $$(I_$(1))
  41. echo "Package: kmod-$(2)" > $(LINUX_BUILD_DIR)/kmod-control/kmod-$(2).control
  42. echo "Priority: optional" >> $(LINUX_BUILD_DIR)/kmod-control/kmod-$(2).control
  43. echo "Section: sys" >> $(LINUX_BUILD_DIR)/kmod-control/kmod-$(2).control
  44. echo "Description: kernel module $(2)" >> $(LINUX_BUILD_DIR)/kmod-control/kmod-$(2).control
  45. ${BASH} ${SCRIPT_DIR}/make-ipkg-dir.sh $$(I_$(1)) \
  46. $(LINUX_BUILD_DIR)/kmod-control/kmod-$(2).control \
  47. $(DEVICE)-$(KERNEL_VERSION)-$(KERNEL_RELEASE) $(CPU_ARCH)
  48. echo "Depends: $$(IDEPENDK_$(1))" >> $$(I_$(1))/CONTROL/control
  49. ifneq ($(strip $(3)),)
  50. mkdir -p $$(I_$(1))/lib/modules/$(KERNEL_VERSION)
  51. $(CP) $(foreach mod,$(3),$(mod).$(LINUX_KMOD_SUFFIX)) $$(I_$(1))/lib/modules/$(KERNEL_VERSION)
  52. ifneq ($(4),)
  53. mkdir -p $$(I_$(1))/etc/modules.d
  54. for module in $(notdir $(3)); do \
  55. echo $$$$module >> $$(I_$(1))/etc/modules.d/$(4)-$(2); \
  56. done
  57. echo "#!/bin/sh" >> $$(I_$(1))/CONTROL/postinst
  58. echo "if [ -z \"\$$$${IPKG_INSTROOT}\" ]; then" >> $$(I_$(1))/CONTROL/postinst
  59. echo ". /etc/functions.sh" >> $$(I_$(1))/CONTROL/postinst
  60. echo "load_modules /etc/modules.d/$(4)-$(2)" >> $$(I_$(1))/CONTROL/postinst
  61. echo "fi" >> $$(I_$(1))/CONTROL/postinst
  62. chmod 0755 $$(I_$(1))/CONTROL/postinst
  63. endif
  64. endif
  65. $(PKG_BUILD) $$(I_$(1)) $(PACKAGE_DIR) $(MAKE_TRACE)
  66. endef
  67. include $(BUILD_DIR)/.kernelconfig