Makefile 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #
  2. # Copyright (C) 2006-2014 OpenWrt.org
  3. # Copyright (C) 2016 LEDE Project
  4. #
  5. # This is free software, licensed under the GNU General Public License v2.
  6. # See /LICENSE for more information.
  7. #
  8. include $(TOPDIR)/rules.mk
  9. include $(INCLUDE_DIR)/kernel.mk
  10. include $(INCLUDE_DIR)/host.mk
  11. include $(INCLUDE_DIR)/version.mk
  12. override MAKEFLAGS=
  13. SDK_NAME:=$(VERSION_DIST_SANITIZED)-sdk-$(if $(CONFIG_VERSION_FILENAMES),$(VERSION_NUMBER)-)$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))$(if $(GCCV),_gcc-$(GCCV))$(DIR_SUFFIX).$(HOST_OS)-$(HOST_ARCH)
  14. SDK_BUILD_DIR:=$(BUILD_DIR)/$(SDK_NAME)
  15. STAGING_SUBDIR_HOST := staging_dir/host
  16. STAGING_SUBDIR_TOOLCHAIN := staging_dir/toolchain-$(ARCH)$(ARCH_SUFFIX)_gcc-$(GCCV)_$(LIBC)-$(LIBCV)$(if $(CONFIG_arm),_eabi)
  17. EXCLUDE_DIRS:=*/ccache/* \
  18. */stamp \
  19. */stampfiles \
  20. */man \
  21. */info \
  22. */root-* \
  23. initial \
  24. *.install.clean \
  25. *.install.flags \
  26. *.install \
  27. */doc
  28. SDK_DIRS = \
  29. $(STAGING_SUBDIR_HOST) \
  30. $(STAGING_SUBDIR_TOOLCHAIN)
  31. BASE_FEED:=$(shell git config --get remote.origin.url 2>/dev/null | sed -ne 's/^/src-git base /p')
  32. BASE_FEED:=$(if $(BASE_FEED),$(BASE_FEED),$(shell cd $(TOPDIR); LC_ALL=C git svn info 2>/dev/null | sed -ne 's/^URL: /src-gitsvn base /p'))
  33. BASE_FEED:=$(if $(BASE_FEED),$(BASE_FEED),$(shell cd $(TOPDIR); LC_ALL=C svn info 2>/dev/null | sed -ne 's/^URL: /src-svn base /p'))
  34. BASE_FEED:=$(if $(BASE_FEED),$(BASE_FEED),src-git base https://git.lede-project.org/source.git$(filter-out ;master,;$(shell git rev-parse --abbrev-ref HEAD)))
  35. KDIR_BASE = $(patsubst $(TOPDIR)/%,%,$(LINUX_DIR))
  36. KERNEL_FILES_ARCH = \
  37. Makefile* \
  38. module.lds \
  39. Kbuild.platforms \
  40. */Platform \
  41. include \
  42. */include \
  43. scripts \
  44. kernel/asm-offsets.s
  45. KERNEL_FILES_BASE := \
  46. .config \
  47. Makefile \
  48. scripts \
  49. include \
  50. Module.symvers \
  51. modules.builtin \
  52. $(addprefix arch/$(LINUX_KARCH)/,$(KERNEL_FILES_ARCH))
  53. KERNEL_FILES := $(patsubst $(TOPDIR)/%,%,$(wildcard $(addprefix $(LINUX_DIR)/,$(KERNEL_FILES_BASE))))
  54. all: compile
  55. $(BIN_DIR)/$(SDK_NAME).tar.xz: clean
  56. mkdir -p $(SDK_BUILD_DIR)/dl $(SDK_BUILD_DIR)/package
  57. $(CP) -L $(INCLUDE_DIR) $(SCRIPT_DIR) $(SDK_BUILD_DIR)/
  58. $(TAR) -cf - -C $(TOPDIR) \
  59. `cd $(TOPDIR); find $(KDIR_BASE) -name \*.ko` \
  60. `cd $(TOPDIR); find $(KDIR_BASE)/firmware/ -newer $(KDIR_BASE)/firmware/Makefile \
  61. -type f -name '*.bin' -or -name '*.cis' -or -name '*.csp' -or -name '*.dsp' -or -name '*.fw'` \
  62. $(foreach exclude,$(EXCLUDE_DIRS),--exclude="$(exclude)") \
  63. $(SDK_DIRS) $(KERNEL_FILES) | \
  64. $(TAR) -xf - -C $(SDK_BUILD_DIR)
  65. (cd $(SDK_BUILD_DIR); find $(STAGING_SUBDIR_HOST)/bin $(STAGING_SUBDIR_HOST)/usr/bin \
  66. $(STAGING_SUBDIR_TOOLCHAIN)/bin $(STAGING_SUBDIR_TOOLCHAIN)/*/bin $(STAGING_SUBDIR_TOOLCHAIN)/libexec \
  67. -type f | $(XARGS) $(SCRIPT_DIR)/bundle-libraries.sh $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST))
  68. @-( \
  69. find \
  70. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/bin \
  71. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/usr/bin \
  72. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/bin \
  73. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/*/bin \
  74. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/libexec \
  75. -type f; \
  76. find \
  77. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/lib \
  78. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/usr/lib \
  79. -type f -name \*.so\* -or -name \*.a; \
  80. ) | xargs strip 2>/dev/null >/dev/null
  81. mkdir -p $(SDK_BUILD_DIR)/target/linux
  82. $(CP) $(GENERIC_PLATFORM_DIR) $(PLATFORM_DIR) $(SDK_BUILD_DIR)/target/linux/
  83. rm -rf \
  84. $(SDK_BUILD_DIR)/target/linux/*/files* \
  85. $(SDK_BUILD_DIR)/target/linux/*/patches*
  86. ./convert-config.pl $(TOPDIR)/.config > $(SDK_BUILD_DIR)/Config-build.in
  87. $(CP) -L \
  88. $(TOPDIR)/LICENSE \
  89. $(TOPDIR)/rules.mk \
  90. ./files/Config.in \
  91. ./files/Makefile \
  92. ./files/include/prepare.mk \
  93. ./files/README.SDK \
  94. $(SDK_BUILD_DIR)/
  95. $(CP) \
  96. $(TOPDIR)/package/Makefile \
  97. $(TOPDIR)/package/libs/toolchain \
  98. $(TOPDIR)/package/kernel/linux \
  99. $(SDK_BUILD_DIR)/package/
  100. -rm -f $(SDK_BUILD_DIR)/feeds.conf.default
  101. $(if $(BASE_FEED),echo "$(BASE_FEED)" > $(SDK_BUILD_DIR)/feeds.conf.default)
  102. if [ -f $(TOPDIR)/feeds.conf ]; then \
  103. cat $(TOPDIR)/feeds.conf >> $(SDK_BUILD_DIR)/feeds.conf.default; \
  104. else \
  105. cat $(TOPDIR)/feeds.conf.default >> $(SDK_BUILD_DIR)/feeds.conf.default; \
  106. fi
  107. $(SED) 's,^# REVISION:=.*,REVISION:=$(REVISION),g' $(SDK_BUILD_DIR)/include/version.mk
  108. $(SED) 's,^# SOURCE_DATE_EPOCH:=.*,SOURCE_DATE_EPOCH:=$(SOURCE_DATE_EPOCH),g' $(SDK_BUILD_DIR)/include/version.mk
  109. $(SED) '/LINUX_VERMAGIC:=/ { s,unknown,$(LINUX_VERMAGIC),g }' $(SDK_BUILD_DIR)/include/kernel.mk
  110. find $(SDK_BUILD_DIR) -name .git | $(XARGS) rm -rf
  111. find $(SDK_BUILD_DIR) -name .svn | $(XARGS) rm -rf
  112. find $(SDK_BUILD_DIR) -name CVS | $(XARGS) rm -rf
  113. (cd $(BUILD_DIR); \
  114. tar -I 'xz -7e' -cf $@ $(SDK_NAME); \
  115. )
  116. download:
  117. prepare:
  118. compile: $(BIN_DIR)/$(SDK_NAME).tar.xz
  119. install: compile
  120. clean:
  121. rm -rf $(SDK_BUILD_DIR) $(BIN_DIR)/$(SDK_NAME).tar.xz