summaryrefslogtreecommitdiffstats
path: root/linux/signals.mk
blob: 4bb881214ce30dcd935b0a9ee6a06b8fe305fd6a (plain) (blame)
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
# See LICENSE file for copyright and license details.

libsyscalls_get_signals.o: generated/linux-signals.h linux/signals.c
libsyscalls_get_signals.lo: generated/linux-signals.h linux/signals.c

generated/linux-signals.tbl: $(LINUX_SOURCE) linux/signals.mk
	mkdir -p -- generated
	set -e; ( \
	get_gcc_or_clang () { \
		( \
			( \
				IFS=:; \
				for dir in $$PATH; do \
					if test ! -d "$$dir"; then continue; fi; \
					for file in "$$dir"/*; do \
						if test ! -x "$$file"; then continue; fi; \
						printf '%s\n' "$$file"; \
					done \
				done \
			) | grep '/\(gcc\|clang\)\(-[0-9.]\{1,\}\)\{0,1\}$$'; \
			printf '%s\n' gcc; \
		) | sed 1q; \
	}; \
	if test -n "$(CC_DEF_EXTRACT)"; then \
		c="$(CC_DEF_EXTRACT)"; \
	else \
		c="$(CC)"; \
	fi; \
	c="$$($$c --version 2>&1 | sed 1q | sed 's/^.*(\(.*\)).*$$/\1/' | tr '[A-Z]' '[a-z]' | cut -d ' ' -f 1)"; \
	if test ! "$$c" = gcc && test ! "$$c" = clang; then \
		c="$$(get_gcc_or_clang)"; \
	fi; \
	extract="$$c -E -dM -D__KERNEL__"; \
	srcdir="linux-src/linux-$(LINUX_VERSION)"; \
	mkdir -p -- "$$srcdir/tools/include/generated/"; \
	touch -- "$$srcdir/tools/include/generated/bounds.h"; \
	touch -- "$$srcdir/tools/include/generated/timeconst.h"; \
	process_arch () \
	{ \
		set -e; \
		signals="$$( \
			$$extract "-I$$srcdir/tools/include" $$fixes "$$2" \
			| sed -n 's/^$(s)*$(h)$(s)*define$(s)\{1,\}\(SIG[^[:space:]]\{1,\}\)$(s)\{1,\}\([0-9]\{1,\}\)$(s)*\(\/.*\)\{0,1\}$$/'"$$1"' \2 \1/p' \
			| grep -v ' SIG_' \
			| grep -v ' SIGSTKSZ' \
			| sort -k 2 -nu; \
		)"; \
		if test "$$1" = arm; then \
			signals="$$(printf "%s\n" "$$signals" | sed 's/\(^\|[^A-Z0-9a-z_]\)SIGSWI\([^A-Z0-9a-z_]\|$$\)/\1SIGRTMIN\2/')"; \
		fi; \
		printf "%s\n" "$$signals"; \
		sigrtmin="$$(printf "%s\n" "$$signals" | sed -n 's/^.* \([0-9]\{1,\}\) SIGRTMIN$$/\1/p')"; \
		maxnamed="$$(printf "%s\n" "$$signals" | sed -n '$$s/^.* \([0-9]\{1,\}\) .*$$/\1/p')"; \
		test "$$sigrtmin" = "$$maxnamed"; \
		maxsig=_NSIG; \
		depth=0; \
		while test -n "$$maxsig" && test -n "$$(printf '%s\n' "$$maxsig" | tr -d '[0-9]')" ; do \
			printf '%s: looking for %s\n' "$$1" "$$maxsig" >&2; \
			def="$$maxsig"; \
			maxsig="$$($$extract "-I$$srcdir/tools/include" $$fixes "$$2" \
			           | sed -n 's/^$(s)*$(h)$(s)*define$(s)\{1,\}'"$$def"'$(s)\{1,\}\([A-Z0-9_]\{1,\}\)$(s)*\(\/.*\)\{0,1\}$$/\1/p')"; \
			if test -z "$$maxsig"; then \
				maxsig="$$($$extract "-I$$srcdir/tools/include" \
					             "-I$$srcdir/arch/$$1/include" \
					             "-I$$srcdir/include" \
					             "-I$$srcdir" \
				                     $$fixes \
					             "$$(printf '%s\n' "$$2" | sed 's:/uapi/:/:')" \
				           | sed -n 's/^$(s)*$(h)$(s)*define$(s)\{1,\}'"$$def"'$(s)\{1,\}\([A-Z0-9_]\{1,\}\)$(s)*\(\/.*\)\{0,1\}$$/\1/p')"; \
			fi; \
			printf '%s: found %s\n' "$$1" "$$maxsig" >&2; \
			: $$(( depth++ )); \
			test $$(( depth )) -lt 1000; \
		done; \
		test -n "$$maxsig"; \
		i=1; \
		while (( sigrtmin + i <= maxsig )); do \
			printf '%s %d SIGRTMIN+%d\n' "$$1" $$(( sigrtmin + i )) $$i; \
			: $$(( i++ )); \
		done; \
	}; \
	getsigs () { \
		process_arch "$$@" | sed 's/\(^\|[^A-Z0-9a-z_]\)\(SIGRTMIN\)\([^A-Z0-9a-z_]\|$$\)/\1_\2\3/'; \
	}; \
	for arch in $$(printf '%s\n' "$$srcdir/arch"/*/ | sed 's:^.*/\([^/]*\)/$$:\1:'); do \
		if test ! "$$arch" = s390 && test -f "$$srcdir/arch/$$arch/include/uapi/asm/signal.h"; then \
			getsigs "$$arch" "$$srcdir/arch/$$arch/include/uapi/asm/signal.h"; \
		fi; \
	done; \
	getsigs generic "$$srcdir/include/uapi/asm-generic/signal.h"; \
	) > $@
	@printf '\033[1;32m%s\033[m\n' \
		'Compiler warnings above are not of interest, they were generated during' \
		'extraction of the Linux source code and are not part of this library'
	@grep '^generic.*SIGRTMIN+.*' >/dev/null 2>/dev/null < $@
	grep '^generic ' < $@ | cut -d ' ' -f 2 > generated/linux-signals.generic.tbl
	@# For most architectures the signal numbers are the same,
	@# yet they have their own signal.h listing them, so to remove
	@# duplication in the library, we removing duplicates after
	@# validating that they have not diverged
	grep '^arm ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl -
	sed '/^arm /d' < $@ > $@.tmp && mv -- $@.tmp $@
	grep '^arm64 ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl -
	sed '/^arm64 /d' < $@ > $@.tmp && mv -- $@.tmp $@
	grep '^hexagon ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl -
	sed '/^hexagon /d' < $@ > $@.tmp && mv -- $@.tmp $@
	grep '^loongarch ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl -
	sed '/^loongarch /d' < $@ > $@.tmp && mv -- $@.tmp $@
	grep '^arc ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl -
	sed '/^arc /d' < $@ > $@.tmp && mv -- $@.tmp $@
	grep '^nios2 ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl -
	sed '/^nios2 /d' < $@ > $@.tmp && mv -- $@.tmp $@
	grep '^ia64 ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl -
	sed '/^ia64 /d' < $@ > $@.tmp && mv -- $@.tmp $@
	grep '^m68k ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl -
	sed '/^m68k /d' < $@ > $@.tmp && mv -- $@.tmp $@
	grep '^powerpc ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl -
	sed '/^powerpc /d' < $@ > $@.tmp && mv -- $@.tmp $@
	grep '^sh ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl -
	sed '/^sh /d' < $@ > $@.tmp && mv -- $@.tmp $@
	grep '^x86 ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl -
	sed '/^x86 /d' < $@ > $@.tmp && mv -- $@.tmp $@
	grep '^xtensa ' < $@ | cut -d ' ' -f 2 | diff -u generated/linux-signals.generic.tbl -
	sed '/^xtensa /d' < $@ > $@.tmp && mv -- $@.tmp $@
	rm -f -- generated/linux-signals.*.tbl

generated/linux-signals.h: generated/linux-signals.tbl linux/signals.mk
	set -e; \
	for arch in $$(cut -d ' ' -f 1 < generated/linux-signals.tbl | uniq); do \
		ARCH="$$(printf '%s\n' "$$arch" | tr '[a-z]' '[A-Z]')"; \
		printf '#define LIST_LINUX_SIGNALS_FOR_%s(X, D)\\\n' "$$ARCH"; \
		sed -n 's/^'"$$arch"' \([0-9]\{1,\}\) \(.*\)$$/\tX(\1, "\2") D\\/p' \
		< generated/linux-signals.tbl \
		| sed '$$s/ D\\//'; \
		printf 'static struct libsyscalls_named_number linux_signals_for_%s[] = {\n' "$$arch"; \
		printf '#define X(NR, NAME) {.number.s = NR, .name = NAME}\n'; \
		printf '\tLIST_LINUX_SIGNALS_FOR_%s(X, COMMA)\n' "$$ARCH"; \
		printf '#undef X\n'; \
		printf '};\n'; \
	done > $@