kernel-defaults.mk 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. KBUILD_BUILD_USER="$(call qstrip,$(CONFIG_KERNEL_BUILD_USER))" \
  13. KBUILD_BUILD_HOST="$(call qstrip,$(CONFIG_KERNEL_BUILD_DOMAIN))" \
  14. CONFIG_SHELL="$(BASH)" \
  15. $(if $(findstring c,$(OPENWRT_VERBOSE)),V=1,V='') \
  16. $(if $(PKG_BUILD_ID),LDFLAGS_MODULE=--build-id=0x$(PKG_BUILD_ID))
  17. ifdef CONFIG_STRIP_KERNEL_EXPORTS
  18. KERNEL_MAKEOPTS += \
  19. EXTRA_LDSFLAGS="-I$(KERNEL_BUILD_DIR) -include symtab.h"
  20. endif
  21. INITRAMFS_EXTRA_FILES ?= $(GENERIC_PLATFORM_DIR)/image/initramfs-base-files.txt
  22. ifneq (,$(KERNEL_CC))
  23. KERNEL_MAKEOPTS += CC="$(KERNEL_CC)"
  24. endif
  25. ifdef CONFIG_USE_SPARSE
  26. KERNEL_MAKEOPTS += C=1 CHECK=$(STAGING_DIR_HOST)/bin/sparse
  27. endif
  28. export HOST_EXTRACFLAGS=-I$(STAGING_DIR_HOST)/include
  29. # defined in quilt.mk
  30. Kernel/Patch:=$(Kernel/Patch/Default)
  31. KERNEL_GIT_OPTS:=
  32. ifneq ($(strip $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)),"")
  33. KERNEL_GIT_OPTS+=--reference $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)
  34. endif
  35. ifneq ($(strip $(CONFIG_KERNEL_GIT_BRANCH)),"")
  36. KERNEL_GIT_OPTS+=--branch $(CONFIG_KERNEL_GIT_BRANCH)
  37. endif
  38. ifeq ($(strip $(CONFIG_EXTERNAL_KERNEL_TREE)),"")
  39. ifeq ($(strip $(CONFIG_KERNEL_GIT_CLONE_URI)),"")
  40. define Kernel/Prepare/Default
  41. xzcat $(DL_DIR)/$(LINUX_SOURCE) | $(TAR) -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
  42. $(Kernel/Patch)
  43. touch $(LINUX_DIR)/.quilt_used
  44. endef
  45. else
  46. define Kernel/Prepare/Default
  47. git clone $(KERNEL_GIT_OPTS) $(CONFIG_KERNEL_GIT_CLONE_URI) $(LINUX_DIR)
  48. endef
  49. endif
  50. else
  51. define Kernel/Prepare/Default
  52. mkdir -p $(KERNEL_BUILD_DIR)
  53. if [ -d $(LINUX_DIR) ]; then \
  54. rmdir $(LINUX_DIR); \
  55. fi
  56. ln -s $(CONFIG_EXTERNAL_KERNEL_TREE) $(LINUX_DIR)
  57. endef
  58. endif
  59. ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
  60. ifeq ($(strip $(CONFIG_EXTERNAL_CPIO)),"")
  61. define Kernel/SetInitramfs/PreConfigure
  62. grep -v -e INITRAMFS -e CONFIG_RD_ -e CONFIG_BLK_DEV_INITRD $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
  63. echo 'CONFIG_BLK_DEV_INITRD=y' >> $(LINUX_DIR)/.config
  64. echo 'CONFIG_INITRAMFS_SOURCE="$(strip $(TARGET_DIR) $(INITRAMFS_EXTRA_FILES))"' >> $(LINUX_DIR)/.config
  65. endef
  66. else
  67. define Kernel/SetInitramfs/PreConfigure
  68. grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
  69. echo 'CONFIG_INITRAMFS_SOURCE="$(call qstrip,$(CONFIG_EXTERNAL_CPIO))"' >> $(LINUX_DIR)/.config
  70. endef
  71. endif
  72. define Kernel/SetInitramfs
  73. rm -f $(LINUX_DIR)/.config.prev
  74. mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
  75. $(call Kernel/SetInitramfs/PreConfigure)
  76. echo 'CONFIG_INITRAMFS_ROOT_UID=$(shell id -u)' >> $(LINUX_DIR)/.config
  77. echo 'CONFIG_INITRAMFS_ROOT_GID=$(shell id -g)' >> $(LINUX_DIR)/.config
  78. echo "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_NONE),CONFIG_INITRAMFS_COMPRESSION_NONE=y,# CONFIG_INITRAMFS_COMPRESSION_NONE is not set)" >> $(LINUX_DIR)/.config
  79. 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
  80. 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
  81. 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
  82. 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
  83. 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
  84. 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
  85. endef
  86. else
  87. endif
  88. define Kernel/SetNoInitramfs
  89. mv $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config.old
  90. grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config.set
  91. echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config.set
  92. endef
  93. define Kernel/Configure/Default
  94. $(LINUX_CONF_CMD) > $(LINUX_DIR)/.config.target
  95. # copy CONFIG_KERNEL_* settings over to .config.target
  96. awk '/^(#[[:space:]]+)?CONFIG_KERNEL/{sub("CONFIG_KERNEL_","CONFIG_");print}' $(TOPDIR)/.config >> $(LINUX_DIR)/.config.target
  97. echo "# CONFIG_KALLSYMS_EXTRA_PASS is not set" >> $(LINUX_DIR)/.config.target
  98. echo "# CONFIG_KALLSYMS_ALL is not set" >> $(LINUX_DIR)/.config.target
  99. echo "CONFIG_KALLSYMS_UNCOMPRESSED=y" >> $(LINUX_DIR)/.config.target
  100. $(SCRIPT_DIR)/metadata.pl kconfig $(TMP_DIR)/.packageinfo $(TOPDIR)/.config $(KERNEL_PATCHVER) > $(LINUX_DIR)/.config.override
  101. $(SCRIPT_DIR)/kconfig.pl 'm+' '+' $(LINUX_DIR)/.config.target /dev/null $(LINUX_DIR)/.config.override > $(LINUX_DIR)/.config.set
  102. $(call Kernel/SetNoInitramfs)
  103. rm -rf $(KERNEL_BUILD_DIR)/modules
  104. cmp -s $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config.prev || { \
  105. cp $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config; \
  106. cp $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config.prev; \
  107. }
  108. $(_SINGLE) [ -d $(LINUX_DIR)/user_headers ] || $(MAKE) $(KERNEL_MAKEOPTS) INSTALL_HDR_PATH=$(LINUX_DIR)/user_headers headers_install
  109. $(SH_FUNC) grep '=[ym]' $(LINUX_DIR)/.config.set | LC_ALL=C sort | md5s > $(LINUX_DIR)/.vermagic
  110. endef
  111. define Kernel/Configure/Initramfs
  112. $(call Kernel/SetInitramfs)
  113. endef
  114. define Kernel/CompileModules/Default
  115. rm -f $(LINUX_DIR)/vmlinux $(LINUX_DIR)/System.map
  116. +$(MAKE) $(KERNEL_MAKEOPTS) modules
  117. endef
  118. OBJCOPY_STRIP = -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id
  119. # AMD64 shares the location with x86
  120. ifeq ($(LINUX_KARCH),x86_64)
  121. IMAGES_DIR:=../../x86/boot
  122. endif
  123. define Kernel/CopyImage
  124. cmp -s $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).debug || { \
  125. $(KERNEL_CROSS)objcopy -O binary $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL)$(1); \
  126. $(KERNEL_CROSS)objcopy $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).elf; \
  127. $(CP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).debug; \
  128. $(foreach k, \
  129. $(if $(KERNEL_IMAGES),$(KERNEL_IMAGES),$(filter-out dtbs,$(KERNELNAME))), \
  130. $(CP) $(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/$(IMAGES_DIR)/$(k) $(KERNEL_BUILD_DIR)/$(k)$(1); \
  131. ) \
  132. }
  133. endef
  134. define Kernel/CompileImage/Default
  135. rm -f $(TARGET_DIR)/init
  136. +$(MAKE) $(KERNEL_MAKEOPTS) $(if $(KERNELNAME),$(KERNELNAME),all) modules
  137. $(call Kernel/CopyImage)
  138. endef
  139. ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
  140. define Kernel/CompileImage/Initramfs
  141. $(call Kernel/Configure/Initramfs)
  142. $(CP) $(GENERIC_PLATFORM_DIR)/base-files/init $(TARGET_DIR)/init
  143. rm -rf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/usr/initramfs_data.cpio*
  144. +$(MAKE) $(KERNEL_MAKEOPTS) $(if $(KERNELNAME),$(KERNELNAME),all) modules
  145. $(call Kernel/CopyImage,-initramfs)
  146. endef
  147. else
  148. define Kernel/CompileImage/Initramfs
  149. endef
  150. endif
  151. define Kernel/Clean/Default
  152. rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.configured
  153. rm -f $(LINUX_KERNEL)
  154. $(_SINGLE)$(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean
  155. endef