summaryrefslogtreecommitdiff
path: root/build-aux/extract-odp-netlink-macros-h
blob: 7152f298c136553300276b08f4a402f2cbeb7cba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh

hfile=$1

generate_fields_macros () {
    local struct_name=$1
    local line_start
    local num_lines
    local line_end
    local awk_cmd
    local STRUCT

    # line_start is the line number where the definition of the struct begin
    # line_end is the line number where the definition of the struct ends
    line_start=`grep -nw $struct_name $hfile | grep { | cut -d ":" -f1`
    num_lines=`tail -n +${line_start} $hfile | grep -n -m1 } | cut -d ":" -f1`
    line_end=$((line_start+num_lines-1))


    STRUCT=`echo $struct_name | tr [a-z] [A-Z]`
    echo "#define ${STRUCT}_OFFSETOF_SIZEOF_ARR { \\"
    # for all the field lines, including the terminating }, remove ";" and
    # replace with an item of {offsetof, sizeof}.
    # 3 awk fields are for type struct <struct name> and field <field_name>
    # 2 awk fields are for type <type> and field <field_name>
    # else - terminating the array by item {0, 0}
    awk_cmd="'{"
    awk_cmd=$awk_cmd'    if (NF == 3)'
    awk_cmd=$awk_cmd'        print "    {offsetof(struct '"${struct_name}"', "$3"), sizeof("$1,$2")}, \\";'
    awk_cmd=$awk_cmd'    else if (NF == 2)'
    awk_cmd=$awk_cmd'        print "    {offsetof(struct '"${struct_name}"', "$2"), sizeof("   $1")}, \\";'
    awk_cmd=$awk_cmd'    else'
    awk_cmd=$awk_cmd'        print "    {0, 0}}";'
    awk_cmd=$awk_cmd"}'"
    awk -F ";" "NR>${line_start} && NR<=${line_end}"' {print $1}' $hfile | eval "awk $awk_cmd"

    echo
    echo
}

echo "/* Generated automatically from <include/odp-netlink.h> -- do not modify! */"
echo "#ifndef ODP_NETLINK_MACROS_H"
echo "#define ODP_NETLINK_MACROS_H"
echo
echo

generate_fields_macros "ovs_key_ethernet"
generate_fields_macros "ovs_key_ipv4"
generate_fields_macros "ovs_key_ipv6"
generate_fields_macros "ovs_key_tcp"
generate_fields_macros "ovs_key_udp"
generate_fields_macros "ovs_key_sctp"
generate_fields_macros "ovs_key_icmp"
generate_fields_macros "ovs_key_icmpv6"
generate_fields_macros "ovs_key_arp"
generate_fields_macros "ovs_key_nd"
generate_fields_macros "ovs_key_nd_extensions"

echo
echo "#endif"