Makefile 5.5 KB

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