kernel-build.mk 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # This file is part of the OpenADK project. OpenADK is copyrighted
  2. # material, please see the LICENCE file in the top-level directory.
  3. include $(ADK_TOPDIR)/rules.mk
  4. include $(ADK_TOPDIR)/mk/kernel-ver.mk
  5. include $(ADK_TOPDIR)/mk/linux.mk
  6. include $(ADK_TOPDIR)/mk/kernel-vars.mk
  7. ifeq ($(ADK_TARGET_KERNEL_USE_CUSTOMCONFIG),y)
  8. KERNEL_MODULES_USED:=$(shell grep -s =m $(ADK_TOPDIR)/$(ADK_TARGET_KERNEL_CUSTOMCONFIG_PATH))
  9. else
  10. KERNEL_MODULES_USED:=$(shell grep ^ADK_KERNEL $(ADK_TOPDIR)/.config|grep =m)
  11. endif
  12. KERNEL_FILE:=$(ADK_TARGET_KERNEL)
  13. KERNEL_TARGET:=$(ADK_TARGET_KERNEL)
  14. ifeq ($(ADK_TARGET_KERNEL_LINUXBIN),y)
  15. KERNEL_FILE:=vmlinux
  16. KERNEL_TARGET:=$(ADK_TARGET_KERNEL)
  17. endif
  18. ifeq ($(ADK_TARGET_KERNEL_ZIMAGE),y)
  19. KERNEL_FILE:=vmlinux
  20. KERNEL_TARGET:=$(ADK_TARGET_KERNEL)
  21. endif
  22. ifeq ($(ADK_TARGET_KERNEL_VMLINUX_BOOTP),y)
  23. KERNEL_FILE:=bootpfile
  24. KERNEL_TARGET:=bootpfile
  25. endif
  26. ifeq ($(ADK_TARGET_KERNEL_VMLINUX_GZ),y)
  27. KERNEL_FILE:=vmlinux
  28. KERNEL_TARGET:=all
  29. endif
  30. ifeq ($(ADK_TARGET_KERNEL_BZIMAGE),y)
  31. KERNEL_FILE:=vmlinux
  32. KERNEL_TARGET:=all
  33. endif
  34. ifeq ($(ADK_TARGET_KERNEL_IMAGE),y)
  35. KERNEL_FILE:=vmlinux
  36. KERNEL_TARGET:=$(ADK_TARGET_KERNEL)
  37. endif
  38. ifneq ($(KERNEL_MODULES_USED),)
  39. KERNEL_TARGET+=modules
  40. endif
  41. ifeq ($(ADK_RUNTIME_DEV_UDEV),y)
  42. ADK_DEPMOD:=$(STAGING_HOST_DIR)/usr/bin/depmod
  43. else
  44. ADK_DEPMOD:=true
  45. endif
  46. $(LINUX_DIR)/.prepared: $(TOOLCHAIN_BUILD_DIR)/w-$(PKG_NAME)-$(PKG_VERSION)-$(PKG_RELEASE)/linux-$(KERNEL_FILE_VER)/.patched
  47. ln -sf $(TOOLCHAIN_BUILD_DIR)/w-$(PKG_NAME)-$(PKG_VERSION)-$(PKG_RELEASE)/linux-$(KERNEL_FILE_VER) $(LINUX_DIR)
  48. mkdir -p $(LINUX_BUILD_DIR)/kmod-control
  49. touch $@
  50. ifeq ($(ADK_TARGET_KERNEL_USE_MINICONFIG),y)
  51. $(LINUX_DIR)/.config: $(BUILD_DIR)/.kernelconfig
  52. endif
  53. ifeq ($(ADK_TARGET_KERNEL_USE_CUSTOMCONFIG),y)
  54. $(ADK_TOPDIR)/$(ADK_TARGET_KERNEL_CUSTOMCONFIG_PATH):
  55. $(LINUX_DIR)/.config: $(ADK_TOPDIR)/$(ADK_TARGET_KERNEL_CUSTOMCONFIG_PATH)
  56. endif
  57. $(LINUX_DIR)/.config: $(LINUX_DIR)/.prepared
  58. $(START_TRACE) "target/$(ADK_TARGET_ARCH)-kernel-configure.. "
  59. echo "-${KERNEL_RELEASE}" >${LINUX_DIR}/localversion
  60. ifeq ($(ADK_TARGET_KERNEL_USE_DEFCONFIG),y)
  61. ${KERNEL_MAKE_ENV} $(MAKE) -C "${LINUX_DIR}" ${KERNEL_MAKE_OPTS} $(ADK_TARGET_KERNEL_DEFCONFIG) $(MAKE_TRACE)
  62. else ifeq ($(ADK_TARGET_KERNEL_USE_CUSTOMCONFIG),y)
  63. @if [ ! -f $(ADK_TOPDIR)/$(ADK_TARGET_KERNEL_CUSTOMCONFIG_PATH) ];then \
  64. echo "no kernel configuration found in $(ADK_TOPDIR)/$(ADK_TARGET_KERNEL_CUSTOMCONFIG_PATH)"; \
  65. exit 1; \
  66. fi
  67. ${KERNEL_MAKE_ENV} $(MAKE) -C "${LINUX_DIR}" ${KERNEL_MAKE_OPTS} KCONFIG_ALLCONFIG=$(ADK_TOPDIR)/$(ADK_TARGET_KERNEL_CUSTOMCONFIG_PATH) allnoconfig $(MAKE_TRACE)
  68. else
  69. $(CP) $(BUILD_DIR)/.kernelconfig $(LINUX_DIR)/mini.config
  70. ${KERNEL_MAKE_ENV} $(MAKE) -C "${LINUX_DIR}" ${KERNEL_MAKE_OPTS} KCONFIG_ALLCONFIG=mini.config allnoconfig $(MAKE_TRACE)
  71. endif
  72. $(CMD_TRACE) " done"
  73. $(END_TRACE)
  74. $(LINUX_DIR)/$(KERNEL_FILE): $(LINUX_DIR)/.config
  75. $(START_TRACE) "target/$(ADK_TARGET_ARCH)-kernel-compile.. "
  76. ${KERNEL_MAKE_ENV} $(MAKE) -C "${LINUX_DIR}" ${KERNEL_MAKE_OPTS} -j${ADK_MAKE_JOBS} $(KERNEL_TARGET) $(MAKE_TRACE)
  77. $(CMD_TRACE) " done"
  78. $(END_TRACE)
  79. prepare:
  80. compile: $(LINUX_DIR)/$(KERNEL_FILE)
  81. install:
  82. ifneq ($(KERNEL_MODULES_USED),)
  83. $(START_TRACE) "target/$(ADK_TARGET_ARCH)-kernel-modules-install.. "
  84. rm -rf $(LINUX_BUILD_DIR)/modules
  85. ${KERNEL_MAKE_ENV} $(MAKE) -C "${LINUX_DIR}" ${KERNEL_MAKE_OPTS} \
  86. DEPMOD=$(ADK_DEPMOD) \
  87. INSTALL_MOD_PATH=$(LINUX_BUILD_DIR)/modules \
  88. modules_install $(MAKE_TRACE)
  89. $(CMD_TRACE) " done"
  90. $(END_TRACE)
  91. ifeq ($(ADK_RUNTIME_DEV_UDEV),)
  92. $(START_TRACE) "target/$(ADK_TARGET_ARCH)-kernel-modules-create-packages.. "
  93. rm -f ${PACKAGE_DIR}/kmod-*
  94. PATH='${HOST_PATH}' ${BASH} ${SCRIPT_DIR}/make-module-ipkgs.sh \
  95. "${ADK_TARGET_CPU_ARCH}" \
  96. "${KERNEL_VERSION}" \
  97. "${LINUX_BUILD_DIR}" \
  98. "${PKG_BUILD}" \
  99. "${PACKAGE_DIR}"
  100. $(CMD_TRACE) " done"
  101. $(END_TRACE)
  102. endif
  103. $(START_TRACE) "target/${ADK_TARGET_ARCH}-kernel-modules-install-packages.. "
  104. for pkg in $(PACKAGE_DIR)/kmod-*; do \
  105. [[ -e "$$pkg" ]] && $(PKG_INSTALL) $$pkg; \
  106. done
  107. $(CMD_TRACE) " done"
  108. $(END_TRACE)
  109. endif
  110. clean:
  111. rm -rf $(LINUX_BUILD_DIR)
  112. rm -f $(wildcard ${PACKAGE_DIR}/kmod-*) $(wildcard ${PACKAGE_DIR}/kernel_*)