kernel.mk 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. [ "$$$$$$$$3" = "1" ] && { \
  61. echo '# May be required for rootfs' ; \
  62. } ; \
  63. for mod in $$$$$$$$2; do \
  64. getvar mod; \
  65. done \
  66. ) > $(2)/etc/modules.d/$$$$$$$$1-$(1); \
  67. modules="$$$$$$$${modules:+$$$$$$$$modules }$$$$$$$$1-$(1)"; \
  68. }; \
  69. $(3) \
  70. if [ -n "$$$$$$$$modules" ]; then \
  71. mkdir -p $(2)/etc/modules.d; \
  72. mkdir -p $(2)/CONTROL; \
  73. echo "#!/bin/sh" > $(2)/CONTROL/postinst; \
  74. echo "[ -z \"\$$$$$$$$IPKG_INSTROOT\" ] || exit 0" >> $(2)/CONTROL/postinst; \
  75. echo ". /etc/functions.sh" >> $(2)/CONTROL/postinst; \
  76. echo "load_modules $$$$$$$$modules" >> $(2)/CONTROL/postinst; \
  77. chmod 0755 $(2)/CONTROL/postinst; \
  78. fi
  79. endef
  80. ifeq ($(DUMP)$(TARGET_BUILD),)
  81. -include $(LINUX_DIR)/.config
  82. endif
  83. define KernelPackage/depends
  84. $(STAMP_BUILT): $(LINUX_DIR)/.config
  85. define KernelPackage/depends
  86. endef
  87. endef
  88. define KernelPackage
  89. NAME:=$(1)
  90. $(eval $(call Package/Default))
  91. $(eval $(call KernelPackage/Defaults))
  92. $(eval $(call KernelPackage/$(1)))
  93. $(eval $(call KernelPackage/$(1)/$(KERNEL)))
  94. $(eval $(call KernelPackage/$(1)/$(BOARD)))
  95. define Package/kmod-$(1)
  96. TITLE:=$(TITLE)
  97. SECTION:=kernel
  98. CATEGORY:=Kernel modules
  99. DESCRIPTION:=$(DESCRIPTION)
  100. EXTRA_DEPENDS:=kernel (=$(LINUX_VERSION)-$(LINUX_RELEASE))
  101. VERSION:=$(LINUX_VERSION)$(if $(PKG_VERSION),+$(PKG_VERSION))-$(if $(PKG_RELEASE),$(PKG_RELEASE),$(LINUX_RELEASE))
  102. $(call KernelPackage/$(1))
  103. $(call KernelPackage/$(1)/$(KERNEL))
  104. $(call KernelPackage/$(1)/$(BOARD))
  105. endef
  106. ifdef KernelPackage/$(1)/description
  107. define Package/kmod-$(1)/description
  108. $(call KernelPackage/$(1)/description)
  109. endef
  110. endif
  111. ifdef KernelPackage/$(1)/config
  112. define Package/kmod-$(1)/config
  113. $(call KernelPackage/$(1)/config)
  114. endef
  115. endif
  116. $(call KernelPackage/depends)
  117. ifneq ($(if $(filter-out %=y %=n %=m,$(KCONFIG)),$(filter m,$(foreach c,$(filter-out %=y %=n %=m,$(KCONFIG)),$($(c)))),.),)
  118. ifneq ($(strip $(FILES)),)
  119. define Package/kmod-$(1)/install
  120. mkdir -p $$(1)/lib/modules/$(LINUX_VERSION)
  121. $(CP) -L $$(FILES) $$(1)/lib/modules/$(LINUX_VERSION)/
  122. $(call ModuleAutoLoad,$(1),$$(1),$(AUTOLOAD))
  123. $(call KernelPackage/$(1)/install,$$(1))
  124. endef
  125. endif
  126. $(if $(CONFIG_PACKAGE_kmod-$(1)),
  127. else
  128. compile: kmod-$(1)-unavailable
  129. kmod-$(1)-unavailable:
  130. @echo "WARNING: kmod-$(1) is not available in the kernel config"
  131. )
  132. endif
  133. $$(eval $$(call BuildPackage,kmod-$(1)))
  134. $$(IPKG_kmod-$(1)): $$(wildcard $$(FILES))
  135. endef
  136. define AutoLoad
  137. add_module $(1) "$(2)" $(3);
  138. endef
  139. ifdef DUMP
  140. CompareKernelPatchVer=0
  141. else
  142. define CompareKernelPatchVer
  143. $(shell [ $$(echo $(1) | tr . 0) -$(2) $$(echo $(3) | tr . 0) ] && echo 1 || echo 0)
  144. endef
  145. endif