kernel-build.mk 4.2 KB

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