aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/kernel/smp_twd.c
blob: 31deb5ae00610a7ef72219f338e7e2c7b5f88d4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
 *  linux/arch/arm/kernel/smp_twd.c
 *
 *  Copyright (C) 2002 ARM Ltd.
 *  All Rights Reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/smp.h>
#include <linux/jiffies.h>
#include <linux/clockchips.h>
#include <linux/irq.h>
#include <linux/io.h>
#include <linux/clk.h>
#include <linux/cpufreq.h>
#include <linux/err.h>

#include <asm/smp_twd.h>
#include <asm/hardware/gic.h>

/* set up by the platform code */
void __iomem *twd_base;
static struct clk *twd_clk;

static unsigned long twd_timer_rate;

static struct clock_event_device __percpu **twd_evt;

static void twd_set_mode(enum clock_event_mode mode,
			struct clock_event_device *clk)
{
	unsigned long ctrl;

	switch (mode) {
	case CLOCK_EVT_MODE_PERIODIC:
		/* timer load already set up */
		ctrl = TWD_TIMER_CONTROL_ENABLE | TWD_TIMER_CONTROL_IT_ENABLE
			| TWD_TIMER_CONTROL_PERIODIC;
		__raw_writel(twd_timer_rate / HZ, twd_base + TWD_TIMER_LOAD);
		gic_enable_ppi(clk->irq);
		break;
	case CLOCK_EVT_MODE_ONESHOT:
		/* period set, and timer enabled in 'next_event' hook */
		ctrl = TWD_TIMER_CONTROL_IT_ENABLE | TWD_TIMER_CONTROL_ONESHOT;
		gic_enable_ppi(clk->irq);
		break;
	case CLOCK_EVT_MODE_UNUSED:
	case CLOCK_EVT_MODE_SHUTDOWN:
	default:
		ctrl = 0;
		gic_disable_ppi(clk->irq);
	}

	__raw_writel(ctrl, twd_base + TWD_TIMER_CONTROL);
}

static int twd_set_next_event(unsigned long evt,
			struct clock_event_device *unused)
{
	unsigned long ctrl = __raw_readl(twd_base + TWD_TIMER_CONTROL);

	ctrl |= TWD_TIMER_CONTROL_ENABLE;

	__raw_writel(evt, twd_base + TWD_TIMER_COUNTER);
	__raw_writel(ctrl, twd_base + TWD_TIMER_CONTROL);

	return 0;
}

/*
 * local_timer_ack: checks for a local timer interrupt.
 *
 * If a local timer interrupt has occurred, acknowledge and return 1.
 * Otherwise, return 0.
 */
int twd_timer_ack(void)
{
	if (__raw_readl(twd_base + TWD_TIMER_INTSTAT)) {
		__raw_writel(1, twd_base + TWD_TIMER_INTSTAT);
		return 1;
	}

	return 0;
}

static struct clk *twd_get_clock(void)
{
	return clk_get_sys("smp_twd", NULL);
}

#ifdef CONFIG_CPU_FREQ
/*
 * Updates clockevent frequency when the cpu frequency changes.
 * Called on the cpu that is changing frequency with interrupts disabled.
 */
static void twd_update_frequency(void *data)
{
	twd_timer_rate = clk_get_rate(twd_clk);

	clockevents_update_freq(*__this_cpu_ptr(twd_evt), twd_timer_rate);
}

static int twd_cpufreq_transition(struct notifier_block *nb,
	unsigned long state, void *data)
{
	struct cpufreq_freqs *freqs = data;

	/*
	 * The twd clock events must be reprogrammed to account for the new
	 * frequency.  The timer is local to a cpu, so cross-call to the
	 * changing cpu.
	 *
	 * Only wait for it to finish, if the cpu is active to avoid
	 * deadlock when cpu1 is spinning on while(!cpu_active(cpu1)) during
	 * booting of that cpu.
	 */
	if (state == CPUFREQ_POSTCHANGE || state == CPUFREQ_RESUMECHANGE)
		smp_call_function_single(freqs->cpu, twd_update_frequency,
					 NULL, cpu_active(freqs->cpu));

	return NOTIFY_OK;
}

static struct notifier_block twd_cpufreq_nb = {
	.notifier_call = twd_cpufreq_transition,
};

