kernel-build.mk 4.0 KB

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