kernel-build.mk 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. ifneq ($(DUMP),1)
  10. all: compile
  11. endif
  12. export QUILT=1
  13. STAMP_PREPARED:=$(LINUX_DIR)/.prepared
  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. MD5SUM:=$(LINUX_KERNEL_MD5SUM)
  38. endef
  39. ifdef CONFIG_COLLECT_KERNEL_DEBUG
  40. define Kernel/CollectDebug
  41. rm -rf $(KERNEL_BUILD_DIR)/debug
  42. mkdir -p $(KERNEL_BUILD_DIR)/debug/modules
  43. $(CP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/debug/
  44. -$(CP) \
  45. $(STAGING_DIR_ROOT)/lib/modules/$(LINUX_VERSION)/* \
  46. $(KERNEL_BUILD_DIR)/debug/modules/
  47. $(FIND) $(KERNEL_BUILD_DIR)/debug -type f | $(XARGS) $(KERNEL_CROSS)strip --only-keep-debug
  48. $(TAR) c -C $(KERNEL_BUILD_DIR) debug \
  49. $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  50. | bzip2 -c -9 > $(BIN_DIR)/kernel-debug.tar.bz2
  51. endef
  52. endif
  53. define BuildKernel
  54. $(if $(QUILT),$(Build/Quilt))
  55. $(if $(LINUX_SITE),$(call Download,kernel))
  56. .NOTPARALLEL:
  57. $(STAMP_PREPARED): $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
  58. -rm -rf $(KERNEL_BUILD_DIR)
  59. -mkdir -p $(KERNEL_BUILD_DIR)
  60. $(Kernel/Prepare)
  61. touch $$@
  62. $(KERNEL_BUILD_DIR)/symtab.h: FORCE
  63. rm -f $(KERNEL_BUILD_DIR)/symtab.h
  64. touch $(KERNEL_BUILD_DIR)/symtab.h
  65. +$(MAKE) $(KERNEL_MAKEOPTS) vmlinux
  66. find $(LINUX_DIR) $(STAGING_DIR_ROOT)/lib/modules -name \*.ko | \
  67. xargs $(TARGET_CROSS)nm | \
  68. awk '$$$$1 == "U" { print $$$$2 } ' | \
  69. sort -u > $(KERNEL_BUILD_DIR)/mod_symtab.txt
  70. $(TARGET_CROSS)nm -n $(LINUX_DIR)/vmlinux.o | grep ' [rR] __ksymtab' | sed -e 's,........ [rR] __ksymtab_,,' > $(KERNEL_BUILD_DIR)/kernel_symtab.txt
  71. grep -Ff $(KERNEL_BUILD_DIR)/mod_symtab.txt $(KERNEL_BUILD_DIR)/kernel_symtab.txt > $(KERNEL_BUILD_DIR)/sym_include.txt
  72. grep -Fvf $(KERNEL_BUILD_DIR)/mod_symtab.txt $(KERNEL_BUILD_DIR)/kernel_symtab.txt > $(KERNEL_BUILD_DIR)/sym_exclude.txt
  73. ( \
  74. echo '#define SYMTAB_KEEP \'; \
  75. cat $(KERNEL_BUILD_DIR)/sym_include.txt | \
  76. awk '{print "KEEP(*(___ksymtab+" $$$$1 ")) \\" }'; \
  77. echo; \
  78. echo '#define SYMTAB_KEEP_GPL \'; \
  79. cat $(KERNEL_BUILD_DIR)/sym_include.txt | \
  80. awk '{print "KEEP(*(___ksymtab_gpl+" $$$$1 ")) \\" }'; \
  81. echo; \
  82. echo '#define SYMTAB_DISCARD \'; \
  83. cat $(KERNEL_BUILD_DIR)/sym_exclude.txt | \
  84. awk '{print "*(___ksymtab+" $$$$1 ") \\" }'; \
  85. echo; \
  86. echo '#define SYMTAB_DISCARD_GPL \'; \
  87. cat $(KERNEL_BUILD_DIR)/sym_exclude.txt | \
  88. awk '{print "*(___ksymtab_gpl+" $$$$1 ") \\" }'; \
  89. echo; \
  90. ) > $$@
  91. $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(LINUX_KCONFIG_LIST) $(TOPDIR)/.config
  92. $(Kernel/Configure)
  93. touch $$@
  94. $(LINUX_DIR)/.modules: $(STAMP_CONFIGURED) $(LINUX_DIR)/.config FORCE
  95. $(Kernel/CompileModules)
  96. touch $$@
  97. $(LINUX_DIR)/.image: $(STAMP_CONFIGURED) $(if $(CONFIG_STRIP_KERNEL_EXPORTS),$(KERNEL_BUILD_DIR)/symtab.h) FORCE
  98. $(Kernel/CompileImage)
  99. $(Kernel/CollectDebug)
  100. touch $$@
  101. mostlyclean: FORCE
  102. $(Kernel/Clean)
  103. define BuildKernel
  104. endef
  105. download: $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
  106. prepare: $(STAMP_CONFIGURED)
  107. compile: $(LINUX_DIR)/.modules
  108. $(MAKE) -C image compile TARGET_BUILD=
  109. oldconfig menuconfig nconfig: $(STAMP_PREPARED) $(STAMP_CHECKED) FORCE
  110. rm -f $(LINUX_DIR)/.config.prev
  111. rm -f $(STAMP_CONFIGURED)
  112. $(LINUX_RECONF_CMD) > $(LINUX_DIR)/.config
  113. $(_SINGLE)$(MAKE) -C $(LINUX_DIR) $(KERNEL_MAKEOPTS) $$@
  114. $(LINUX_RECONF_DIFF) $(LINUX_DIR)/.config > $(LINUX_RECONFIG_TARGET)
  115. install: $(LINUX_DIR)/.image
  116. +$(MAKE) -C image compile install TARGET_BUILD=
  117. clean: FORCE
  118. rm -rf $(KERNEL_BUILD_DIR)
  119. image-prereq:
  120. @+$(NO_TRACE_MAKE) -s -C image prereq TARGET_BUILD=
  121. prereq: image-prereq
  122. endef