static int twd_cpufreq_init(void)
{
	if (twd_evt && *__this_cpu_ptr(twd_evt) && !IS_ERR(twd_clk))
		return cpufreq_register_notifier(&twd_cpufreq_nb,
			CPUFREQ_TRANSITION_NOTIFIER);

	return 0;
}
core_initcall(twd_cpufreq_init);

#endif
static void __cpuinit twd_calibrate_rate(void)
{
	unsigned long count;
	u64 waitjiffies;

	/*
	 * If this is the first time round, we need to work out how fast
	 * the timer ticks
	 */
	if (twd_timer_rate == 0) {
		printk(KERN_INFO "Calibrating local timer... ");

		/* Wait for a tick to start */
		waitjiffies = get_jiffies_64() + 1;

		while (get_jiffies_64() < waitjiffies)
			udelay(10);

		/* OK, now the tick has started, let's get the timer going */
		waitjiffies += 5;

				 /* enable, no interrupt or reload */
		__raw_writel(0x1, twd_base + TWD_TIMER_CONTROL);

				 /* maximum value */
		__raw_writel(0xFFFFFFFFU, twd_base + TWD_TIMER_COUNTER);

		while (get_jiffies_64() < waitjiffies)
			udelay(10);

		count = __raw_readl(twd_base + TWD_TIMER_COUNTER);

		twd_timer_rate = (0xFFFFFFFFU - count) * (HZ / 5);

		printk("%lu.%02luMHz.\n", twd_timer_rate / 1000000,
			(twd_timer_rate / 10000) % 100);
	}
}

/*
 * Setup the local clock events for a CPU.
 */
