rules.mk 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. #
  3. # Copyright (C) 2006-2010 OpenWrt.org
  4. # Copyright (C) 2016 LEDE Project
  5. ifneq ($(__rules_inc),1)
  6. __rules_inc=1
  7. ifeq ($(DUMP),)
  8. -include $(TOPDIR)/.config
  9. endif
  10. include $(TOPDIR)/include/debug.mk
  11. include $(TOPDIR)/include/verbose.mk
  12. ifneq ($(filter check,$(MAKECMDGOALS)),)
  13. CHECK:=1
  14. DUMP:=1
  15. endif
  16. export TMP_DIR:=$(TOPDIR)/tmp
  17. export TMPDIR:=$(TMP_DIR)
  18. qstrip=$(strip $(subst ",,$(1)))
  19. #"))
  20. empty:=
  21. space:= $(empty) $(empty)
  22. comma:=,
  23. merge=$(subst $(space),,$(1))
  24. confvar=$(shell echo '$(foreach v,$(1),$(v)=$(subst ','\'',$($(v))))' | $(STAGING_DIR_HOST)/bin/mkhash md5)
  25. strip_last=$(patsubst %.$(lastword $(subst .,$(space),$(1))),%,$(1))
  26. paren_left = (
  27. paren_right = )
  28. chars_lower = a b c d e f g h i j k l m n o p q r s t u v w x y z
  29. chars_upper = A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  30. define sep
  31. endef
  32. define newline
  33. endef
  34. __tr_list = $(join $(join $(1),$(foreach char,$(1),$(comma))),$(2))
  35. __tr_head_stripped = $(subst $(space),,$(foreach cv,$(call __tr_list,$(1),$(2)),$$$(paren_left)subst$(cv)$(comma)))
  36. __tr_head = $(subst $(paren_left)subst,$(paren_left)subst$(space),$(__tr_head_stripped))
  37. __tr_tail = $(subst $(space),,$(foreach cv,$(1),$(paren_right)))
  38. __tr_template = $(__tr_head)$$(1)$(__tr_tail)
  39. $(eval toupper = $(call __tr_template,$(chars_lower),$(chars_upper)))
  40. $(eval tolower = $(call __tr_template,$(chars_upper),$(chars_lower)))
  41. version_abbrev = $(if $(if $(CHECK),,$(DUMP)),$(1),$(shell printf '%.8s' $(1)))
  42. _SINGLE=export MAKEFLAGS=$(space);
  43. CFLAGS:=
  44. ARCH:=$(subst i486,i386,$(subst i586,i386,$(subst i686,i386,$(call qstrip,$(CONFIG_ARCH)))))
  45. ARCH_PACKAGES:=$(call qstrip,$(CONFIG_TARGET_ARCH_PACKAGES))
  46. BOARD:=$(call qstrip,$(CONFIG_TARGET_BOARD))
  47. SUBTARGET:=$(call qstrip,$(CONFIG_TARGET_SUBTARGET))
  48. TARGET_OPTIMIZATION:=$(call qstrip,$(CONFIG_TARGET_OPTIMIZATION))
  49. export EXTRA_OPTIMIZATION:=$(filter-out -fno-plt,$(call qstrip,$(CONFIG_EXTRA_OPTIMIZATION)))
  50. TARGET_SUFFIX=$(call qstrip,$(CONFIG_TARGET_SUFFIX))
  51. BUILD_SUFFIX:=$(call qstrip,$(CONFIG_BUILD_SUFFIX))
  52. SUBDIR:=$(patsubst $(TOPDIR)/%,%,${CURDIR})
  53. BUILD_SUBDIR:=$(patsubst $(TOPDIR)/%,%,${CURDIR})
  54. NPROC:=$(shell sysctl -n hw.ncpu 2>/dev/null || nproc)
  55. export SHELL:=/usr/bin/env bash
  56. IS_PACKAGE_BUILD := $(if $(filter package/%,$(BUILD_SUBDIR)),1)
  57. OPTIMIZE_FOR_CPU=$(subst i386,i486,$(ARCH))
  58. ifneq (,$(findstring $(ARCH) , aarch64 aarch64_be powerpc ))
  59. FPIC:=-DPIC -fPIC
  60. else
  61. FPIC:=-DPIC -fpic
  62. endif
  63. HOST_FPIC:=-DPIC -fPIC
  64. ARCH_SUFFIX:=$(call qstrip,$(CONFIG_CPU_TYPE))
  65. GCC_ARCH:=
  66. ifneq ($(ARCH_SUFFIX),)
  67. ARCH_SUFFIX:=_$(ARCH_SUFFIX)
  68. endif
  69. ifneq ($(filter -march=armv%,$(TARGET_OPTIMIZATION)),)
  70. GCC_ARCH:=$(patsubst -march=%,%,$(filter -march=armv%,$(TARGET_OPTIMIZATION)))
  71. endif
  72. ifdef CONFIG_HAS_SPE_FPU
  73. TARGET_SUFFIX:=$(TARGET_SUFFIX)spe
  74. endif
  75. ifdef CONFIG_MIPS64_ABI
  76. ifneq ($(CONFIG_MIPS64_ABI_O32),y)
  77. ARCH_SUFFIX:=$(ARCH_SUFFIX)_$(call qstrip,$(CONFIG_MIPS64_ABI))
  78. endif
  79. endif
  80. DEFAULT_SUBDIR_TARGETS:=clean download prepare compile update refresh prereq dist distcheck configure check check-depends
  81. define DefaultTargets
  82. $(foreach t,$(DEFAULT_SUBDIR_TARGETS) $(1),
  83. .$(t):
  84. $(t): .$(t)
  85. .PHONY: $(t) .$(t)
  86. )
  87. endef
  88. DL_DIR:=$(if $(call qstrip,$(CONFIG_DOWNLOAD_FOLDER)),$(call qstrip,$(CONFIG_DOWNLOAD_FOLDER)),$(TOPDIR)/dl)
  89. OUTPUT_DIR:=$(if $(call qstrip,$(CONFIG_BINARY_FOLDER)),$(call qstrip,$(CONFIG_BINARY_FOLDER)),$(TOPDIR)/bin)
  90. BIN_DIR:=$(OUTPUT_DIR)/targets/$(BOARD)/$(SUBTARGET)
  91. INCLUDE_DIR:=$(TOPDIR)/include
  92. SCRIPT_DIR:=$(TOPDIR)/scripts
  93. BUILD_DIR_BASE:=$(TOPDIR)/build_dir
  94. ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
  95. GCCV:=$(call qstrip,$(CONFIG_GCC_VERSION))
  96. LIBC:=$(call qstrip,$(CONFIG_LIBC))
  97. REAL_GNU_TARGET_NAME=$(OPTIMIZE_FOR_CPU)-openwrt-linux$(if $(TARGET_SUFFIX),-$(TARGET_SUFFIX))
  98. GNU_TARGET_NAME=$(OPTIMIZE_FOR_CPU)-openwrt-linux
  99. DIR_SUFFIX:=_$(LIBC)$(if $(CONFIG_arm),_eabi)
  100. BIN_DIR:=$(BIN_DIR)$(if $(CONFIG_USE_MUSL),,-$(LIBC))
  101. TARGET_DIR_NAME = target-$(ARCH)$(ARCH_SUFFIX)$(DIR_SUFFIX)$(if $(BUILD_SUFFIX),_$(BUILD_SUFFIX))
  102. TOOLCHAIN_DIR_NAME = toolchain-$(ARCH)$(ARCH_SUFFIX)_gcc-$(GCCV)$(DIR_SUFFIX)
  103. else
  104. ifeq ($(CONFIG_NATIVE_TOOLCHAIN),)
  105. GNU_TARGET_NAME=$(call qstrip,$(CONFIG_TARGET_NAME))
  106. else
  107. GNU_TARGET_NAME=$(shell gcc -dumpmachine)
  108. endif
  109. REAL_GNU_TARGET_NAME=$(GNU_TARGET_NAME)
  110. LIBC:=$(call qstrip,$(CONFIG_LIBC))
  111. TARGET_DIR_NAME:=target-$(GNU_TARGET_NAME)_$(LIBC)$(if $(BUILD_SUFFIX),_$(BUILD_SUFFIX))
  112. TOOLCHAIN_DIR_NAME:=toolchain-$(GNU_TARGET_NAME)
  113. endif
  114. ifeq ($(or $(CONFIG_EXTERNAL_TOOLCHAIN),$(CONFIG_TARGET_uml)),)
  115. ifeq ($(CONFIG_GCC_USE_IREMAP),y)
  116. iremap = -iremap$(1):$(2)
  117. else
  118. iremap = -f$(if $(CONFIG_REPRODUCIBLE_DEBUG_INFO),file,macro)-prefix-map=$(1)=$(2)
  119. endif
  120. endif
  121. PACKAGE_DIR:=$(BIN_DIR)/packages
  122. PACKAGE_DIR_ALL:=$(TOPDIR)/staging_dir/packages/$(BOARD)
  123. BUILD_DIR:=$(BUILD_DIR_BASE)/$(TARGET_DIR_NAME)
  124. STAGING_DIR:=$(TOPDIR)/staging_dir/$(TARGET_DIR_NAME)
  125. BUILD_DIR_TOOLCHAIN:=$(BUILD_DIR_BASE)/$(TOOLCHAIN_DIR_NAME)
  126. TOOLCHAIN_DIR:=$(TOPDIR)/staging_dir/$(TOOLCHAIN_DIR_NAME)
  127. STAMP_DIR:=$(BUILD_DIR)/stamp
  128. STAMP_DIR_HOST=$(BUILD_DIR_HOST)/stamp
  129. TARGET_ROOTFS_DIR?=$(if $(call qstrip,$(CONFIG_TARGET_ROOTFS_DIR)),$(call qstrip,$(CONFIG_TARGET_ROOTFS_DIR)),$(BUILD_DIR))
  130. TARGET_DIR:=$(TARGET_ROOTFS_DIR)/root-$(BOARD)
  131. STAGING_DIR_ROOT:=$(STAGING_DIR)/root-$(BOARD)
  132. STAGING_DIR_IMAGE:=$(STAGING_DIR)/image
  133. BUILD_LOG_DIR:=$(if $(call qstrip,$(CONFIG_BUILD_LOG_DIR)),$(call qstrip,$(CONFIG_BUILD_LOG_DIR)),$(TOPDIR)/logs)
  134. PKG_INFO_DIR := $(STAGING_DIR)/pkginfo
  135. BUILD_DIR_HOST:=$(if $(IS_PACKAGE_BUILD),$(BUILD_DIR_BASE)/hostpkg,$(BUILD_DIR_BASE)/host)
  136. STAGING_DIR_HOST:=$(TOPDIR)/staging_dir/host
  137. STAGING_DIR_HOSTPKG:=$(TOPDIR)/staging_dir/hostpkg
  138. TARGET_PATH:=$(subst $(space),:,$(filter-out .,$(filter-out ./,$(subst :,$(space),$(PATH)))))
  139. TARGET_INIT_PATH:=$(call qstrip,$(CONFIG_TARGET_INIT_PATH))
  140. TARGET_INIT_PATH:=$(if $(TARGET_INIT_PATH),$(TARGET_INIT_PATH),/usr/sbin:/sbin:/usr/bin:/bin)
  141. TARGET_CFLAGS:=$(TARGET_OPTIMIZATION)$(if $(CONFIG_DEBUG), -g3) $(call qstrip,$(CONFIG_EXTRA_OPTIMIZATION))
  142. TARGET_CXXFLAGS = $(TARGET_CFLAGS)
  143. TARGET_ASFLAGS_DEFAULT = $(TARGET_CFLAGS)
  144. TARGET_ASFLAGS = $(TARGET_ASFLAGS_DEFAULT)
  145. ifneq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
  146. LIBGCC_S_PATH=$(realpath $(wildcard $(call qstrip,$(CONFIG_LIBGCC_ROOT_DIR))/$(call qstrip,$(CONFIG_LIBGCC_FILE_SPEC))))
  147. LIBGCC_S=$(if $(LIBGCC_S_PATH),-L$(dir $(LIBGCC_S_PATH)) -lgcc_s)
  148. LIBGCC_A=$(realpath $(lastword $(wildcard $(dir $(LIBGCC_S_PATH))/gcc/*/*/libgcc.a)))
  149. else
  150. LIBGCC_A=$(lastword $(wildcard $(TOOLCHAIN_DIR)/lib/gcc/*/*/libgcc.a))
  151. LIBGCC_S=$(if $(wildcard $(TOOLCHAIN_DIR)/lib/libgcc_s.so),-L$(TOOLCHAIN_DIR)/lib -lgcc_s,$(LIBGCC_A))
  152. endif
  153. ifeq ($(CONFIG_ARCH_64BIT),y)
  154. LIB_SUFFIX:=64
  155. endif
  156. ifndef DUMP
  157. ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
  158. -include $(TOOLCHAIN_DIR)/info.mk
  159. export GCC_HONOUR_COPTS:=0
  160. TARGET_CROSS:=$(if $(TARGET_CROSS),$(TARGET_CROSS),$(OPTIMIZE_FOR_CPU)-openwrt-linux$(if $(TARGET_SUFFIX),-$(TARGET_SUFFIX))-)
  161. TARGET_CFLAGS+= -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result
  162. TARGET_CPPFLAGS+= -I$(TOOLCHAIN_DIR)/usr/include
  163. ifeq ($(CONFIG_USE_MUSL),y)
  164. TARGET_CPPFLAGS+= -I$(TOOLCHAIN_DIR)/include/fortify
  165. endif
  166. TARGET_CPPFLAGS+= -I$(TOOLCHAIN_DIR)/include
  167. TARGET_LDFLAGS+= -L$(TOOLCHAIN_DIR)/usr/lib -L$(TOOLCHAIN_DIR)/lib
  168. TARGET_PATH:=$(TOOLCHAIN_DIR)/bin:$(TARGET_PATH)
  169. else
  170. ifeq ($(CONFIG_NATIVE_TOOLCHAIN),)
  171. TARGET_CROSS:=$(call qstrip,$(CONFIG_TOOLCHAIN_PREFIX))
  172. TOOLCHAIN_ROOT_DIR:=$(call qstrip,$(CONFIG_TOOLCHAIN_ROOT))
  173. TOOLCHAIN_BIN_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_BIN_PATH)))
  174. TOOLCHAIN_INC_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_INC_PATH)))
  175. TOOLCHAIN_LIB_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_LIB_PATH)))
  176. ifneq ($(TOOLCHAIN_BIN_DIRS),)
  177. TARGET_PATH:=$(subst $(space),:,$(TOOLCHAIN_BIN_DIRS)):$(TARGET_PATH)
  178. endif
  179. ifneq ($(TOOLCHAIN_INC_DIRS),)
  180. TARGET_CPPFLAGS+= $(patsubst %,-I%,$(TOOLCHAIN_INC_DIRS))
  181. endif
  182. ifneq ($(TOOLCHAIN_LIB_DIRS),)
  183. TARGET_LDFLAGS+= $(patsubst %,-L%,$(TOOLCHAIN_LIB_DIRS))
  184. endif
  185. TARGET_PATH:=$(TOOLCHAIN_DIR)/bin:$(TARGET_PATH)
  186. endif
  187. endif
  188. endif
  189. TARGET_PATH_PKG:=$(STAGING_DIR)/host/bin:$(STAGING_DIR_HOSTPKG)/bin:$(TARGET_PATH)
  190. ifeq ($(CONFIG_SOFT_FLOAT),y)
  191. SOFT_FLOAT_CONFIG_OPTION:=--with-float=soft
  192. ifeq ($(CONFIG_arm),y)
  193. TARGET_CFLAGS+= -mfloat-abi=soft
  194. else
  195. TARGET_CFLAGS+= -msoft-float
  196. endif
  197. else
  198. SOFT_FLOAT_CONFIG_OPTION:=
  199. ifeq ($(CONFIG_arm),y)
  200. TARGET_CFLAGS+= -mfloat-abi=hard
  201. endif
  202. endif
  203. export PATH:=$(TARGET_PATH)
  204. export STAGING_DIR STAGING_DIR_HOST STAGING_DIR_HOSTPKG
  205. export SH_FUNC:=. $(INCLUDE_DIR)/shell.sh;
  206. PKG_CONFIG:=$(STAGING_DIR_HOST)/bin/pkg-config
  207. export PKG_CONFIG
  208. HOSTCC:=gcc
  209. HOSTCXX:=g++
  210. HOST_CPPFLAGS:=-I$(STAGING_DIR_HOST)/include $(if $(IS_PACKAGE_BUILD),-I$(STAGING_DIR_HOSTPKG)/include -I$(STAGING_DIR)/host/include)
  211. HOST_CFLAGS:=-O2 $(HOST_CPPFLAGS)
  212. HOST_LDFLAGS:=-L$(STAGING_DIR_HOST)/lib $(if $(IS_PACKAGE_BUILD),-L$(STAGING_DIR_HOSTPKG)/lib -L$(STAGING_DIR)/host/lib)
  213. ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
  214. TARGET_AR:=$(TARGET_CROSS)gcc-ar
  215. TARGET_RANLIB:=$(TARGET_CROSS)gcc-ranlib
  216. TARGET_NM:=$(TARGET_CROSS)gcc-nm
  217. else
  218. TARGET_AR:=$(TARGET_CROSS)ar
  219. TARGET_RANLIB:=$(TARGET_CROSS)ranlib
  220. TARGET_NM:=$(TARGET_CROSS)nm
  221. endif
  222. BUILD_KEY=$(TOPDIR)/key-build
  223. FAKEROOT:=$(STAGING_DIR_HOST)/bin/fakeroot
  224. TARGET_CC:=$(TARGET_CROSS)gcc
  225. TARGET_CXX:=$(TARGET_CROSS)g++
  226. KPATCH:=$(SCRIPT_DIR)/patch-kernel.sh
  227. SED:=$(STAGING_DIR_HOST)/bin/sed -i -e
  228. ESED:=$(STAGING_DIR_HOST)/bin/sed -E -i -e
  229. CP:=cp -fpR
  230. LN:=ln -sf
  231. XARGS:=xargs -r
  232. BASH:=bash
  233. TAR:=tar
  234. FIND:=find
  235. PATCH:=patch
  236. PYTHON:=python
  237. INSTALL_BIN:=install -m0755
  238. INSTALL_SUID:=install -m4755
  239. INSTALL_DIR:=install -d -m0755
  240. INSTALL_DATA:=install -m0644
  241. INSTALL_CONF:=install -m0600
  242. TARGET_CC_NOCACHE:=$(TARGET_CC)
  243. TARGET_CXX_NOCACHE:=$(TARGET_CXX)
  244. HOSTCC_NOCACHE:=$(HOSTCC)
  245. HOSTCXX_NOCACHE:=$(HOSTCXX)
  246. export TARGET_CC_NOCACHE
  247. export TARGET_CXX_NOCACHE
  248. export HOSTCC_NOCACHE
  249. export HOSTCXX_NOCACHE
  250. ifneq ($(CONFIG_CCACHE),)
  251. TARGET_CC:= ccache_cc
  252. TARGET_CXX:= ccache_cxx
  253. HOSTCC:= ccache $(HOSTCC)
  254. HOSTCXX:= ccache $(HOSTCXX)
  255. export CCACHE_BASEDIR:=$(TOPDIR)
  256. export CCACHE_DIR:=$(if $(call qstrip,$(CONFIG_CCACHE_DIR)),$(call qstrip,$(CONFIG_CCACHE_DIR)),$(TOPDIR)/.ccache)
  257. export CCACHE_COMPILERCHECK:=%compiler% -dumpmachine; %compiler% -dumpversion
  258. endif
  259. TARGET_CONFIGURE_OPTS = \
  260. AR="$(TARGET_AR)" \
  261. AS="$(TARGET_CC) -c $(TARGET_ASFLAGS)" \
  262. LD=$(TARGET_CROSS)ld \
  263. NM="$(TARGET_NM)" \
  264. CC="$(TARGET_CC)" \
  265. GCC="$(TARGET_CC)" \
  266. CXX="$(TARGET_CXX)" \
  267. RANLIB="$(TARGET_RANLIB)" \
  268. STRIP=$(TARGET_CROSS)strip \
  269. OBJCOPY=$(TARGET_CROSS)objcopy \
  270. OBJDUMP=$(TARGET_CROSS)objdump \
  271. SIZE=$(TARGET_CROSS)size
  272. # strip an entire directory
  273. ifneq ($(CONFIG_NO_STRIP),)
  274. RSTRIP:=:
  275. STRIP:=:
  276. else
  277. ifneq ($(CONFIG_USE_STRIP),)
  278. STRIP:=$(TARGET_CROSS)strip $(call qstrip,$(CONFIG_STRIP_ARGS))
  279. else
  280. ifneq ($(CONFIG_USE_SSTRIP),)
  281. STRIP:=$(STAGING_DIR_HOST)/bin/sstrip $(call qstrip,$(CONFIG_SSTRIP_ARGS))
  282. endif
  283. endif
  284. RSTRIP= \
  285. export CROSS="$(TARGET_CROSS)" \
  286. $(if $(PKG_BUILD_ID),KEEP_BUILD_ID=1) \
  287. $(if $(CONFIG_KERNEL_KALLSYMS),NO_RENAME=1) \
  288. $(if $(CONFIG_KERNEL_PROFILING),KEEP_SYMBOLS=1); \
  289. NM="$(TARGET_CROSS)nm" \
  290. STRIP="$(STRIP)" \
  291. STRIP_KMOD="$(SCRIPT_DIR)/strip-kmod.sh" \
  292. PATCHELF="$(STAGING_DIR_HOST)/bin/patchelf" \
  293. $(SCRIPT_DIR)/rstrip.sh
  294. endif
  295. ifeq ($(CONFIG_IPV6),y)
  296. DISABLE_IPV6:=
  297. else
  298. DISABLE_IPV6:=--disable-ipv6
  299. endif
  300. TAR_OPTIONS:=-xf -
  301. ifeq ($(CONFIG_BUILD_LOG),y)
  302. BUILD_LOG:=1
  303. endif
  304. export BISON_PKGDATADIR:=$(STAGING_DIR_HOST)/share/bison
  305. export M4:=$(STAGING_DIR_HOST)/bin/m4
  306. define shvar
  307. V_$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
  308. endef
  309. define shexport
  310. export $(call shvar,$(1))=$$(call $(1))
  311. endef
  312. # Execute commands under flock
  313. # $(1) => The shell expression.
  314. # $(2) => The lock name. If not given, the global lock will be used.
  315. ifneq ($(wildcard $(STAGING_DIR_HOST)/bin/flock),)
  316. define locked
  317. SHELL= \
  318. flock \
  319. $(TMP_DIR)/.$(if $(2),$(strip $(2)),global).flock \
  320. -c '$(subst ','\'',$(1))'
  321. endef
  322. else
  323. locked=$(1)
  324. endif
  325. # Recursively copy paths into another directory, purge dangling
  326. # symlinks before.
  327. # $(1) => File glob expression
  328. # $(2) => Destination directory
  329. define file_copy
  330. for src_dir in $(sort $(foreach d,$(wildcard $(1)),$(dir $(d)))); do \
  331. ( cd $$src_dir; find -type f -or -type d ) | \
  332. ( cd $(2); while :; do \
  333. read FILE; \
  334. [ -z "$$FILE" ] && break; \
  335. [ -L "$$FILE" ] || continue; \
  336. echo "Removing symlink $(2)/$$FILE"; \
  337. rm -f "$$FILE"; \
  338. done; ); \
  339. done; \
  340. $(CP) $(1) $(2)
  341. endef
  342. # Calculate sha256sum of any plain file within a given directory
  343. # $(1) => Input directory
  344. # $(2) => If set, recurse into subdirectories
  345. define sha256sums
  346. (cd $(1); find . $(if $(2),,-maxdepth 1) -type f -not -name 'sha256sums' -printf "%P\n" | sort | \
  347. xargs -r $(STAGING_DIR_HOST)/bin/mkhash -n sha256 | sed -ne 's!^\(.*\) \(.*\)$$!\1 *\2!p' > sha256sums)
  348. endef
  349. # file extension
  350. ext=$(word $(words $(subst ., ,$(1))),$(subst ., ,$(1)))
  351. # Count Git commits of a package
  352. # $(1) => if non-empty: count commits since last ": [uU]pdate to " or ": [bB]ump to " in commit message
  353. define commitcount
  354. $(shell \
  355. if git log -1 >/dev/null 2>/dev/null; then \
  356. if [ -n "$(1)" ]; then \
  357. last_bump="$$(git log --pretty=format:'%h %s' . | \
  358. grep --max-count=1 -e ': [uU]pdate to ' -e ': [bB]ump to ' | \
  359. cut -f 1 -d ' ')"; \
  360. fi; \
  361. if [ -n "$$last_bump" ]; then \
  362. echo -n $$(($$(git rev-list --count "$$last_bump..HEAD" .) + 1)); \
  363. else \
  364. git rev-list --count HEAD .; \
  365. fi; \
  366. else \
  367. secs="$$(($(SOURCE_DATE_EPOCH) % 86400))"; \
  368. date="$$(date --utc --date="@$(SOURCE_DATE_EPOCH)" "+%y%m%d")"; \
  369. printf '%s.%05d' "$$date" "$$secs"; \
  370. fi; \
  371. )
  372. endef
  373. abi_version_str = $(subst -,,$(subst _,,$(subst .,,$(1))))
  374. COMMITCOUNT = $(if $(DUMP),0,$(call commitcount))
  375. AUTORELEASE = $(if $(DUMP),0,$(call commitcount,1))
  376. all:
  377. FORCE: ;
  378. .PHONY: FORCE
  379. check: FORCE
  380. @true
  381. val.%:
  382. @$(if $(filter undefined,$(origin $*)),\
  383. echo "$* undefined" >&2, \
  384. echo '$(subst ','"'"',$($*))' \
  385. )
  386. var.%:
  387. @$(if $(filter undefined,$(origin $*)),\
  388. echo "$* undefined" >&2, \
  389. echo "$*='"'$(subst ','"'\"'\"'"',$($*))'"'" \
  390. )
  391. endif #__rules_inc