kernel-defaults.mk 6.8 KB

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