kernel-defaults.mk 7.6 KB

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