1
0

rules.mk 14 KB

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