]> granicus.if.org Git - strace/blob - mpers.sh
Remove linux/ptp_clock.h
[strace] / mpers.sh
1 #!/bin/sh -e
2 #
3 # Copyright (c) 2015 Elvira Khabirova <lineprinter0@gmail.com>
4 # Copyright (c) 2015-2017 The strace developers.
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 #    notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 #    notice, this list of conditions and the following disclaimer in the
14 #    documentation and/or other materials provided with the distribution.
15 # 3. The name of the author may not be used to endorse or promote products
16 #    derived from this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 export LC_ALL=C
30
31 MPERS_AWK="${0%/*}/mpers.awk"
32 ARCH_FLAG=$1
33 PARSER_FILE=$2
34
35 READELF="${READELF:-readelf}"
36 CC="${CC-gcc}"
37 CFLAGS="$CFLAGS -gdwarf-2 -c"
38 CPP="${CPP-$CC -E}"
39 CPPFLAGS="$CPPFLAGS -MM -MG"
40
41 VAR_NAME='mpers_target_var'
42 BITS_DIR="mpers${ARCH_FLAG}"
43
44 mkdir -p ${BITS_DIR}
45 set -- $(sed -r -n \
46         's/^#[[:space:]]*include[[:space:]]+DEF_MPERS_TYPE\(([^)[:space:]]*)\)$/\1/p' \
47                 "${PARSER_FILE}")
48 for m_type; do
49         f_h="${BITS_DIR}/${m_type}.h"
50         f_c="${BITS_DIR}/${m_type}.c"
51         f_i="${BITS_DIR}/${m_type}.i"
52         f_o="${BITS_DIR}/${m_type}.o"
53         f_d1="${BITS_DIR}/${m_type}.d1"
54         f_d2="${BITS_DIR}/${m_type}.d2"
55         sed -e '
56                 /DEF_MPERS_TYPE('"${m_type}"')$/n
57                 /DEF_MPERS_TYPE/d
58                 /^[[:space:]]*#[[:space:]]*include[[:space:]]*"xlat\//d
59                 /^#[[:space:]]*include[[:space:]][[:space:]]*MPERS_DEFS$/ {s//'"${m_type} ${VAR_NAME}"';/;q}
60                 ' "${PARSER_FILE}" > "${f_c}"
61         $CPP $CPPFLAGS "${f_c}" > "${f_i}"
62         grep -F -q "${m_type}.h" "${f_i}" ||
63                 continue
64         sed -i -e '/DEF_MPERS_TYPE/d' "${f_c}"
65         $CC $CFLAGS $ARCH_FLAG "${f_c}" -o "${f_o}"
66         $READELF --debug-dump=info "${f_o}" > "${f_d1}"
67         sed -r -n '
68                 /^[[:space:]]*<1>/,/^[[:space:]]*<1><[^>]+>: Abbrev Number: 0/!d
69                 /^[[:space:]]*<[^>]*><[^>]*>: Abbrev Number: 0/d
70                 s/^[[:space:]]*<[[:xdigit:]]+>[[:space:]]+//
71                 s/^[[:space:]]*((<[[:xdigit:]]+>){2}):[[:space:]]+/\1\n/
72                 s/[[:space:]]+$//
73                 p' "${f_d1}" > "${f_d2}"
74         gawk -v VAR_NAME="$VAR_NAME" -v ARCH_FLAG="${ARCH_FLAG#-}" \
75                 -f "$MPERS_AWK" "${f_d2}" > "${f_h}"
76 done