1
0

Makefile 6.0 KB

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