kernel.mk 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #
  2. # Copyright (C) 2006 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. ifeq ($(__target_inc),)
  8. include $(INCLUDE_DIR)/target.mk
  9. endif
  10. ifeq ($(DUMP),1)
  11. KERNEL?=<KERNEL>
  12. BOARD?=<BOARD>
  13. LINUX_VERSION?=<LINUX_VERSION>
  14. else
  15. ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
  16. export GCC_HONOUR_COPTS=s
  17. endif
  18. LINUX_KMOD_SUFFIX=ko
  19. ifneq (,$(findstring uml,$(BOARD)))
  20. KERNEL_CC?=$(HOSTCC)
  21. KERNEL_CROSS?=
  22. else
  23. KERNEL_CC?=$(TARGET_CC)
  24. KERNEL_CROSS?=$(TARGET_CROSS)
  25. endif
  26. ifeq ($(TARGET_BUILD),1)
  27. PATCH_DIR ?= ./patches$(if $(wildcard ./patches-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
  28. FILES_DIR ?= $(foreach dir,$(wildcard ./files ./files-$(KERNEL_PATCHVER)),"$(dir)")
  29. endif
  30. KERNEL_BUILD_DIR ?= $(BUILD_DIR_BASE)/linux-$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET))$(if $(BUILD_SUFFIX),_$(BUILD_SUFFIX))
  31. LINUX_DIR ?= $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)
  32. LINUX_UNAME_VERSION:=$(if $(word 3,$(subst ., ,$(KERNEL_BASE))),$(KERNEL_BASE),$(KERNEL_BASE).0)
  33. ifneq ($(findstring -rc,$(LINUX_VERSION)),)
  34. LINUX_UNAME_VERSION:=$(LINUX_UNAME_VERSION)-$(strip $(lastword $(subst -, ,$(LINUX_VERSION))))
  35. endif
  36. MODULES_SUBDIR:=lib/modules/$(LINUX_UNAME_VERSION)
  37. TARGET_MODULES_DIR := $(LINUX_TARGET_DIR)/$(MODULES_SUBDIR)
  38. LINUX_KERNEL:=$(KERNEL_BUILD_DIR)/vmlinux
  39. LINUX_SOURCE:=linux-$(LINUX_VERSION).tar.bz2
  40. TESTING:=$(if $(findstring -rc,$(LINUX_VERSION)),/testing,)
  41. ifeq ($(call qstrip,$(CONFIG_EXTERNAL_KERNEL_TREE)),)
  42. LINUX_SITE:=@KERNEL/linux/kernel/v$(KERNEL)$(TESTING)
  43. endif
  44. ifneq ($(TARGET_BUILD),1)
  45. PKG_BUILD_DIR ?= $(KERNEL_BUILD_DIR)/$(PKG_NAME)$(if $(PKG_VERSION),-$(PKG_VERSION))
  46. endif
  47. endif
  48. ifneq (,$(findstring uml,$(BOARD)))
  49. LINUX_KARCH=um
  50. else
  51. ifeq (,$(LINUX_KARCH))
  52. LINUX_KARCH=$(strip $(subst i386,x86,$(subst armeb,arm,$(subst mipsel,mips,$(subst mips64,mips,$(subst mips64el,mips,$(subst sh2,sh,$(subst sh3,sh,$(subst sh4,sh,$(ARCH))))))))))
  53. endif
  54. endif
  55. define KernelPackage/Defaults
  56. FILES:=
  57. AUTOLOAD:=
  58. endef
  59. define ModuleAutoLoad
  60. $(SH_FUNC) \
  61. export modules=; \
  62. add_module() { \
  63. priority="$$$$$$$$1"; \
  64. mods="$$$$$$$$2"; \
  65. boot="$$$$$$$$3"; \
  66. shift 3; \
  67. mkdir -p $(2)/etc/modules.d; \
  68. ( \
  69. [ "$$$$$$$$boot" = "1" ] && { \
  70. echo '# May be required for rootfs' ; \
  71. } ; \
  72. for mod in $$$$$$$$mods; do \
  73. echo "$$$$$$$$mod"; \
  74. done \
  75. ) > $(2)/etc/modules.d/$$$$$$$$priority-$(1); \
  76. modules="$$$$$$$${modules:+$$$$$$$$modules }$$$$$$$$priority-$(1)"; \
  77. }; \
  78. $(3) \
  79. if [ -n "$$$$$$$$modules" ]; then \
  80. mkdir -p $(2)/etc/modules.d; \
  81. mkdir -p $(2)/CONTROL; \
  82. echo "#!/bin/sh" > $(2)/CONTROL/postinst; \
  83. echo "[ -z \"\$$$$$$$$IPKG_INSTROOT\" ] || exit 0" >> $(2)/CONTROL/postinst; \
  84. echo ". /etc/functions.sh" >> $(2)/CONTROL/postinst; \
  85. echo "load_modules $$$$$$$$modules" >> $(2)/CONTROL/postinst; \
  86. chmod 0755 $(2)/CONTROL/postinst; \
  87. fi
  88. endef
  89. ifeq ($(DUMP)$(TARGET_BUILD),)
  90. -include $(LINUX_DIR)/.config
  91. endif
  92. define KernelPackage/depends
  93. $(STAMP_BUILT): $(LINUX_DIR)/.config
  94. define KernelPackage/depends
  95. endef
  96. endef
  97. define KernelPackage
  98. NAME:=$(1)
  99. $(eval $(call Package/Default))
  100. $(eval $(call KernelPackage/Defaults))
  101. $(eval $(call KernelPackage/$(1)))
  102. $(eval $(call KernelPackage/$(1)/$(BOARD)))
  103. define Package/kmod-$(1)
  104. TITLE:=$(TITLE)
  105. SECTION:=kernel
  106. CATEGORY:=Kernel modules
  107. DESCRIPTION:=$(DESCRIPTION)
  108. EXTRA_DEPENDS:=kernel (=$(LINUX_VERSION)-$(LINUX_RELEASE))
  109. VERSION:=$(LINUX_VERSION)$(if $(PKG_VERSION),+$(PKG_VERSION))-$(if $(PKG_RELEASE),$(PKG_RELEASE),$(LINUX_RELEASE))
  110. $(call KernelPackage/$(1))
  111. $(call KernelPackage/$(1)/$(BOARD))
  112. endef
  113. ifdef KernelPackage/$(1)/description
  114. define Package/kmod-$(1)/description
  115. $(call KernelPackage/$(1)/description)
  116. endef
  117. endif
  118. ifdef KernelPackage/$(1)/config
  119. define Package/kmod-$(1)/config
  120. $(call KernelPackage/$(1)/config)
  121. endef
  122. endif
  123. $(call KernelPackage/depends)
  124. ifneq ($(if $(filter-out %=y %=n %=m,$(KCONFIG)),$(filter m,$(foreach c,$(filter-out %=y %=n %=m,$(KCONFIG)),$($(c)))),.),)
  125. ifneq ($(strip $(FILES)),)
  126. define Package/kmod-$(1)/install
  127. mkdir -p $$(1)/$(MODULES_SUBDIR)
  128. $(CP) -L $$(FILES) $$(1)/$(MODULES_SUBDIR)/
  129. $(call ModuleAutoLoad,$(1),$$(1),$(AUTOLOAD))
  130. $(call KernelPackage/$(1)/install,$$(1))
  131. endef
  132. endif
  133. $(if $(CONFIG_PACKAGE_kmod-$(1)),
  134. else
  135. compile: kmod-$(1)-unavailable
  136. kmod-$(1)-unavailable:
  137. @echo "WARNING: kmod-$(1) is not available in the kernel config"
  138. )
  139. endif
  140. $$(eval $$(call BuildPackage,kmod-$(1)))
  141. $$(IPKG_kmod-$(1)): $$(wildcard $$(FILES))
  142. endef
  143. define AutoLoad
  144. add_module "$(1)" "$(2)" "$(3)";
  145. endef
  146. version_field=$(if $(word $(1),$(2)),$(word $(1),$(2)),0)
  147. kernel_version_merge=$$(( ($(call version_field,1,$(1)) << 24) + ($(call version_field,2,$(1)) << 16) + ($(call version_field,3,$(1)) << 8) + $(call version_field,4,$(1)) ))
  148. ifdef DUMP
  149. kernel_version_cmp=
  150. else
  151. kernel_version_cmp=$(shell [ $(call kernel_version_merge,$(call split_version,$(2))) $(1) $(call kernel_version_merge,$(call split_version,$(3))) ] && echo 1 )
  152. endif
  153. CompareKernelPatchVer=$(if $(call kernel_version_cmp,-$(2),$(1),$(3)),1,0)
  154. kernel_patchver_gt=$(call kernel_version_cmp,-gt,$(KERNEL_PATCHVER),$(1))
  155. kernel_patchver_ge=$(call kernel_version_cmp,-ge,$(KERNEL_PATCHVER),$(1))
  156. kernel_patchver_eq=$(call kernel_version_cmp,-eq,$(KERNEL_PATCHVER),$(1))
  157. kernel_patchver_le=$(call kernel_version_cmp,-lt,$(KERNEL_PATCHVER),$(1))
  158. kernel_patchver_lt=$(call kernel_version_cmp,-le,$(KERNEL_PATCHVER),$(1))