void __cpuinit twd_timer_setup(struct clock_event_device *clk)
{
	struct clock_event_device **this_cpu_clk;

	if (!twd_evt) {

		twd_evt = alloc_percpu(struct clock_event_device *);
		if (!twd_evt) {
			pr_err("twd: can't allocate memory\n");
			return;
		}
	}

	if (!twd_clk)
		twd_clk = twd_get_clock();

	if (!IS_ERR_OR_NULL(twd_clk))
		twd_timer_rate = clk_get_rate(twd_clk);
	else
		twd_calibrate_rate();

	clk->name = "local_timer";
	clk->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT |
			CLOCK_EVT_FEAT_C3STOP;
	clk->rating = 350;
	clk->set_mode = twd_set_mode;
	clk->set_next_event = twd_set_next_event;

	this_cpu_clk = __this_cpu_ptr(twd_evt);
	*this_cpu_clk = clk;

	clockevents_config_and_register(clk, twd_timer_rate,
					0xf, 0xffffffff);

	/* Make sure our local interrupt controller has this enabled */
	gic_enable_ppi(clk->irq);
}
class="k">)/scripts BUILD_DIR_BASE:=$(TOPDIR)/build_dir ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),) GCCV:=$(call qstrip,$(CONFIG_GCC_VERSION)) LIBC:=$(call qstrip,$(CONFIG_LIBC)) REAL_GNU_TARGET_NAME=$(OPTIMIZE_FOR_CPU)-openwrt-linux$(if $(TARGET_SUFFIX),-$(TARGET_SUFFIX)) GNU_TARGET_NAME=$(OPTIMIZE_FOR_CPU)-openwrt-linux DIR_SUFFIX:=_$(LIBC)$(if $(CONFIG_arm),_eabi) BIN_DIR:=$(BIN_DIR)$(if $(CONFIG_USE_MUSL),,-$(LIBC)) TARGET_DIR_NAME = target-$(ARCH)$(ARCH_SUFFIX)$(DIR_SUFFIX)$(if $(BUILD_SUFFIX),_$(BUILD_SUFFIX)) TOOLCHAIN_DIR_NAME = toolchain-$(ARCH)$(ARCH_SUFFIX)_gcc-$(GCCV)$(DIR_SUFFIX) else ifeq ($(CONFIG_NATIVE_TOOLCHAIN),) GNU_TARGET_NAME=$(call qstrip,$(CONFIG_TARGET_NAME)) else GNU_TARGET_NAME=$(shell gcc -dumpmachine) endif REAL_GNU_TARGET_NAME=$(GNU_TARGET_NAME) LIBC:=$(call qstrip,$(CONFIG_LIBC)) TARGET_DIR_NAME:=target-$(GNU_TARGET_NAME)_$(LIBC)$(if $(BUILD_SUFFIX),_$(BUILD_SUFFIX)) TOOLCHAIN_DIR_NAME:=toolchain-$(GNU_TARGET_NAME) endif ifeq ($(or $(CONFIG_EXTERNAL_TOOLCHAIN),$(CONFIG_TARGET_uml)),) ifeq ($(CONFIG_GCC_USE_IREMAP),y) iremap = -iremap$(1):$(2) else iremap = -f$(if $(CONFIG_REPRODUCIBLE_DEBUG_INFO),file,macro)-prefix-map=$(1)=$(2) endif endif PACKAGE_DIR:=$(BIN_DIR)/packages PACKAGE_DIR_ALL:=$(TOPDIR)/staging_dir/packages/$(BOARD) BUILD_DIR:=$(BUILD_DIR_BASE)/$(TARGET_DIR_NAME) STAGING_DIR:=$(TOPDIR)/staging_dir/$(TARGET_DIR_NAME) BUILD_DIR_TOOLCHAIN:=$(BUILD_DIR_BASE)/$(TOOLCHAIN_DIR_NAME) TOOLCHAIN_DIR:=$(TOPDIR)/staging_dir/$(TOOLCHAIN_DIR_NAME) STAMP_DIR:=$(BUILD_DIR)/stamp STAMP_DIR_HOST=$(BUILD_DIR_HOST)/stamp TARGET_ROOTFS_DIR?=$(if $(call qstrip,$(CONFIG_TARGET_ROOTFS_DIR)),$(call qstrip,$(CONFIG_TARGET_ROOTFS_DIR)),$(BUILD_DIR)) TARGET_DIR:=$(TARGET_ROOTFS_DIR)/root-$(BOARD) STAGING_DIR_ROOT:=$(STAGING_DIR)/root-$(BOARD) STAGING_DIR_IMAGE:=$(STAGING_DIR)/image BUILD_LOG_DIR:=$(if $(call qstrip,$(CONFIG_BUILD_LOG_DIR)),$(call qstrip,$(CONFIG_BUILD_LOG_DIR)),$(TOPDIR)/logs) PKG_INFO_DIR := $(STAGING_DIR)/pkginfo BUILD_DIR_HOST:=$(if $(IS_PACKAGE_BUILD),$(BUILD_DIR_BASE)/hostpkg,$(BUILD_DIR_BASE)/host) STAGING_DIR_HOST:=$(TOPDIR)/staging_dir/host STAGING_DIR_HOSTPKG:=$(TOPDIR)/staging_dir/hostpkg TARGET_PATH:=$(subst $(space),:,$(filter-out .,$(filter-out ./,$(subst :,$(space),$(PATH))))) TARGET_INIT_PATH:=$(call qstrip,$(CONFIG_TARGET_INIT_PATH)) TARGET_INIT_PATH:=$(if $(TARGET_INIT_PATH),$(TARGET_INIT_PATH),/usr/sbin:/sbin:/usr/bin:/bin) TARGET_CFLAGS:=$(TARGET_OPTIMIZATION)$(if $(CONFIG_DEBUG), -g3) $(call qstrip,$(CONFIG_EXTRA_OPTIMIZATION)) TARGET_CXXFLAGS = $(TARGET_CFLAGS) TARGET_ASFLAGS_DEFAULT = $(TARGET_CFLAGS) TARGET_ASFLAGS = $(TARGET_ASFLAGS_DEFAULT) ifneq ($(CONFIG_EXTERNAL_TOOLCHAIN),) LIBGCC_S_PATH=$(realpath $(wildcard $(call qstrip,$(CONFIG_LIBGCC_ROOT_DIR))/$(call qstrip,$(CONFIG_LIBGCC_FILE_SPEC)))) LIBGCC_S=$(if $(LIBGCC_S_PATH),-L$(dir $(LIBGCC_S_PATH)) -lgcc_s) LIBGCC_A=$(realpath $(lastword $(wildcard $(dir $(LIBGCC_S_PATH))/gcc/*/*/libgcc.a))) else LIBGCC_A=$(lastword $(wildcard $(TOOLCHAIN_DIR)/lib/gcc/*/*/libgcc.a)) LIBGCC_S=$(if $(wildcard $(TOOLCHAIN_DIR)/lib/libgcc_s.so),-L$(TOOLCHAIN_DIR)/lib -lgcc_s,$(LIBGCC_A)) endif ifeq ($(CONFIG_ARCH_64BIT),y) LIB_SUFFIX:=64 endif ifndef DUMP ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),) -include $(TOOLCHAIN_DIR)/info.mk export GCC_HONOUR_COPTS:=0 TARGET_CROSS:=$(if $(TARGET_CROSS),$(TARGET_CROSS),$(OPTIMIZE_FOR_CPU)-openwrt-linux$(if $(TARGET_SUFFIX),-$(TARGET_SUFFIX))-) TARGET_CFLAGS+= -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result TARGET_CPPFLAGS+= -I$(TOOLCHAIN_DIR)/usr/include ifeq ($(CONFIG_USE_MUSL),y) TARGET_CPPFLAGS+= -I$(TOOLCHAIN_DIR)/include/fortify endif TARGET_CPPFLAGS+= -I$(TOOLCHAIN_DIR)/include TARGET_LDFLAGS+= -L$(TOOLCHAIN_DIR)/usr/lib -L$(TOOLCHAIN_DIR)/lib TARGET_PATH:=$(TOOLCHAIN_DIR)/bin:$(TARGET_PATH) else ifeq ($(CONFIG_NATIVE_TOOLCHAIN),) TARGET_CROSS:=$(call qstrip,$(CONFIG_TOOLCHAIN_PREFIX)) TOOLCHAIN_ROOT_DIR:=$(call qstrip,$(CONFIG_TOOLCHAIN_ROOT)) TOOLCHAIN_BIN_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_BIN_PATH))) TOOLCHAIN_INC_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_INC_PATH))) TOOLCHAIN_LIB_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_LIB_PATH))) ifneq ($(TOOLCHAIN_BIN_DIRS),) TARGET_PATH:=$(subst $(space),:,$(TOOLCHAIN_BIN_DIRS)):$(TARGET_PATH) endif ifneq ($(TOOLCHAIN_INC_DIRS),) TARGET_CPPFLAGS+= $(patsubst %,-I%,$(TOOLCHAIN_INC_DIRS)) endif ifneq ($(TOOLCHAIN_LIB_DIRS),) TARGET_LDFLAGS+= $(patsubst %,-L%,$(TOOLCHAIN_LIB_DIRS)) endif TARGET_PATH:=$(TOOLCHAIN_DIR)/bin:$(TARGET_PATH) endif endif endif TARGET_PATH_PKG:=$(STAGING_DIR)/host/bin:$(STAGING_DIR_HOSTPKG)/bin:$(TARGET_PATH) ifeq ($(CONFIG_SOFT_FLOAT),y) SOFT_FLOAT_CONFIG_OPTION:=--with-float=soft ifeq ($(CONFIG_arm),y) TARGET_CFLAGS+= -mfloat-abi=soft else TARGET_CFLAGS+= -msoft-float endif else SOFT_FLOAT_CONFIG_OPTION:= ifeq ($(CONFIG_arm),y) TARGET_CFLAGS+= -mfloat-abi=hard endif endif export PATH:=$(TARGET_PATH) export STAGING_DIR STAGING_DIR_HOST STAGING_DIR_HOSTPKG export SH_FUNC:=. $(INCLUDE_DIR)/shell.sh; PKG_CONFIG:=$(STAGING_DIR_HOST)/bin/pkg-config export PKG_CONFIG HOSTCC:=gcc HOSTCXX:=g++ HOST_CPPFLAGS:=-I$(STAGING_DIR_HOST)/include $(if $(IS_PACKAGE_BUILD),-I$(STAGING_DIR_HOSTPKG)/include -I$(STAGING_DIR)/host/include) HOST_CFLAGS:=-O2 $(HOST_CPPFLAGS) HOST_LDFLAGS:=-L$(STAGING_DIR_HOST)/lib $(if $(IS_PACKAGE_BUILD),-L$(STAGING_DIR_HOSTPKG)/lib -L$(STAGING_DIR)/host/lib) ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),) TARGET_AR:=$(TARGET_CROSS)gcc-ar TARGET_RANLIB:=$(TARGET_CROSS)gcc-ranlib TARGET_NM:=$(TARGET_CROSS)gcc-nm else TARGET_AR:=$(TARGET_CROSS)ar TARGET_RANLIB:=$(TARGET_CROSS)ranlib TARGET_NM:=$(TARGET_CROSS)nm endif BUILD_KEY=$(TOPDIR)/key-build FAKEROOT:=$(STAGING_DIR_HOST)/bin/fakeroot TARGET_CC:=$(TARGET_CROSS)gcc TARGET_CXX:=$(TARGET_CROSS)g++ KPATCH:=$(SCRIPT_DIR)/patch-kernel.sh SED:=$(STAGING_DIR_HOST)/bin/sed -i -e ESED:=$(STAGING_DIR_HOST)/bin/sed -E -i -e MKHASH:=$(STAGING_DIR_HOST)/bin/mkhash # MKHASH is used in /scripts, so we export it here. export MKHASH CP:=cp -fpR LN:=ln -sf XARGS:=xargs -r BASH:=bash TAR:=tar FIND:=find PATCH:=patch PYTHON:=python INSTALL_BIN:=install -m0755 INSTALL_SUID:=install -m4755 INSTALL_DIR:=install -d -m0755 INSTALL_DATA:=install -m0644 INSTALL_CONF:=install -m0600 TARGET_CC_NOCACHE:=$(TARGET_CC) TARGET_CXX_NOCACHE:=$(TARGET_CXX) HOSTCC_NOCACHE:=$(HOSTCC) HOSTCXX_NOCACHE:=$(HOSTCXX) export TARGET_CC_NOCACHE export TARGET_CXX_NOCACHE export HOSTCC_NOCACHE export HOSTCXX_NOCACHE ifneq ($(CONFIG_CCACHE),) TARGET_CC:= ccache_cc TARGET_CXX:= ccache_cxx HOSTCC:= ccache $(HOSTCC) HOSTCXX:= ccache $(HOSTCXX) export CCACHE_BASEDIR:=$(TOPDIR) export CCACHE_DIR:=$(if $(call qstrip,$(CONFIG_CCACHE_DIR)),$(call qstrip,$(CONFIG_CCACHE_DIR)),$(TOPDIR)/.ccache) export CCACHE_COMPILERCHECK:=%compiler% -dumpmachine; %compiler% -dumpversion endif TARGET_CONFIGURE_OPTS = \ AR="$(TARGET_AR)" \ AS="$(TARGET_CC) -c $(TARGET_ASFLAGS)" \ LD=$(TARGET_CROSS)ld \ NM="$(TARGET_NM)" \ CC="$(TARGET_CC)" \ GCC="$(TARGET_CC)" \ CXX="$(TARGET_CXX)" \ RANLIB="$(TARGET_RANLIB)" \ STRIP=$(TARGET_CROSS)strip \ OBJCOPY=$(TARGET_CROSS)objcopy \ OBJDUMP=$(TARGET_CROSS)objdump \ SIZE=$(TARGET_CROSS)size # strip an entire directory ifneq ($(CONFIG_NO_STRIP),) RSTRIP:=: STRIP:=: else ifneq ($(CONFIG_USE_STRIP),) STRIP:=$(TARGET_CROSS)strip $(call qstrip,$(CONFIG_STRIP_ARGS)) else ifneq ($(CONFIG_USE_SSTRIP),) STRIP:=$(STAGING_DIR_HOST)/bin/sstrip $(call qstrip,$(CONFIG_SSTRIP_ARGS)) endif endif RSTRIP= \ export CROSS="$(TARGET_CROSS)" \ $(if $(PKG_BUILD_ID),KEEP_BUILD_ID=1) \ $(if $(CONFIG_KERNEL_KALLSYMS),NO_RENAME=1) \ $(if $(CONFIG_KERNEL_PROFILING),KEEP_SYMBOLS=1); \ NM="$(TARGET_CROSS)nm" \ STRIP="$(STRIP)" \ STRIP_KMOD="$(SCRIPT_DIR)/strip-kmod.sh" \ PATCHELF="$(STAGING_DIR_HOST)/bin/patchelf" \ $(SCRIPT_DIR)/rstrip.sh endif NINJA = \ MAKEFLAGS="$(MAKE_JOBSERVER)" \ $(STAGING_DIR_HOST)/bin/ninja \ $(if $(findstring c,$(OPENWRT_VERBOSE)),-v) \ $(if $(MAKE_JOBSERVER),,-j1) ifeq ($(CONFIG_IPV6),y) DISABLE_IPV6:= else DISABLE_IPV6:=--disable-ipv6 endif TAR_OPTIONS:=-xf - ifeq ($(CONFIG_BUILD_LOG),y) BUILD_LOG:=1 endif export BISON_PKGDATADIR:=$(STAGING_DIR_HOST)/share/bison export M4:=$(STAGING_DIR_HOST)/bin/m4 define shvar V_$(subst .,_,$(subst -,_,$(subst /,_,$(1)))) endef define shexport export $(call shvar,$(1))=$$(call $(1)) endef # Execute commands under flock # $(1) => The shell expression. # $(2) => The lock name. If not given, the global lock will be used. ifneq ($(wildcard $(STAGING_DIR_HOST)/bin/flock),) define locked SHELL= \ flock \ $(TMP_DIR)/.$(if $(2),$(strip $(2)),global).flock \ -c '$(subst ','\'',$(1))' endef else locked=$(1) endif # Recursively copy paths into another directory, purge dangling # symlinks before. # $(1) => File glob expression # $(2) => Destination directory define file_copy for src_dir in $(sort $(foreach d,$(wildcard $(1)),$(dir $(d)))); do \ ( cd $$src_dir; find -type f -or -type d ) | \ ( cd $(2); while :; do \ read FILE; \ [ -z "$$FILE" ] && break; \ [ -L "$$FILE" ] || continue; \ echo "Removing symlink $(2)/$$FILE"; \ rm -f "$$FILE"; \ done; ); \ done; \ $(CP) $(1) $(2) endef # Calculate sha256sum of any plain file within a given directory # $(1) => Input directory # $(2) => If set, recurse into subdirectories define sha256sums (cd $(1); find . $(if $(2),,-maxdepth 1) -type f -not -name 'sha256sums' -printf "%P\n" | sort | \ xargs -r $(MKHASH) -n sha256 | sed -ne 's!^\(.*\) \(.*\)$$!\1 *\2!p' > sha256sums) endef # file extension ext=$(word $(words $(subst ., ,$(1))),$(subst ., ,$(1))) # Count Git commits of a package # $(1) => if non-empty: count commits since last ": [uU]pdate to " or ": [bB]ump to " in commit message define commitcount $(shell \ if git log -1 >/dev/null 2>/dev/null; then \ if [ -n "$(1)" ]; then \ last_bump="$$(git log --pretty=format:'%h %s' . | \ grep --max-count=1 -e ': [uU]pdate to ' -e ': [bB]ump to ' | \ cut -f 1 -d ' ')"; \ fi; \ if [ -n "$$last_bump" ]; then \ echo -n $$(($$(git rev-list --count "$$last_bump..HEAD" .) + 1)); \ else \ git rev-list --count HEAD .; \ fi; \ else \ secs="$$(($(SOURCE_DATE_EPOCH) % 86400))"; \ date="$$(date --utc --date="@$(SOURCE_DATE_EPOCH)" "+%y%m%d")"; \ printf '%s.%05d' "$$date" "$$secs"; \ fi; \ ) endef abi_version_str = $(subst -,,$(subst _,,$(subst .,,$(1)))) COMMITCOUNT = $(if $(DUMP),0,$(call commitcount)) AUTORELEASE = $(if $(DUMP),0,$(call commitcount,1)) all: FORCE: ; .PHONY: FORCE check: FORCE @true val.%: @$(if $(filter undefined,$(origin $*)),\ echo "$* undefined" >&2, \ echo '$(subst ','"'"',$($*))' \ ) var.%: @$(if $(filter undefined,$(origin $*)),\ echo "$* undefined" >&2, \ echo "$*='"'$(subst ','"'\"'\"'"',$($*))'"'" \ ) endif #__rules_inc