kernel-build.mk 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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: export STAGING_PREFIX=$$(STAGING_DIR_HOST)
  117. $(LINUX_DIR)/.modules: export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig
  118. $(LINUX_DIR)/.modules: export PKG_CONFIG_LIBDIR=$$(STAGING_DIR_HOST)/lib/pkgconfig
  119. $(LINUX_DIR)/.modules: $(STAMP_CONFIGURED) $(LINUX_DIR)/.config FORCE
  120. $(Kernel/CompileModules)
  121. touch $$@
  122. $(LINUX_DIR)/.image: export STAGING_PREFIX=$$(STAGING_DIR_HOST)
  123. $(LINUX_DIR)/.image: export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig
  124. $(LINUX_DIR)/.image: export PKG_CONFIG_LIBDIR=$$(STAGING_DIR_HOST)/lib/pkgconfig
  125. $(LINUX_DIR)/.image: $(STAMP_CONFIGURED) $(if $(CONFIG_STRIP_KERNEL_EXPORTS),$(KERNEL_BUILD_DIR)/symtab.h) FORCE
  126. $(Kernel/CompileImage)
  127. $(Kernel/CollectDebug)
  128. touch $$@
  129. mostlyclean: FORCE
  130. $(Kernel/Clean)
  131. define BuildKernel
  132. endef
  133. download: $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
  134. prepare: $(STAMP_PREPARED)
  135. compile: $(LINUX_DIR)/.modules
  136. $(MAKE) -C image compile TARGET_BUILD=
  137. oldconfig menuconfig nconfig: $(STAMP_PREPARED) $(STAMP_CHECKED) FORCE
  138. rm -f $(LINUX_DIR)/.config.prev
  139. rm -f $(STAMP_CONFIGURED)
  140. $(LINUX_RECONF_CMD) > $(LINUX_DIR)/.config
  141. $(_SINGLE)$(KERNEL_MAKE) \
  142. $(if $(findstring Darwin,$(HOST_OS)),HOST_LOADLIBES="-L$(STAGING_DIR_HOST)/lib -lncurses") \
  143. $$@
  144. $(LINUX_RECONF_DIFF) $(LINUX_DIR)/.config > $(LINUX_RECONFIG_TARGET)
  145. install: $(LINUX_DIR)/.image
  146. +$(MAKE) -C image compile install TARGET_BUILD=
  147. clean: FORCE
  148. rm -rf $(KERNEL_BUILD_DIR)
  149. image-prereq:
  150. @+$(NO_TRACE_MAKE) -s -C image prereq TARGET_BUILD=
  151. prereq: image-prereq
  152. endef