162306a36Sopenharmony_ci#!/bin/sh
262306a36Sopenharmony_ci# SPDX-License-Identifier: LGPL-2.1
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci# This one uses a copy from the kernel sources headers that is in a
562306a36Sopenharmony_ci# place used just for these tools/perf/beauty/ usage, we shouldn't not
662306a36Sopenharmony_ci# put it in tools/include/linux otherwise they would be used in the
762306a36Sopenharmony_ci# normal compiler building process and would drag needless stuff from the
862306a36Sopenharmony_ci# kernel.
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci# When what these scripts need is already in tools/include/ then use it,
1162306a36Sopenharmony_ci# otherwise grab and check the copy from the kernel sources just for these
1262306a36Sopenharmony_ci# string table building scripts.
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci[ $# -eq 1 ] && header_dir=$1 || header_dir=tools/perf/trace/beauty/include/linux/
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ciprintf "static const char *socket_families[] = {\n"
1762306a36Sopenharmony_ci# #define AF_LOCAL	1	/* POSIX name for AF_UNIX	*/
1862306a36Sopenharmony_ciregex='^#define[[:space:]]+AF_(\w+)[[:space:]]+([[:digit:]]+).*'
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_cigrep -E $regex ${header_dir}/socket.h | \
2162306a36Sopenharmony_ci	sed -r "s/$regex/\2 \1/g"	| \
2262306a36Sopenharmony_ci	xargs printf "\t[%s] = \"%s\",\n" | \
2362306a36Sopenharmony_ci	grep -E -v "\"(UNIX|MAX)\""
2462306a36Sopenharmony_ciprintf "};\n"
25