Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / mbedtls / repo / tests / scripts / list-identifiers.sh
1 #!/bin/bash
2 #
3 # Create a file named identifiers containing identifiers from internal header
4 # files or all header files, based on --internal flag.
5 # Outputs the line count of the file to stdout.
6 #
7 # Usage: list-identifiers.sh [ -i | --internal ]
8
9 set -eu
10
11 if [ -d include/mbedtls ]; then :; else
12     echo "$0: must be run from root" >&2
13     exit 1
14 fi
15
16 INTERNAL=""
17
18 until [ -z "${1-}" ]
19 do
20   case "$1" in
21     -i|--internal)
22       INTERNAL="1"
23       ;;
24     *)
25       # print error
26       echo "Unknown argument: '$1'"
27       exit 1
28       ;;
29   esac
30   shift
31 done
32
33 if [ $INTERNAL ]
34 then
35     HEADERS=$( ls include/mbedtls/*_internal.h | egrep -v 'compat-1\.3\.h|bn_mul' )
36 else
37     HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h|bn_mul' )
38 fi
39
40 rm -f identifiers
41
42 grep '^[^ /#{]' $HEADERS | \
43     sed -e 's/^[^:]*://' | \
44     egrep -v '^(extern "C"|(typedef )?(struct|enum)( {)?$|};?$)' \
45     > _decls
46
47 if true; then
48 sed -n -e 's/.* \**\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p' \
49        -e 's/.*(\*\(.*\))(.*/\1/p' _decls
50 grep -v '(' _decls | sed -e 's/\([a-zA-Z0-9_]*\)[;[].*/\1/' -e 's/.* \**//'
51 fi > _identifiers
52
53 if [ $( wc -l < _identifiers ) -eq $( wc -l < _decls ) ]; then
54     rm _decls
55     egrep -v '^(u?int(16|32|64)_t)$' _identifiers | sort > identifiers
56     rm _identifiers
57 else
58     echo "$0: oops, lost some identifiers" 2>&1
59     exit 1
60 fi
61
62 wc -l identifiers