xref: /OK3568_Linux_fs/kernel/tools/perf/trace/beauty/socket.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/bin/sh
2*4882a593Smuzhiyun# SPDX-License-Identifier: LGPL-2.1
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun# This one uses a copy from the kernel sources headers that is in a
5*4882a593Smuzhiyun# place used just for these tools/perf/beauty/ usage, we shouldn't not
6*4882a593Smuzhiyun# put it in tools/include/linux otherwise they would be used in the
7*4882a593Smuzhiyun# normal compiler building process and would drag needless stuff from the
8*4882a593Smuzhiyun# kernel.
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun# When what these scripts need is already in tools/include/ then use it,
11*4882a593Smuzhiyun# otherwise grab and check the copy from the kernel sources just for these
12*4882a593Smuzhiyun# string table building scripts.
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun[ $# -eq 1 ] && header_dir=$1 || header_dir=tools/perf/trace/beauty/include/linux/
15*4882a593Smuzhiyun
16*4882a593Smuzhiyunprintf "static const char *socket_families[] = {\n"
17*4882a593Smuzhiyun# #define AF_LOCAL	1	/* POSIX name for AF_UNIX	*/
18*4882a593Smuzhiyunregex='^#define[[:space:]]+AF_(\w+)[[:space:]]+([[:digit:]]+).*'
19*4882a593Smuzhiyun
20*4882a593Smuzhiyunegrep $regex ${header_dir}/socket.h | \
21*4882a593Smuzhiyun	sed -r "s/$regex/\2 \1/g"	| \
22*4882a593Smuzhiyun	xargs printf "\t[%s] = \"%s\",\n" | \
23*4882a593Smuzhiyun	egrep -v "\"(UNIX|MAX)\""
24*4882a593Smuzhiyunprintf "};\n"
25