1
0

Makefile 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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_TARGET := staging_dir/$(TARGET_DIR_NAME)
  17. STAGING_SUBDIR_TOOLCHAIN := staging_dir/toolchain-$(ARCH)$(ARCH_SUFFIX)_gcc-$(GCCV)_$(LIBC)-$(LIBCV)$(if $(CONFIG_arm),_eabi)
  18. EXCLUDE_DIRS:=*/ccache/* \
  19. */stamp \
  20. */stampfiles \
  21. */man \
  22. */info \
  23. */root-* \
  24. initial \
  25. *.install.clean \
  26. *.install.flags \
  27. *.install \
  28. */doc \
  29. */share/locale
  30. SDK_DIRS = \
  31. $(STAGING_SUBDIR_HOST) \
  32. $(STAGING_SUBDIR_TOOLCHAIN)
  33. GIT_URL:=$(filter git://% http://% https://%,$(shell git config --get remote.origin.url 2>/dev/null))
  34. GIT_COMMIT:=$(shell git rev-parse HEAD 2>/dev/null)
  35. GIT_BRANCH:=$(filter-out master HEAD,$(shell git rev-parse --abbrev-ref HEAD 2>/dev/null))
  36. GIT_TAGNAME:=$(shell git show-ref --tags --dereference 2>/dev/null | sed -ne '/^$(GIT_COMMIT) / { s|^.*/||; s|\^.*||; p }')
  37. BASE_FEED:=$(if $(GIT_URL),src-git base $(GIT_URL)$(if $(GIT_BRANCH),;$(GIT_BRANCH),$(if $(GIT_TAGNAME),;$(GIT_TAGNAME))))
  38. 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'))
  39. 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'))
  40. BASE_FEED:=$(if $(BASE_FEED),$(BASE_FEED),src-git base https://git.lede-project.org/source.git$(if $(GIT_BRANCH),;$(GIT_BRANCH),$(if $(GIT_TAGNAME),;$(GIT_TAGNAME))))
  41. KDIR_BASE = $(patsubst $(TOPDIR)/%,%,$(LINUX_DIR))
  42. KERNEL_FILES_ARCH = \
  43. Makefile* \
  44. module.lds \
  45. Kbuild.platforms \
  46. */Platform \
  47. include \
  48. */include \
  49. scripts \
  50. kernel/asm-offsets.s
  51. KERNEL_FILES_BASE := \
  52. .config \
  53. Makefile \
  54. scripts \
  55. include \
  56. Module.symvers \
  57. modules.builtin \
  58. $(addprefix arch/$(LINUX_KARCH)/,$(KERNEL_FILES_ARCH))
  59. KERNEL_FILES := $(patsubst $(TOPDIR)/%,%,$(wildcard $(addprefix $(LINUX_DIR)/,$(KERNEL_FILES_BASE))))
  60. all: compile
  61. $(BIN_DIR)/$(SDK_NAME).tar.xz: clean
  62. mkdir -p $(SDK_BUILD_DIR)/dl $(SDK_BUILD_DIR)/package
  63. $(CP) -L $(INCLUDE_DIR) $(SCRIPT_DIR) $(SDK_BUILD_DIR)/
  64. $(TAR) -cf - -C $(TOPDIR) \
  65. `cd $(TOPDIR); find $(KDIR_BASE) -name \*.ko` \
  66. `cd $(TOPDIR); find $(KDIR_BASE)/firmware/ -newer $(KDIR_BASE)/firmware/Makefile \
  67. -type f -name '*.bin' -or -name '*.cis' -or -name '*.csp' -or -name '*.dsp' -or -name '*.fw'` \
  68. $(foreach exclude,$(EXCLUDE_DIRS),--exclude="$(exclude)") \
  69. $(SDK_DIRS) $(KERNEL_FILES) | \
  70. $(TAR) -xf - -C $(SDK_BUILD_DIR)
  71. (cd $(SDK_BUILD_DIR); find $(STAGING_SUBDIR_HOST)/bin $(STAGING_SUBDIR_HOST)/usr/bin \
  72. $(STAGING_SUBDIR_TOOLCHAIN)/bin $(STAGING_SUBDIR_TOOLCHAIN)/*/bin $(STAGING_SUBDIR_TOOLCHAIN)/libexec \
  73. -type f | $(XARGS) $(SCRIPT_DIR)/bundle-libraries.sh $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST))
  74. @-( \
  75. find \
  76. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/bin \
  77. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/usr/bin \
  78. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/bin \
  79. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/*/bin \
  80. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/libexec \
  81. -type f; \
  82. find \
  83. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/lib \
  84. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/usr/lib \
  85. -type f -name \*.so\*; \
  86. ) | xargs strip 2>/dev/null >/dev/null
  87. mkdir -p $(SDK_BUILD_DIR)/target/linux
  88. $(CP) $(GENERIC_PLATFORM_DIR) $(PLATFORM_DIR) $(SDK_BUILD_DIR)/target/linux/
  89. rm -rf \
  90. $(SDK_BUILD_DIR)/target/linux/*/files* \
  91. $(SDK_BUILD_DIR)/target/linux/*/patches*
  92. ./convert-config.pl $(TOPDIR)/.config > $(SDK_BUILD_DIR)/Config-build.in
  93. $(CP) -L \
  94. $(TOPDIR)/LICENSE \
  95. $(TOPDIR)/rules.mk \
  96. ./files/Config.in \
  97. ./files/Makefile \
  98. ./files/include/prepare.mk \
  99. ./files/README.SDK \
  100. $(SDK_BUILD_DIR)/
  101. $(CP) \
  102. $(TOPDIR)/package/Makefile \
  103. $(TOPDIR)/package/libs/toolchain \
  104. $(TOPDIR)/package/kernel/linux \
  105. $(SDK_BUILD_DIR)/package/
  106. -rm -rf \
  107. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/ccache \
  108. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TARGET)/ccache \
  109. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/ccache
  110. -rm -f $(SDK_BUILD_DIR)/feeds.conf.default
  111. $(if $(BASE_FEED),echo "$(BASE_FEED)" > $(SDK_BUILD_DIR)/feeds.conf.default)
  112. if [ -f $(TOPDIR)/feeds.conf ]; then \
  113. cat $(TOPDIR)/feeds.conf >> $(SDK_BUILD_DIR)/feeds.conf.default; \
  114. else \
  115. cat $(TOPDIR)/feeds.conf.default >> $(SDK_BUILD_DIR)/feeds.conf.default; \
  116. fi
  117. $(SED) 's,^# REVISION:=.*,REVISION:=$(REVISION),g' $(SDK_BUILD_DIR)/include/version.mk
  118. $(SED) 's,^# SOURCE_DATE_EPOCH:=.*,SOURCE_DATE_EPOCH:=$(SOURCE_DATE_EPOCH),g' $(SDK_BUILD_DIR)/include/version.mk
  119. $(SED) '/LINUX_VERMAGIC:=/ { s,unknown,$(LINUX_VERMAGIC),g }' $(SDK_BUILD_DIR)/include/kernel.mk
  120. find $(SDK_BUILD_DIR) -name .git | $(XARGS) rm -rf
  121. find $(SDK_BUILD_DIR) -name .svn | $(XARGS) rm -rf
  122. find $(SDK_BUILD_DIR) -name CVS | $(XARGS) rm -rf
  123. -make -C $(SDK_BUILD_DIR)/scripts/config clean
  124. (cd $(BUILD_DIR); \
  125. tar -I 'xz -7e' -cf $@ $(SDK_NAME); \
  126. )
  127. download:
  128. prepare:
  129. compile: $(BIN_DIR)/$(SDK_NAME).tar.xz
  130. install: compile
  131. clean:
  132. rm -rf $(SDK_BUILD_DIR) $(BIN_DIR)/$(SDK_NAME).tar.xz