kernel-build.mk 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #
  2. # Copyright (C) 2006-2007 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. include $(INCLUDE_DIR)/host.mk
  8. include $(INCLUDE_DIR)/prereq.mk
  9. include $(INCLUDE_DIR)/depends.mk
  10. ifneq ($(DUMP),1)
  11. all: compile
  12. endif
  13. KERNEL_FILE_DEPENDS=$(GENERIC_PATCH_DIR) $(PATCH_DIR) $(GENERIC_FILES_DIR) $(FILES_DIR)
  14. STAMP_PREPARED=$(LINUX_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,$(KERNEL_FILE_DEPENDS),)))
  15. STAMP_CONFIGURED:=$(LINUX_DIR)/.configured
  16. include $(INCLUDE_DIR)/download.mk
  17. include $(INCLUDE_DIR)/quilt.mk
  18. include $(INCLUDE_DIR)/kernel-defaults.mk
  19. define Kernel/Prepare
  20. $(call Kernel/Prepare/Default)
  21. endef
  22. define Kernel/Configure
  23. $(call Kernel/Configure/Default)
  24. endef
  25. define Kernel/CompileModules
  26. $(call Kernel/CompileModules/Default)
  27. endef
  28. define Kernel/CompileImage
  29. $(call Kernel/CompileImage/Default)
  30. $(call Kernel/CompileImage/Initramfs)
  31. endef
  32. define Kernel/Clean
  33. $(call Kernel/Clean/Default)
  34. endef
  35. define Download/kernel
  36. URL:=$(LINUX_SITE)
  37. FILE:=$(LINUX_SOURCE)
  38. MD5SUM:=$(LINUX_KERNEL_MD5SUM)
  39. endef
  40. KERNEL_GIT_OPTS:=
  41. ifneq ($(strip $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)),"")
  42. KERNEL_GIT_OPTS+=--reference $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)
  43. endif
  44. ifneq ($(strip $(CONFIG_KERNEL_GIT_BRANCH)),"")
  45. KERNEL_GIT_OPTS+=--branch $(CONFIG_KERNEL_GIT_BRANCH)
  46. endif
  47. define Download/git-kernel
  48. URL:=$(call qstrip,$(CONFIG_KERNEL_GIT_CLONE_URI))
  49. PROTO:=git
  50. VERSION:=$(CONFIG_KERNEL_GIT_BRANCH)
  51. FILE:=$(LINUX_SOURCE)
  52. SUBDIR:=linux-$(KERNEL_PATCHVER)
  53. OPTS:=$(KERNEL_GIT_OPTS)
  54. endef
  55. ifdef CONFIG_COLLECT_KERNEL_DEBUG
  56. define Kernel/CollectDebug
  57. rm -rf $(KERNEL_BUILD_DIR)/debug
  58. mkdir -p $(KERNEL_BUILD_DIR)/debug/modules
  59. $(CP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/debug/
  60. -$(CP) \
  61. $(STAGING_DIR_ROOT)/lib/modules/$(LINUX_VERSION)/* \
  62. $(KERNEL_BUILD_DIR)/debug/modules/
  63. $(FIND) $(KERNEL_BUILD_DIR)/debug -type f | $(XARGS) $(KERNEL_CROSS)strip --only-keep-debug
  64. $(TAR) c -C $(KERNEL_BUILD_DIR) debug \
  65. $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  66. | bzip2 -c -9 > $(BIN_DIR)/kernel-debug.tar.bz2
  67. endef
  68. endif
  69. ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),)
  70. ifneq ($(if $(QUILT),,$(CONFIG_AUTOREBUILD)),)
  71. define Kernel/Autoclean
  72. $(PKG_BUILD_DIR)/.dep_files: $(STAMP_PREPARED)
  73. $(call rdep,$(KERNEL_FILE_DEPENDS),$(STAMP_PREPARED),$(PKG_BUILD_DIR)/.dep_files,-x "*/.dep_*")
  74. endef
  75. endif
  76. endif
  77. define BuildKernel
  78. $(if $(QUILT),$(Build/Quilt))
  79. $(if $(LINUX_SITE),$(call Download,kernel))
  80. $(if $(call qstrip,$(CONFIG_KERNEL_GIT_CLONE_URI)),$(call Download,git-kernel))
  81. .NOTPARALLEL:
  82. $(Kernel/Autoclean)
  83. $(STAMP_PREPARED): $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
  84. -rm -rf $(KERNEL_BUILD_DIR)
  85. -mkdir -p $(KERNEL_BUILD_DIR)
  86. $(Kernel/Prepare)
  87. touch $$@
  88. $(KERNEL_BUILD_DIR)/symtab.h: FORCE
  89. rm -f $(KERNEL_BUILD_DIR)/symtab.h
  90. touch $(KERNEL_BUILD_DIR)/symtab.h
  91. +$(MAKE) $(KERNEL_MAKEOPTS) vmlinux
  92. find $(LINUX_DIR) $(STAGING_DIR_ROOT)/lib/modules -name \*.ko | \
  93. xargs $(TARGET_CROSS)nm | \
  94. awk '$$$$1 == "U" { print $$$$2 } ' | \
  95. sort -u > $(KERNEL_BUILD_DIR)/mod_symtab.txt
  96. $(TARGET_CROSS)nm -n $(LINUX_DIR)/vmlinux.o | grep ' [rR] __ksymtab' | sed -e 's,........ [rR] __ksymtab_,,' > $(KERNEL_BUILD_DIR)/kernel_symtab.txt
  97. grep -Ff $(KERNEL_BUILD_DIR)/mod_symtab.txt $(KERNEL_BUILD_DIR)/kernel_symtab.txt > $(KERNEL_BUILD_DIR)/sym_include.txt
  98. grep -Fvf $(KERNEL_BUILD_DIR)/mod_symtab.txt $(KERNEL_BUILD_DIR)/kernel_symtab.txt > $(KERNEL_BUILD_DIR)/sym_exclude.txt
  99. ( \
  100. echo '#define SYMTAB_KEEP \'; \
  101. cat $(KERNEL_BUILD_DIR)/sym_include.txt | \
  102. awk '{print "KEEP(*(___ksymtab+" $$$$1 ")) \\" }'; \
  103. echo; \
  104. echo '#define SYMTAB_KEEP_GPL \'; \
  105. cat $(KERNEL_BUILD_DIR)/sym_include.txt | \
  106. awk '{print "KEEP(*(___ksymtab_gpl+" $$$$1 ")) \\" }'; \
  107. echo; \
  108. echo '#define SYMTAB_DISCARD \'; \
  109. cat $(KERNEL_BUILD_DIR)/sym_exclude.txt | \
  110. awk '{print "*(___ksymtab+" $$$$1 ") \\" }'; \
  111. echo; \
  112. echo '#define SYMTAB_DISCARD_GPL \'; \
  113. cat $(KERNEL_BUILD_DIR)/sym_exclude.txt | \
  114. awk '{print "*(___ksymtab_gpl+" $$$$1 ") \\" }'; \
  115. echo; \
  116. ) > $$@
  117. $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(LINUX_KCONFIG_LIST) $(TOPDIR)/.config FORCE
  118. $(Kernel/Configure)
  119. touch $$@
  120. $(LINUX_DIR)/.modules: $(STAMP_CONFIGURED) $(LINUX_DIR)/.config FORCE
  121. $(Kernel/CompileModules)
  122. touch $$@
  123. $(LINUX_DIR)/.image: $(STAMP_CONFIGURED) $(if $(CONFIG_STRIP_KERNEL_EXPORTS),$(KERNEL_BUILD_DIR)/symtab.h) FORCE
  124. $(Kernel/CompileImage)
  125. $(Kernel/CollectDebug)
  126. touch $$@
  127. mostlyclean: FORCE
  128. $(Kernel/Clean)
  129. define BuildKernel
  130. endef
  131. download: $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
  132. prepare: $(STAMP_CONFIGURED)
  133. compile: $(LINUX_DIR)/.modules
  134. $(MAKE) -C image compile TARGET_BUILD=
  135. oldconfig menuconfig nconfig: $(STAMP_PREPARED) $(STAMP_CHECKED) FORCE
  136. rm -f $(LINUX_DIR)/.config.prev
  137. rm -f $(STAMP_CONFIGURED)
  138. $(LINUX_RECONF_CMD) > $(LINUX_DIR)/.config
  139. $(_SINGLE)$(MAKE) -C $(LINUX_DIR) $(KERNEL_MAKEOPTS) HOST_LOADLIBES="-L$(STAGING_DIR_HOST)/lib -lncurses" $$@
  140. $(LINUX_RECONF_DIFF) $(LINUX_DIR)/.config > $(LINUX_RECONFIG_TARGET)
  141. install: $(LINUX_DIR)/.image
  142. +$(MAKE) -C image compile install TARGET_BUILD=
  143. clean: FORCE
  144. rm -rf $(KERNEL_BUILD_DIR)
  145. image-prereq:
  146. @+$(NO_TRACE_MAKE) -s -C image prereq TARGET_BUILD=
  147. prereq: image-prereq
  148. endef