kernel-build.mk 3.6 KB

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