kernel-build.mk 4.1 KB

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