kernel.mk 4.5 KB

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