From c131f122778c62f920a99bbf854ced4a37ee8b03 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 3 Dec 2023 19:23:35 +0100 Subject: First commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- linux/errors.mk | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 linux/errors.mk (limited to 'linux/errors.mk') diff --git a/linux/errors.mk b/linux/errors.mk new file mode 100644 index 0000000..b6b7197 --- /dev/null +++ b/linux/errors.mk @@ -0,0 +1,52 @@ +libsyscalls_get_syscall_errors.o: generated/linux-errors.h linux/errors.c +libsyscalls_get_syscall_errors.lo: generated/linux-errors.h linux/errors.c + +generated/linux-errors.tbl: $(LINUX_SOURCE) linux/errors.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.]\+\)\?$$'; \ + printf '%s\n' gcc; \ + ) | sed 1q; \ + }; \ + extract="$$(get_gcc_or_clang) -E -dM"; \ + toolsdir="linux-src/linux-$(LINUX_VERSION)/tools"; \ + process_arch() \ + { \ + ($$extract "-I$$toolsdir/include/uapi" "$$2" && \ + cat -- "linux-src/linux-$(LINUX_VERSION)/include/linux/errno.h") \ + | sed -n 's/^\s*\x23\s*define\s\+\(E[^\s]\+\)\s\+\([0-9]\+\)\s*\(\/.*\)\?$$/'"$$1"' \2 \1/p' \ + | sort -k 2 -nu; \ + }; \ + for arch in $$(printf '%s\n' "$$toolsdir/arch"/*/ | sed 's:^.*/\([^/]*\)/$$:\1:'); do \ + if test -f "$$toolsdir/arch/$$arch/include/uapi/asm/errno.h"; then \ + process_arch "$$arch" "$$toolsdir/arch/$$arch/include/uapi/asm/errno.h"; \ + fi; \ + done; \ + process_arch generic "$$toolsdir/include/uapi/asm-generic/errno.h"; \ + ) > $@ + +generated/linux-errors.h: generated/linux-errors.tbl linux/errors.mk + set -e; \ + for arch in $$(cut -d ' ' -f 1 < generated/linux-errors.tbl | uniq); do \ + ARCH="$$(printf '%s\n' "$$arch" | tr '[a-z]' '[A-Z]')"; \ + printf '#define LIST_LINUX_ERRORS_FOR_%s(X, D)\\\n' "$$ARCH"; \ + sed -n 's/^'"$$arch"' \([0-9]\+\) \(.*\)$$/\tX(\1, "\2") D\\/p' \ + < generated/linux-errors.tbl \ + | sed '$$s/ D\\//'; \ + printf 'static struct libsyscalls_named_number linux_errors_for_%s[] = {\n' "$$arch"; \ + printf '#define X(NR, NAME) {.number.s = NR, .name = NAME}\n'; \ + printf '\tLIST_LINUX_ERRORS_FOR_%s(X, COMMA)\n' "$$ARCH"; \ + printf '#undef X\n'; \ + printf '};\n'; \ + done > $@ -- cgit v1.2.3-70-g09d2