kernel-defaults.mk 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #
  2. # Copyright (C) 2006-2015 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. KERNEL_MAKEOPTS := -C $(LINUX_DIR) \
  8. HOSTCFLAGS="$(HOST_CFLAGS) -Wall -Wmissing-prototypes -Wstrict-prototypes" \
  9. CROSS_COMPILE="$(KERNEL_CROSS)" \
  10. ARCH="$(LINUX_KARCH)" \
  11. KBUILD_HAVE_NLS=no \
  12. CONFIG_SHELL="$(BASH)" \
  13. $(if $(findstring c,$(OPENWRT_VERBOSE)),V=1,V='')
  14. ifdef CONFIG_STRIP_KERNEL_EXPORTS
  15. KERNEL_MAKEOPTS += \
  16. EXTRA_LDSFLAGS="-I$(KERNEL_BUILD_DIR) -include symtab.h"
  17. endif
  18. INITRAMFS_EXTRA_FILES ?= $(GENERIC_PLATFORM_DIR)/image/initramfs-base-files.txt
  19. ifneq (,$(KERNEL_CC))
  20. KERNEL_MAKEOPTS += CC="$(KERNEL_CC)"
  21. endif
  22. ifdef CONFIG_USE_SPARSE
  23. KERNEL_MAKEOPTS += C=1 CHECK=$(STAGING_DIR_HOST)/bin/sparse
  24. endif
  25. export HOST_EXTRACFLAGS=-I$(STAGING_DIR_HOST)/include
  26. # defined in quilt.mk
  27. Kernel/Patch:=$(Kernel/Patch/Default)
  28. KERNEL_GIT_OPTS:=
  29. ifneq ($(strip $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)),"")
  30. KERNEL_GIT_OPTS+=--reference $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)
  31. endif
  32. ifneq ($(strip $(CONFIG_KERNEL_GIT_BRANCH)),"")
  33. KERNEL_GIT_OPTS+=--branch $(CONFIG_KERNEL_GIT_BRANCH)
  34. endif
  35. ifeq ($(strip $(CONFIG_EXTERNAL_KERNEL_TREE)),"")
  36. ifeq ($(strip $(CONFIG_KERNEL_GIT_CLONE_URI)),"")
  37. define Kernel/Prepare/Default
  38. xzcat $(DL_DIR)/$(LINUX_SOURCE) | $(TAR) -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
  39. $(Kernel/Patch)
  40. touch $(LINUX_DIR)/.quilt_used
  41. endef
  42. else
  43. define Kernel/Prepare/Default
  44. git clone $(KERNEL_GIT_OPTS) $(CONFIG_KERNEL_GIT_CLONE_URI) $(LINUX_DIR)
  45. endef
  46. endif
  47. else
  48. define Kernel/Prepare/Default
  49. mkdir -p $(KERNEL_BUILD_DIR)
  50. if [ -d $(LINUX_DIR) ]; then \
  51. rmdir $(LINUX_DIR); \
  52. fi
  53. ln -s $(CONFIG_EXTERNAL_KERNEL_TREE) $(LINUX_DIR)
  54. endef
  55. endif
  56. ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
  57. ifeq ($(strip $(CONFIG_EXTERNAL_CPIO)),"")
  58. define Kernel/SetInitramfs/PreConfigure
  59. grep -v -e INITRAMFS -e CONFIG_RD_ -e CONFIG_BLK_DEV_INITRD $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
  60. echo 'CONFIG_BLK_DEV_INITRD=y' >> $(LINUX_DIR)/.config
  61. echo 'CONFIG_INITRAMFS_SOURCE="$(strip $(TARGET_DIR) $(INITRAMFS_EXTRA_FILES))"' >> $(LINUX_DIR)/.config
  62. endef
  63. else
  64. define Kernel/SetInitramfs/PreConfigure
  65. grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
  66. echo 'CONFIG_INITRAMFS_SOURCE="$(call qstrip,$(CONFIG_EXTERNAL_CPIO))"' >> $(LINUX_DIR)/.config
  67. endef
  68. endif
  69. define Kernel/SetInitramfs
  70. mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
  71. $(call Kernel/SetInitramfs/PreConfigure)
  72. echo 'CONFIG_INITRAMFS_ROOT_UID=$(shell id -u)' >> $(LINUX_DIR)/.config
  73. echo 'CONFIG_INITRAMFS_ROOT_GID=$(shell id -g)' >> $(LINUX_DIR)/.config
  74. echo "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_NONE),CONFIG_INITRAMFS_COMPRESSION_NONE=y,# CONFIG_INITRAMFS_COMPRESSION_NONE is not set)" >> $(LINUX_DIR)/.config
  75. echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP),CONFIG_INITRAMFS_COMPRESSION_GZIP=y\nCONFIG_RD_GZIP=y,# CONFIG_INITRAMFS_COMPRESSION_GZIP is not set\n# CONFIG_RD_GZIP is not set)" >> $(LINUX_DIR)/.config
  76. echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2),CONFIG_INITRAMFS_COMPRESSION_BZIP2=y\nCONFIG_RD_BZIP2=y,# CONFIG_INITRAMFS_COMPRESSION_BZIP2 is not set\n# CONFIG_RD_BZIP2 is not set)" >> $(LINUX_DIR)/.config
  77. echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA),CONFIG_INITRAMFS_COMPRESSION_LZMA=y\nCONFIG_RD_LZMA=y,# CONFIG_INITRAMFS_COMPRESSION_LZMA is not set\n# CONFIG_RD_LZMA is not set)" >> $(LINUX_DIR)/.config
  78. echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZO),CONFIG_INITRAMFS_COMPRESSION_LZO=y\nCONFIG_RD_LZO=y,# CONFIG_INITRAMFS_COMPRESSION_LZO is not set\n# CONFIG_RD_LZO is not set)" >> $(LINUX_DIR)/.config
  79. echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ),CONFIG_INITRAMFS_COMPRESSION_XZ=y\nCONFIG_RD_XZ=y,# CONFIG_INITRAMFS_COMPRESSION_XZ is not set\n# CONFIG_RD_XZ is not set)" >> $(LINUX_DIR)/.config
  80. echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZ4),CONFIG_INITRAMFS_COMPRESSION_LZ4=y\nCONFIG_RD_LZ4=y,# CONFIG_INITRAMFS_COMPRESSION_LZ4 is not set\n# CONFIG_RD_LZ4 is not set)" >> $(LINUX_DIR)/.config
  81. endef
  82. else
  83. endif
  84. define Kernel/SetNoInitramfs
  85. mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
  86. grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
  87. echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config
  88. endef
  89. define Kernel/Configure/Default
  90. $(LINUX_CONF_CMD) > $(LINUX_DIR)/.config.target
  91. # copy CONFIG_KERNEL_* settings over to .config.target
  92. awk '/^(#[[:space:]]+)?CONFIG_KERNEL/{sub("CONFIG_KERNEL_","CONFIG_");print}' $(TOPDIR)/.config >> $(LINUX_DIR)/.config.target
  93. echo "# CONFIG_KALLSYMS_EXTRA_PASS is not set" >> $(LINUX_DIR)/.config.target
  94. echo "# CONFIG_KALLSYMS_ALL is not set" >> $(LINUX_DIR)/.config.target
  95. echo "# CONFIG_KALLSYMS_UNCOMPRESSED is not set" >> $(LINUX_DIR)/.config.target
  96. $(SCRIPT_DIR)/metadata.pl kconfig $(TMP_DIR)/.packageinfo $(TOPDIR)/.config $(KERNEL_PATCHVER) > $(LINUX_DIR)/.config.override
  97. $(SCRIPT_DIR)/kconfig.pl 'm+' '+' $(LINUX_DIR)/.config.target /dev/null $(LINUX_DIR)/.config.override > $(LINUX_DIR)/.config
  98. $(call Kernel/SetNoInitramfs)
  99. rm -rf $(KERNEL_BUILD_DIR)/modules
  100. $(_SINGLE) [ -d $(LINUX_DIR)/user_headers ] || $(MAKE) $(KERNEL_MAKEOPTS) INSTALL_HDR_PATH=$(LINUX_DIR)/user_headers headers_install
  101. $(SH_FUNC) grep '=[ym]' $(LINUX_DIR)/.config | LC_ALL=C sort | md5s > $(LINUX_DIR)/.vermagic
  102. endef
  103. define Kernel/Configure/Initramfs
  104. $(call Kernel/SetInitramfs)
  105. endef
  106. define Kernel/CompileModules/Default
  107. rm -f $(LINUX_DIR)/vmlinux $(LINUX_DIR)/System.map
  108. +$(MAKE) $(KERNEL_MAKEOPTS) modules
  109. endef
  110. OBJCOPY_STRIP = -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id
  111. # AMD64 shares the location with x86
  112. ifeq ($(LINUX_KARCH),x86_64)
  113. IMAGES_DIR:=../../x86/boot
  114. endif
  115. define Kernel/CopyImage
  116. $(KERNEL_CROSS)objcopy -O binary $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL)$(1)
  117. $(KERNEL_CROSS)objcopy $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).elf
  118. $(CP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux.debug
  119. $(foreach k, \
  120. $(if $(KERNEL_IMAGES),$(KERNEL_IMAGES),$(filter-out dtbs,$(KERNELNAME))), \
  121. $(CP) $(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/$(IMAGES_DIR)/$(k) $(KERNEL_BUILD_DIR)/$(k)$(1); \
  122. )
  123. endef
  124. define Kernel/CompileImage/Default
  125. rm -f $(TARGET_DIR)/init
  126. +$(MAKE) $(KERNEL_MAKEOPTS) $(if $(KERNELNAME),$(KERNELNAME),all) modules
  127. $(call Kernel/CopyImage)
  128. endef
  129. ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
  130. define Kernel/CompileImage/Initramfs
  131. $(call Kernel/Configure/Initramfs)
  132. $(CP) $(GENERIC_PLATFORM_DIR)/base-files/init $(TARGET_DIR)/init
  133. rm -rf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/usr/initramfs_data.cpio*
  134. +$(MAKE) $(KERNEL_MAKEOPTS) $(if $(KERNELNAME),$(KERNELNAME),all) modules
  135. $(call Kernel/CopyImage,-initramfs)
  136. endef
  137. else
  138. define Kernel/CompileImage/Initramfs
  139. endef
  140. endif
  141. define Kernel/Clean/Default
  142. rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.configured
  143. rm -f $(LINUX_KERNEL)
  144. $(_SINGLE)$(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean
  145. endef