Makefile 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. KDIR_ARCHES = $(LINUX_KARCH)
  43. # arch/arm64/ includes reference files in arch/arm/, so we'll need both
  44. ifeq ($(LINUX_KARCH),arm64)
  45. KDIR_ARCHES += arm
  46. endif
  47. KERNEL_FILES_ARCH = \
  48. Makefile* \
  49. module.lds \
  50. Kbuild.platforms \
  51. */Platform \
  52. include \
  53. */include \
  54. scripts \
  55. kernel/asm-offsets.s
  56. KERNEL_FILES_BASE := \
  57. .config \
  58. Makefile \
  59. scripts \
  60. include \
  61. Module.symvers \
  62. modules.builtin \
  63. $(foreach arch,$(KDIR_ARCHES),$(addprefix arch/$(arch)/,$(KERNEL_FILES_ARCH)))
  64. KERNEL_FILES := $(patsubst $(TOPDIR)/%,%,$(wildcard $(addprefix $(LINUX_DIR)/,$(KERNEL_FILES_BASE))))
  65. all: compile
  66. $(BIN_DIR)/$(SDK_NAME).tar.xz: clean
  67. mkdir -p $(SDK_BUILD_DIR)/dl $(SDK_BUILD_DIR)/package
  68. $(CP) -L $(INCLUDE_DIR) $(SCRIPT_DIR) $(SDK_BUILD_DIR)/
  69. $(TAR) -cf - -C $(TOPDIR) \
  70. `cd $(TOPDIR); find $(KDIR_BASE)/ -name \*.ko` \
  71. `cd $(TOPDIR); find $(KDIR_BASE)/firmware/ -newer $(KDIR_BASE)/firmware/Makefile \
  72. -type f -name '*.bin' -or -name '*.cis' -or -name '*.csp' -or -name '*.dsp' -or -name '*.fw'` \
  73. $(foreach exclude,$(EXCLUDE_DIRS),--exclude="$(exclude)") \
  74. $(SDK_DIRS) $(KERNEL_FILES) | \
  75. $(TAR) -xf - -C $(SDK_BUILD_DIR)
  76. # Copy usbip sources, this is required for the usbip userspace packages to be buildable by the SDK.
  77. $(TAR) -cf - -C $(TOPDIR) $(KDIR_BASE)/tools/usb/usbip/ | \
  78. $(TAR) -xf - -C $(SDK_BUILD_DIR)
  79. (cd $(SDK_BUILD_DIR); find $(STAGING_SUBDIR_HOST)/bin $(STAGING_SUBDIR_HOST)/usr/bin \
  80. $(STAGING_SUBDIR_TOOLCHAIN)/bin $(STAGING_SUBDIR_TOOLCHAIN)/*/bin $(STAGING_SUBDIR_TOOLCHAIN)/libexec \
  81. -type f | $(XARGS) $(SCRIPT_DIR)/bundle-libraries.sh $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST))
  82. @-( \
  83. find \
  84. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/bin \
  85. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/usr/bin \
  86. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/bin \
  87. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/*/bin \
  88. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/libexec \
  89. -type f; \
  90. find \
  91. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/lib \
  92. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/usr/lib \
  93. -type f -name \*.so\*; \
  94. ) | xargs strip 2>/dev/null >/dev/null
  95. mkdir -p $(SDK_BUILD_DIR)/target/linux
  96. $(CP) $(GENERIC_PLATFORM_DIR) $(PLATFORM_DIR) $(SDK_BUILD_DIR)/target/linux/
  97. rm -rf \
  98. $(SDK_BUILD_DIR)/target/linux/*/files* \
  99. $(SDK_BUILD_DIR)/target/linux/*/patches*
  100. ./convert-config.pl $(TOPDIR)/.config > $(SDK_BUILD_DIR)/Config-build.in
  101. $(CP) -L \
  102. $(TOPDIR)/LICENSE \
  103. $(TOPDIR)/rules.mk \
  104. ./files/Config.in \
  105. ./files/Makefile \
  106. ./files/include/prepare.mk \
  107. ./files/README.SDK \
  108. $(SDK_BUILD_DIR)/
  109. $(CP) \
  110. $(TOPDIR)/package/Makefile \
  111. $(TOPDIR)/package/libs/toolchain \
  112. $(TOPDIR)/package/kernel/linux \
  113. $(SDK_BUILD_DIR)/package/
  114. -rm -rf \
  115. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_HOST)/ccache \
  116. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TARGET)/ccache \
  117. $(SDK_BUILD_DIR)/$(STAGING_SUBDIR_TOOLCHAIN)/ccache
  118. -rm -f $(SDK_BUILD_DIR)/feeds.conf.default
  119. $(if $(BASE_FEED),echo "$(BASE_FEED)" > $(SDK_BUILD_DIR)/feeds.conf.default)
  120. if [ -f $(TOPDIR)/feeds.conf ]; then \
  121. cat $(TOPDIR)/feeds.conf >> $(SDK_BUILD_DIR)/feeds.conf.default; \
  122. else \
  123. cat $(TOPDIR)/feeds.conf.default >> $(SDK_BUILD_DIR)/feeds.conf.default; \
  124. fi
  125. $(SED) 's,^# REVISION:=.*,REVISION:=$(REVISION),g' $(SDK_BUILD_DIR)/include/version.mk
  126. $(SED) 's,^# SOURCE_DATE_EPOCH:=.*,SOURCE_DATE_EPOCH:=$(SOURCE_DATE_EPOCH),g' $(SDK_BUILD_DIR)/include/version.mk
  127. $(SED) '/LINUX_VERMAGIC:=/ { s,unknown,$(LINUX_VERMAGIC),g }' $(SDK_BUILD_DIR)/include/kernel.mk
  128. find $(SDK_BUILD_DIR) -name .git | $(XARGS) rm -rf
  129. find $(SDK_BUILD_DIR) -name .svn | $(XARGS) rm -rf
  130. find $(SDK_BUILD_DIR) -name CVS | $(XARGS) rm -rf
  131. -make -C $(SDK_BUILD_DIR)/scripts/config clean
  132. (cd $(BUILD_DIR); \
  133. tar -I 'xz -7e' -cf $@ $(SDK_NAME); \
  134. )
  135. download:
  136. prepare:
  137. compile: $(BIN_DIR)/$(SDK_NAME).tar.xz
  138. install: compile
  139. clean:
  140. rm -rf $(SDK_BUILD_DIR) $(BIN_DIR)/$(SDK_NAME).tar.xz