1
0

Makefile 5.8 KB

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