2
0

kernel-build.mk 5.2 KB

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