kernel-build.mk 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_BZIMAGE),y)
  23. KERNEL_FILE:=vmlinux
  24. KERNEL_TARGET:=all
  25. endif
  26. ifeq ($(ADK_TARGET_KERNEL_IMAGE),y)
  27. KERNEL_FILE:=vmlinux
  28. KERNEL_TARGET:=$(ADK_TARGET_KERNEL)
  29. endif
  30. ifeq ($(ADK_RUNTIME_DEV_UDEV),y)
  31. ADK_DEPMOD:=$(STAGING_HOST_DIR)/usr/bin/depmod
  32. else
  33. ADK_DEPMOD:=true
  34. endif
  35. $(LINUX_DIR)/.prepared: $(TOOLCHAIN_BUILD_DIR)/w-$(PKG_NAME)-$(PKG_VERSION)-$(PKG_RELEASE)/linux-$(KERNEL_FILE_VER)/.patched
  36. ln -sf $(TOOLCHAIN_BUILD_DIR)/w-$(PKG_NAME)-$(PKG_VERSION)-$(PKG_RELEASE)/linux-$(KERNEL_FILE_VER) $(LINUX_DIR)
  37. mkdir -p $(LINUX_BUILD_DIR)/kmod-control
  38. touch $@
  39. ifeq ($(ADK_TARGET_KERNEL_USE_MINICONFIG),y)
  40. $(LINUX_DIR)/.config: $(BUILD_DIR)/.kernelconfig
  41. endif
  42. ifeq ($(ADK_TARGET_KERNEL_USE_CUSTOMCONFIG),y)
  43. $(ADK_TOPDIR)/$(ADK_TARGET_KERNEL_CUSTOMCONFIG_PATH):
  44. $(LINUX_DIR)/.config: $(ADK_TOPDIR)/$(ADK_TARGET_KERNEL_CUSTOMCONFIG_PATH)
  45. endif
  46. $(LINUX_DIR)/.config: $(LINUX_DIR)/.prepared
  47. $(START_TRACE) "target/$(ADK_TARGET_ARCH)-kernel-configure.. "
  48. -for f in $(TARGETS);do if [ -f $$f ];then rm $$f;fi;done
  49. echo "-${KERNEL_RELEASE}" >${LINUX_DIR}/localversion
  50. ifeq ($(ADK_TARGET_KERNEL_USE_DEFCONFIG),y)
  51. ${KERNEL_MAKE_ENV} $(MAKE) -C "${LINUX_DIR}" ${KERNEL_MAKE_OPTS} $(ADK_TARGET_KERNEL_DEFCONFIG) $(MAKE_TRACE)
  52. else ifeq ($(ADK_TARGET_KERNEL_USE_CUSTOMCONFIG),y)
  53. @if [ ! -f $(ADK_TOPDIR)/$(ADK_TARGET_KERNEL_CUSTOMCONFIG_PATH) ];then \
  54. echo "no kernel configuration found in $(ADK_TOPDIR)/$(ADK_TARGET_KERNEL_CUSTOMCONFIG_PATH)"; \
  55. exit 1; \
  56. fi
  57. ${KERNEL_MAKE_ENV} $(MAKE) -C "${LINUX_DIR}" ${KERNEL_MAKE_OPTS} KCONFIG_ALLCONFIG=$(ADK_TOPDIR)/$(ADK_TARGET_KERNEL_CUSTOMCONFIG_PATH) allnoconfig $(MAKE_TRACE)
  58. else
  59. $(CP) $(BUILD_DIR)/.kernelconfig $(LINUX_DIR)/mini.config
  60. ${KERNEL_MAKE_ENV} $(MAKE) -C "${LINUX_DIR}" ${KERNEL_MAKE_OPTS} KCONFIG_ALLCONFIG=mini.config allnoconfig $(MAKE_TRACE)
  61. endif
  62. touch -c $(LINUX_DIR)/.config
  63. $(CMD_TRACE) " done"
  64. $(END_TRACE)
  65. $(LINUX_DIR)/$(KERNEL_FILE): $(LINUX_DIR)/.config
  66. $(START_TRACE) "target/$(ADK_TARGET_ARCH)-kernel-compile.. "
  67. ${KERNEL_MAKE_ENV} $(MAKE) -C "${LINUX_DIR}" ${KERNEL_MAKE_OPTS} -j${ADK_MAKE_JOBS} $(KERNEL_TARGET) $(MAKE_TRACE)
  68. touch -c $(LINUX_DIR)/$(KERNEL_FILE)
  69. $(CMD_TRACE) " done"
  70. $(END_TRACE)
  71. $(LINUX_BUILD_DIR)/modules: $(LINUX_DIR)/$(KERNEL_FILE)
  72. $(START_TRACE) "target/$(ADK_TARGET_ARCH)-kernel-modules-compile.. "
  73. ${KERNEL_MAKE_ENV} $(MAKE) -C "${LINUX_DIR}" ${KERNEL_MAKE_OPTS} -j${ADK_MAKE_JOBS} modules $(MAKE_TRACE)
  74. $(CMD_TRACE) " done"
  75. $(END_TRACE)
  76. $(START_TRACE) "target/$(ADK_TARGET_ARCH)-kernel-modules-install.. "
  77. rm -rf $(LINUX_BUILD_DIR)/modules
  78. ${KERNEL_MAKE_ENV} $(MAKE) -C "${LINUX_DIR}" ${KERNEL_MAKE_OPTS} \
  79. DEPMOD=$(ADK_DEPMOD) \
  80. INSTALL_MOD_PATH=$(LINUX_BUILD_DIR)/modules \
  81. modules_install $(MAKE_TRACE)
  82. $(CMD_TRACE) " done"
  83. $(END_TRACE)
  84. ifneq ($(ADK_RUNTIME_DEV_UDEV),y)
  85. $(START_TRACE) "target/$(ADK_TARGET_ARCH)-create-packages.. "
  86. @mkdir -p ${PACKAGE_DIR}
  87. PATH='${HOST_PATH}' ${BASH} ${SCRIPT_DIR}/make-module-ipkgs.sh \
  88. "${ADK_TARGET_CPU_ARCH}" \
  89. "${KERNEL_VERSION}" \
  90. "${LINUX_BUILD_DIR}" \
  91. "${PKG_BUILD}" \
  92. "${PACKAGE_DIR}"
  93. $(CMD_TRACE) " done"
  94. $(END_TRACE)
  95. endif
  96. prepare:
  97. ifneq ($(KERNEL_MODULES_USED),)
  98. compile: $(LINUX_BUILD_DIR)/modules
  99. else
  100. compile: $(LINUX_DIR)/$(KERNEL_FILE)
  101. endif
  102. install: compile
  103. ifneq ($(KERNEL_MODULES_USED),)
  104. $(START_TRACE) "target/${ADK_TARGET_ARCH}-modules-install.. "
  105. ifeq ($(ADK_TARGET_PACKAGE_IPKG)$(ADK_TARGET_PACKAGE_OPKG),y)
  106. $(PKG_INSTALL) $(wildcard ${PACKAGE_DIR}/kmod-*) $(MAKE_TRACE)
  107. else
  108. $(foreach pkg,$(wildcard ${PACKAGE_DIR}/kmod-*),$(shell $(PKG_INSTALL) $(pkg)))
  109. endif
  110. $(CMD_TRACE) " done"
  111. $(END_TRACE)
  112. endif
  113. clean:
  114. rm -rf $(LINUX_BUILD_DIR)
  115. rm -f $(wildcard ${PACKAGE_DIR}/kmod-*) $(wildcard ${PACKAGE_DIR}/kernel_*)