cbe1b0cb4c7f6fa9753f30ae90b2a7e1f08f7a83
[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))))' | $(STAGING_DIR_HOST)/bin/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:=-fPIC
79 else
80 FPIC:=-fpic
81 endif
82
83 HOST_FPIC:=-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 ifeq ($(CONFIG_GCC_USE_IREMAP),y)
142 iremap = -iremap$(1):$(2)
143 else
144 iremap = -f$(if $(CONFIG_REPRODUCIBLE_DEBUG_INFO),file,macro)-prefix-map=$(1)=$(2)
145 endif
146 endif
147
148 PACKAGE_DIR:=$(BIN_DIR)/packages
149 PACKAGE_DIR_ALL:=$(TOPDIR)/staging_dir/packages/$(BOARD)
150 BUILD_DIR:=$(BUILD_DIR_BASE)/$(TARGET_DIR_NAME)
151 STAGING_DIR:=$(TOPDIR)/staging_dir/$(TARGET_DIR_NAME)
152 BUILD_DIR_TOOLCHAIN:=$(BUILD_DIR_BASE)/$(TOOLCHAIN_DIR_NAME)
153 TOOLCHAIN_DIR:=$(TOPDIR)/staging_dir/$(TOOLCHAIN_DIR_NAME)
154 STAMP_DIR:=$(BUILD_DIR)/stamp
155 STAMP_DIR_HOST=$(BUILD_DIR_HOST)/stamp
156 TARGET_ROOTFS_DIR?=$(if $(call qstrip,$(CONFIG_TARGET_ROOTFS_DIR)),$(call qstrip,$(CONFIG_TARGET_ROOTFS_DIR)),$(BUILD_DIR))
157 TARGET_DIR:=$(TARGET_ROOTFS_DIR)/root-$(BOARD)
158 STAGING_DIR_ROOT:=$(STAGING_DIR)/root-$(BOARD)
159 STAGING_DIR_IMAGE:=$(STAGING_DIR)/image
160 BUILD_LOG_DIR:=$(if $(call qstrip,$(CONFIG_BUILD_LOG_DIR)),$(call qstrip,$(CONFIG_BUILD_LOG_DIR)),$(TOPDIR)/logs)
161 PKG_INFO_DIR := $(STAGING_DIR)/pkginfo
162
163 BUILD_DIR_HOST:=$(if $(IS_PACKAGE_BUILD),$(BUILD_DIR_BASE)/hostpkg,$(BUILD_DIR_BASE)/host)
164 STAGING_DIR_HOST:=$(TOPDIR)/staging_dir/host
165 STAGING_DIR_HOSTPKG:=$(TOPDIR)/staging_dir/hostpkg
166
167 TARGET_PATH:=$(subst $(space),:,$(filter-out .,$(filter-out ./,$(subst :,$(space),$(PATH)))))
168 TARGET_INIT_PATH:=$(call qstrip,$(CONFIG_TARGET_INIT_PATH))
169 TARGET_INIT_PATH:=$(if $(TARGET_INIT_PATH),$(TARGET_INIT_PATH),/usr/sbin:/sbin:/usr/bin:/bin)
170 TARGET_CFLAGS:=$(TARGET_OPTIMIZATION)$(if $(CONFIG_DEBUG), -g3) $(call qstrip,$(CONFIG_EXTRA_OPTIMIZATION))
171 TARGET_CXXFLAGS = $(TARGET_CFLAGS)
172 TARGET_ASFLAGS_DEFAULT = $(TARGET_CFLAGS)
173 TARGET_ASFLAGS = $(TARGET_ASFLAGS_DEFAULT)
174 ifneq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
175 LIBGCC_S_PATH=$(realpath $(wildcard $(call qstrip,$(CONFIG_LIBGCC_ROOT_DIR))/$(call qstrip,$(CONFIG_LIBGCC_FILE_SPEC))))
176 LIBGCC_S=$(if $(LIBGCC_S_PATH),-L$(dir $(LIBGCC_S_PATH)) -lgcc_s)
177 LIBGCC_A=$(realpath $(lastword $(wildcard $(dir $(LIBGCC_S_PATH))/gcc/*/*/libgcc.a)))
178 else
179 LIBGCC_A=$(lastword $(wildcard $(TOOLCHAIN_DIR)/lib/gcc/*/*/libgcc.a))
180 LIBGCC_S=$(if $(wildcard $(TOOLCHAIN_DIR)/lib/libgcc_s.so),-L$(TOOLCHAIN_DIR)/lib -lgcc_s,$(LIBGCC_A))
181 endif
182
183 ifeq ($(CONFIG_ARCH_64BIT),y)
184 LIB_SUFFIX:=64
185 endif
186
187 ifndef DUMP
188 ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
189 -include $(TOOLCHAIN_DIR)/info.mk
190 export GCC_HONOUR_COPTS:=0
191 TARGET_CROSS:=$(if $(TARGET_CROSS),$(TARGET_CROSS),$(OPTIMIZE_FOR_CPU)-openwrt-linux$(if $(TARGET_SUFFIX),-$(TARGET_SUFFIX))-)
192 TARGET_CFLAGS+= -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result
193 TARGET_CPPFLAGS+= -I$(TOOLCHAIN_DIR)/usr/include
194 ifeq ($(CONFIG_USE_MUSL),y)
195 TARGET_CPPFLAGS+= -I$(TOOLCHAIN_DIR)/include/fortify
196 endif
197 TARGET_CPPFLAGS+= -I$(TOOLCHAIN_DIR)/include
198 TARGET_LDFLAGS+= -L$(TOOLCHAIN_DIR)/usr/lib -L$(TOOLCHAIN_DIR)/lib
199 TARGET_PATH:=$(TOOLCHAIN_DIR)/bin:$(TARGET_PATH)
200 else
201 ifeq ($(CONFIG_NATIVE_TOOLCHAIN),)
202 TARGET_CROSS:=$(call qstrip,$(CONFIG_TOOLCHAIN_PREFIX))
203 TOOLCHAIN_ROOT_DIR:=$(call qstrip,$(CONFIG_TOOLCHAIN_ROOT))
204 TOOLCHAIN_BIN_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_BIN_PATH)))
205 TOOLCHAIN_INC_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_INC_PATH)))
206 TOOLCHAIN_LIB_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_LIB_PATH)))
207 ifneq ($(TOOLCHAIN_BIN_DIRS),)
208 TARGET_PATH:=$(subst $(space),:,$(TOOLCHAIN_BIN_DIRS)):$(TARGET_PATH)
209 endif
210 ifneq ($(TOOLCHAIN_INC_DIRS),)
211 TARGET_CPPFLAGS+= $(patsubst %,-I%,$(TOOLCHAIN_INC_DIRS))
212 endif
213 ifneq ($(TOOLCHAIN_LIB_DIRS),)
214 TARGET_LDFLAGS+= $(patsubst %,-L%,$(TOOLCHAIN_LIB_DIRS))
215 endif
216 TARGET_PATH:=$(TOOLCHAIN_DIR)/bin:$(TARGET_PATH)
217 endif
218 endif
219 endif
220 TARGET_PATH_PKG:=$(STAGING_DIR)/host/bin:$(STAGING_DIR_HOSTPKG)/bin:$(TARGET_PATH)
221
222 ifeq ($(CONFIG_SOFT_FLOAT),y)
223 SOFT_FLOAT_CONFIG_OPTION:=--with-float=soft
224 ifeq ($(CONFIG_arm),y)
225 TARGET_CFLAGS+= -mfloat-abi=soft
226 else
227 TARGET_CFLAGS+= -msoft-float
228 endif
229 else
230 SOFT_FLOAT_CONFIG_OPTION:=
231 ifeq ($(CONFIG_arm),y)
232 TARGET_CFLAGS+= -mfloat-abi=hard
233 endif
234 endif
235
236 export PATH:=$(TARGET_PATH)
237 export STAGING_DIR STAGING_DIR_HOST STAGING_DIR_HOSTPKG
238 export SH_FUNC:=. $(INCLUDE_DIR)/shell.sh;
239
240 PKG_CONFIG:=$(STAGING_DIR_HOST)/bin/pkg-config
241
242 export PKG_CONFIG
243
244 HOSTCC:=gcc
245 HOSTCXX:=g++
246 HOST_CPPFLAGS:=-I$(STAGING_DIR_HOST)/include $(if $(IS_PACKAGE_BUILD),-I$(STAGING_DIR_HOSTPKG)/include -I$(STAGING_DIR)/host/include)
247 HOST_CFLAGS:=-O2 $(HOST_CPPFLAGS)
248 HOST_LDFLAGS:=-L$(STAGING_DIR_HOST)/lib $(if $(IS_PACKAGE_BUILD),-L$(STAGING_DIR_HOSTPKG)/lib -L$(STAGING_DIR)/host/lib)
249
250 ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
251 TARGET_AR:=$(TARGET_CROSS)gcc-ar
252 TARGET_RANLIB:=$(TARGET_CROSS)gcc-ranlib
253 TARGET_NM:=$(TARGET_CROSS)gcc-nm
254 else
255 TARGET_AR:=$(TARGET_CROSS)ar
256 TARGET_RANLIB:=$(TARGET_CROSS)ranlib
257 TARGET_NM:=$(TARGET_CROSS)nm
258 endif
259
260 BUILD_KEY=$(TOPDIR)/key-build
261
262 FAKEROOT:=$(STAGING_DIR_HOST)/bin/fakeroot
263
264 TARGET_CC:=$(TARGET_CROSS)gcc
265 TARGET_CXX:=$(TARGET_CROSS)g++
266 KPATCH:=$(SCRIPT_DIR)/patch-kernel.sh
267 SED:=$(STAGING_DIR_HOST)/bin/sed -i -e
268 ESED:=$(STAGING_DIR_HOST)/bin/sed -E -i -e
269 CP:=cp -fpR
270 LN:=ln -sf
271 XARGS:=xargs -r
272
273 BASH:=bash
274 TAR:=tar
275 FIND:=find
276 PATCH:=patch
277 PYTHON:=python
278
279 INSTALL_BIN:=install -m0755
280 INSTALL_SUID:=install -m4755
281 INSTALL_DIR:=install -d -m0755
282 INSTALL_DATA:=install -m0644
283 INSTALL_CONF:=install -m0600
284
285 TARGET_CC_NOCACHE:=$(TARGET_CC)
286 TARGET_CXX_NOCACHE:=$(TARGET_CXX)
287 HOSTCC_NOCACHE:=$(HOSTCC)
288 HOSTCXX_NOCACHE:=$(HOSTCXX)
289 export TARGET_CC_NOCACHE
290 export TARGET_CXX_NOCACHE
291 export HOSTCC_NOCACHE
292 export HOSTCXX_NOCACHE
293
294 ifneq ($(CONFIG_CCACHE),)
295 TARGET_CC:= ccache_cc
296 TARGET_CXX:= ccache_cxx
297 HOSTCC:= ccache $(HOSTCC)
298 HOSTCXX:= ccache $(HOSTCXX)
299 export CCACHE_BASEDIR:=$(TOPDIR)
300 export CCACHE_DIR:=$(if $(call qstrip,$(CONFIG_CCACHE_DIR)),$(call qstrip,$(CONFIG_CCACHE_DIR)),$(TOPDIR)/.ccache)
301 export CCACHE_COMPILERCHECK:=%compiler% -dumpmachine; %compiler% -dumpversion
302 endif
303
304 TARGET_CONFIGURE_OPTS = \
305 AR="$(TARGET_AR)" \
306 AS="$(TARGET_CC) -c $(TARGET_ASFLAGS)" \
307 LD=$(TARGET_CROSS)ld \
308 NM="$(TARGET_NM)" \
309 CC="$(TARGET_CC)" \
310 GCC="$(TARGET_CC)" \
311 CXX="$(TARGET_CXX)" \
312 RANLIB="$(TARGET_RANLIB)" \
313 STRIP=$(TARGET_CROSS)strip \
314 OBJCOPY=$(TARGET_CROSS)objcopy \
315 OBJDUMP=$(TARGET_CROSS)objdump \
316 SIZE=$(TARGET_CROSS)size
317
318 # strip an entire directory
319 ifneq ($(CONFIG_NO_STRIP),)
320 RSTRIP:=:
321 STRIP:=:
322 else
323 ifneq ($(CONFIG_USE_STRIP),)
324 STRIP:=$(TARGET_CROSS)strip $(call qstrip,$(CONFIG_STRIP_ARGS))
325 else
326 ifneq ($(CONFIG_USE_SSTRIP),)
327 STRIP:=$(STAGING_DIR_HOST)/bin/sstrip $(call qstrip,$(CONFIG_SSTRIP_ARGS))
328 endif
329 endif
330 RSTRIP= \
331 export CROSS="$(TARGET_CROSS)" \
332 $(if $(PKG_BUILD_ID),KEEP_BUILD_ID=1) \
333 $(if $(CONFIG_KERNEL_KALLSYMS),NO_RENAME=1) \
334 $(if $(CONFIG_KERNEL_PROFILING),KEEP_SYMBOLS=1); \
335 NM="$(TARGET_CROSS)nm" \
336 STRIP="$(STRIP)" \
337 STRIP_KMOD="$(SCRIPT_DIR)/strip-kmod.sh" \
338 PATCHELF="$(STAGING_DIR_HOST)/bin/patchelf" \
339 $(SCRIPT_DIR)/rstrip.sh
340 endif
341
342 ifeq ($(CONFIG_IPV6),y)
343 DISABLE_IPV6:=
344 else
345 DISABLE_IPV6:=--disable-ipv6
346 endif
347
348 TAR_OPTIONS:=-xf -
349
350 ifeq ($(CONFIG_BUILD_LOG),y)
351 BUILD_LOG:=1
352 endif
353
354 export BISON_PKGDATADIR:=$(STAGING_DIR_HOST)/share/bison
355 export M4:=$(STAGING_DIR_HOST)/bin/m4
356
357 define shvar
358 V_$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
359 endef
360
361 define shexport
362 export $(call shvar,$(1))=$$(call $(1))
363 endef
364
365 # Execute commands under flock
366 # $(1) => The shell expression.
367 # $(2) => The lock name. If not given, the global lock will be used.
368 ifneq ($(wildcard $(STAGING_DIR_HOST)/bin/flock),)
369 define locked
370 SHELL= \
371 flock \
372 $(TMP_DIR)/.$(if $(2),$(strip $(2)),global).flock \
373 -c '$(subst ','\'',$(1))'
374 endef
375 else
376 locked=$(1)
377 endif
378
379 # Recursively copy paths into another directory, purge dangling
380 # symlinks before.
381 # $(1) => File glob expression
382 # $(2) => Destination directory
383 define file_copy
384 for src_dir in $(sort $(foreach d,$(wildcard $(1)),$(dir $(d)))); do \
385 ( cd $$src_dir; find -type f -or -type d ) | \
386 ( cd $(2); while :; do \
387 read FILE; \
388 [ -z "$$FILE" ] && break; \
389 [ -L "$$FILE" ] || continue; \
390 echo "Removing symlink $(2)/$$FILE"; \
391 rm -f "$$FILE"; \
392 done; ); \
393 done; \
394 $(CP) $(1) $(2)
395 endef
396
397 # Calculate sha256sum of any plain file within a given directory
398 # $(1) => Input directory
399 # $(2) => If set, recurse into subdirectories
400 define sha256sums
401 (cd $(1); find . $(if $(2),,-maxdepth 1) -type f -not -name 'sha256sums' -printf "%P\n" | sort | \
402 xargs -r $(STAGING_DIR_HOST)/bin/mkhash -n sha256 | sed -ne 's!^\(.*\) \(.*\)$$!\1 *\2!p' > sha256sums)
403 endef
404
405 # file extension
406 ext=$(word $(words $(subst ., ,$(1))),$(subst ., ,$(1)))
407
408 # Count Git commits of a package
409 # $(1) => if non-empty: count commits since last ": [uU]pdate to " or ": [bB]ump to " in commit message
410 define commitcount
411 $(shell \
412 if git log -1 >/dev/null 2>/dev/null; then \
413 if [ -n "$(1)" ]; then \
414 last_bump="$$(git log --pretty=format:'%h %s' . | \
415 grep --max-count=1 -e ': [uU]pdate to ' -e ': [bB]ump to ' | \
416 cut -f 1 -d ' ')"; \
417 fi; \
418 if [ -n "$$last_bump" ]; then \
419 echo -n $$(($$(git rev-list --count "$$last_bump..HEAD" .) + 1)); \
420 else \
421 git rev-list --count HEAD .; \
422 fi; \
423 else \
424 secs="$$(($(SOURCE_DATE_EPOCH) % 86400))"; \
425 date="$$(date --utc --date="@$(SOURCE_DATE_EPOCH)" "+%y%m%d")"; \
426 printf '%s.%05d' "$$date" "$$secs"; \
427 fi; \
428 )
429 endef
430
431 COMMITCOUNT = $(if $(DUMP),0,$(call commitcount))
432 AUTORELEASE = $(if $(DUMP),0,$(call commitcount,1))
433
434 all:
435 FORCE: ;
436 .PHONY: FORCE
437
438 check: FORCE
439 @true
440
441 val.%:
442 @$(if $(filter undefined,$(origin $*)),\
443 echo "$* undefined" >&2, \
444 echo '$(subst ','"'"',$($*))' \
445 )
446
447 var.%:
448 @$(if $(filter undefined,$(origin $*)),\
449 echo "$* undefined" >&2, \
450 echo "$*='"'$(subst ','"'\"'\"'"',$($*))'"'" \
451 )
452
453 endif #__rules_inc