2
0

kernel.mk 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. export GCC_HONOUR_COPTS=s
  16. LINUX_KMOD_SUFFIX=ko
  17. ifneq (,$(findstring uml,$(BOARD)))
  18. KERNEL_CC?=$(HOSTCC)
  19. KERNEL_CROSS?=
  20. else
  21. KERNEL_CC?=$(TARGET_CC)
  22. KERNEL_CROSS?=$(TARGET_CROSS)
  23. endif
  24. ifeq ($(TARGET_BUILD),1)
  25. PATCH_DIR ?= ./patches$(if $(wildcard ./patches-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
  26. FILES_DIR ?= $(foreach dir,$(wildcard ./files ./files-$(KERNEL_PATCHVER)),"$(dir)")
  27. endif
  28. KERNEL_BUILD_DIR ?= $(BUILD_DIR_BASE)/linux-$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET))$(if $(BUILD_SUFFIX),_$(BUILD_SUFFIX))
  29. LINUX_DIR ?= $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)
  30. MODULES_SUBDIR:=lib/modules/$(LINUX_VERSION)
  31. TARGET_MODULES_DIR := $(LINUX_TARGET_DIR)/$(MODULES_SUBDIR)
  32. LINUX_KERNEL:=$(KERNEL_BUILD_DIR)/vmlinux
  33. LINUX_SOURCE:=linux-$(LINUX_VERSION).tar.bz2
  34. TESTING:=$(if $(findstring -rc,$(LINUX_VERSION)),/testing,)
  35. ifeq ($(call qstrip,$(CONFIG_EXTERNAL_KERNEL_TREE)),)
  36. LINUX_SITE:=@KERNEL/linux/kernel/v$(KERNEL)$(TESTING)
  37. endif
  38. ifneq ($(TARGET_BUILD),1)
  39. PKG_BUILD_DIR ?= $(KERNEL_BUILD_DIR)/$(PKG_NAME)$(if $(PKG_VERSION),-$(PKG_VERSION))
  40. endif
  41. endif
  42. ifneq (,$(findstring uml,$(BOARD)))
  43. LINUX_KARCH=um
  44. else
  45. ifeq (,$(LINUX_KARCH))
  46. 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))))))))))
  47. endif
  48. endif
  49. define KernelPackage/Defaults
  50. FILES:=
  51. AUTOLOAD:=
  52. endef
  53. define ModuleAutoLoad
  54. $(SH_FUNC) \
  55. export modules=; \
  56. add_module() { \
  57. mkdir -p $(2)/etc/modules.d; \
  58. ( \
  59. [ "$$$$$$$$3" = "1" ] && { \
  60. echo '# May be required for rootfs' ; \
  61. } ; \
  62. for mod in $$$$$$$$2; do \
  63. getvar mod; \
  64. done \
  65. ) > $(2)/etc/modules.d/$$$$$$$$1-$(1); \
  66. modules="$$$$$$$${modules:+$$$$$$$$modules }$$$$$$$$1-$(1)"; \
  67. }; \
  68. $(3) \
  69. if [ -n "$$$$$$$$modules" ]; then \
  70. mkdir -p $(2)/etc/modules.d; \
  71. mkdir -p $(2)/CONTROL; \
  72. echo "#!/bin/sh" > $(2)/CONTROL/postinst; \
  73. echo "[ -z \"\$$$$$$$$IPKG_INSTROOT\" ] || exit 0" >> $(2)/CONTROL/postinst; \
  74. echo ". /etc/functions.sh" >> $(2)/CONTROL/postinst; \
  75. echo "load_modules $$$$$$$$modules" >> $(2)/CONTROL/postinst; \
  76. chmod 0755 $(2)/CONTROL/postinst; \
  77. fi
  78. endef
  79. ifeq ($(DUMP)$(TARGET_BUILD),)
  80. -include $(LINUX_DIR)/.config
  81. endif
  82. define KernelPackage/depends
  83. $(STAMP_BUILT): $(LINUX_DIR)/.config
  84. define KernelPackage/depends
  85. endef
  86. endef
  87. define KernelPackage
  88. NAME:=$(1)
  89. $(eval $(call Package/Default))
  90. $(eval $(call KernelPackage/Defaults))
  91. $(eval $(call KernelPackage/$(1)))
  92. $(eval $(call KernelPackage/$(1)/$(KERNEL)))
  93. $(eval $(call KernelPackage/$(1)/$(BOARD)))
  94. define Package/kmod-$(1)
  95. TITLE:=$(TITLE)
  96. SECTION:=kernel
  97. CATEGORY:=Kernel modules
  98. DESCRIPTION:=$(DESCRIPTION)
  99. EXTRA_DEPENDS:=kernel (=$(LINUX_VERSION)-$(LINUX_RELEASE))
  100. VERSION:=$(LINUX_VERSION)$(if $(PKG_VERSION),+$(PKG_VERSION))-$(if $(PKG_RELEASE),$(PKG_RELEASE),$(LINUX_RELEASE))
  101. $(call KernelPackage/$(1))
  102. $(call KernelPackage/$(1)/$(KERNEL))
  103. $(call KernelPackage/$(1)/$(BOARD))
  104. endef
  105. ifdef KernelPackage/$(1)/description
  106. define Package/kmod-$(1)/description
  107. $(call KernelPackage/$(1)/description)
  108. endef
  109. endif
  110. ifdef KernelPackage/$(1)/config
  111. define Package/kmod-$(1)/config
  112. $(call KernelPackage/$(1)/config)
  113. endef
  114. endif
  115. $(call KernelPackage/depends)
  116. ifneq ($(if $(filter-out %=y %=n %=m,$(KCONFIG)),$(filter m,$(foreach c,$(filter-out %=y %=n %=m,$(KCONFIG)),$($(c)))),.),)
  117. ifneq ($(strip $(FILES)),)
  118. define Package/kmod-$(1)/install
  119. mkdir -p $$(1)/lib/modules/$(LINUX_VERSION)
  120. $(CP) -L $$(FILES) $$(1)/lib/modules/$(LINUX_VERSION)/
  121. $(call ModuleAutoLoad,$(1),$$(1),$(AUTOLOAD))
  122. $(call KernelPackage/$(1)/install,$$(1))
  123. endef
  124. endif
  125. $(if $(CONFIG_PACKAGE_kmod-$(1)),
  126. else
  127. compile: kmod-$(1)-unavailable
  128. kmod-$(1)-unavailable:
  129. @echo "WARNING: kmod-$(1) is not available in the kernel config"
  130. )
  131. endif
  132. $$(eval $$(call BuildPackage,kmod-$(1)))
  133. $$(IPKG_kmod-$(1)): $$(wildcard $$(FILES))
  134. endef
  135. define AutoLoad
  136. add_module $(1) "$(2)" $(3);
  137. endef
  138. ifdef DUMP
  139. CompareKernelPatchVer=0
  140. else
  141. define CompareKernelPatchVer
  142. $(shell [ $$(echo $(1) | tr . 0) -$(2) $$(echo $(3) | tr . 0) ] && echo 1 || echo 0)
  143. endef
  144. endif