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