From 3ef25acf3600fb822bdf1487036184b4978d737f Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Sun, 28 Dec 2025 16:04:28 +0200 Subject: [PATCH] Add a script to auto-generate mapping from exterr category to source file Reviewed by: emaste, mkusick Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54380 --- tools/build/make_libc_exterr_cat_filenames.sh | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 tools/build/make_libc_exterr_cat_filenames.sh diff --git a/tools/build/make_libc_exterr_cat_filenames.sh b/tools/build/make_libc_exterr_cat_filenames.sh new file mode 100755 index 00000000000..fbde8589120 --- /dev/null +++ b/tools/build/make_libc_exterr_cat_filenames.sh @@ -0,0 +1,22 @@ +#!/bin/sh +set -e + +check="lib/libc/gen/uexterr_format.c" +target="lib/libc/gen/exterr_cat_filenames.h" + +if [ \! -f "${check}" ] ; then + echo "Script must be run from the top of the full source tree" + exit 1 +fi + +echo "/*" >"${target}" +printf " * Automatically %sgenerated, use\\n" \@ >>"${target}" +echo " * tools/build/make_libc_exterr_cat_filenames.sh" >>"${target}" +echo " */" >>"${target}" + +(find sys -type f -name '*.c' | \ + xargs grep -E '^#define[[:space:]]+EXTERR_CATEGORY[[:space:]]+EXTERR_CAT_' | \ + sed -E 's/[[:space:]]+/:/g' | \ + awk -F ':' '{filename = $1; sub(/^sys\//, "", filename); + printf("\t[%s] = \"%s\",\n", $4, filename)}') \ + >>"${target}"