diff options
author | Mattias Andrée <maandree@kth.se> | 2023-12-03 19:23:35 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-12-03 19:23:35 +0100 |
commit | c131f122778c62f920a99bbf854ced4a37ee8b03 (patch) | |
tree | 14c933f98f4d64dffb0a594bc40dd5121c6c5a8e /linux/errors.mk | |
download | libsyscalls-c131f122778c62f920a99bbf854ced4a37ee8b03.tar.gz libsyscalls-c131f122778c62f920a99bbf854ced4a37ee8b03.tar.bz2 libsyscalls-c131f122778c62f920a99bbf854ced4a37ee8b03.tar.xz |
First commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | linux/errors.mk | 52 |
1 files changed, 52 insertions, 0 deletions
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 > $@ |