blob: f01f6c98a9f7adde7508288a46a052eb0d29f666 [file] [log] [blame]
Elvira Khabirova09294222015-08-04 01:47:02 +03001#!/bin/sh -e
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00002#
3# Copyright (c) 2015 Elvira Khabirova <lineprinter0@gmail.com>
Elliott Hughesb7556142018-02-20 17:03:16 -08004# Copyright (c) 2015-2018 The strace developers.
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00005# 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.
Elvira Khabirova09294222015-08-04 01:47:02 +030028
29export LC_ALL=C
30
31MPERS_AWK="${0%/*}/mpers.awk"
32ARCH_FLAG=$1
Elliott Hughesb7556142018-02-20 17:03:16 -080033CC_ARCH_FLAG=$2
34PARSER_FILE=$3
Elvira Khabirova09294222015-08-04 01:47:02 +030035
Elliott Hughesb7556142018-02-20 17:03:16 -080036READELF="${READELF:-readelf}"
Elvira Khabirova09294222015-08-04 01:47:02 +030037CC="${CC-gcc}"
Dmitry V. Levin4b08afd2015-12-16 01:26:27 +000038CFLAGS="$CFLAGS -gdwarf-2 -c"
Elvira Khabirova09294222015-08-04 01:47:02 +030039CPP="${CPP-$CC -E}"
40CPPFLAGS="$CPPFLAGS -MM -MG"
41
42VAR_NAME='mpers_target_var'
Elliott Hughesb7556142018-02-20 17:03:16 -080043BITS_DIR="mpers-${ARCH_FLAG}"
Elvira Khabirova09294222015-08-04 01:47:02 +030044
45mkdir -p ${BITS_DIR}
Dmitry V. Levin469fd102016-07-28 16:51:58 +000046set -- $(sed -r -n \
47 's/^#[[:space:]]*include[[:space:]]+DEF_MPERS_TYPE\(([^)[:space:]]*)\)$/\1/p' \
Elvira Khabirova09294222015-08-04 01:47:02 +030048 "${PARSER_FILE}")
49for m_type; do
50 f_h="${BITS_DIR}/${m_type}.h"
51 f_c="${BITS_DIR}/${m_type}.c"
52 f_i="${BITS_DIR}/${m_type}.i"
53 f_o="${BITS_DIR}/${m_type}.o"
54 f_d1="${BITS_DIR}/${m_type}.d1"
55 f_d2="${BITS_DIR}/${m_type}.d2"
56 sed -e '
57 /DEF_MPERS_TYPE('"${m_type}"')$/n
58 /DEF_MPERS_TYPE/d
Dmitry V. Levin469fd102016-07-28 16:51:58 +000059 /^[[:space:]]*#[[:space:]]*include[[:space:]]*"xlat\//d
60 /^#[[:space:]]*include[[:space:]][[:space:]]*MPERS_DEFS$/ {s//'"${m_type} ${VAR_NAME}"';/;q}
Elvira Khabirova09294222015-08-04 01:47:02 +030061 ' "${PARSER_FILE}" > "${f_c}"
62 $CPP $CPPFLAGS "${f_c}" > "${f_i}"
63 grep -F -q "${m_type}.h" "${f_i}" ||
64 continue
65 sed -i -e '/DEF_MPERS_TYPE/d' "${f_c}"
Elliott Hughesb7556142018-02-20 17:03:16 -080066 $CC $CFLAGS $CC_ARCH_FLAG "${f_c}" -o "${f_o}"
67 $READELF --debug-dump=info "${f_o}" > "${f_d1}"
Dmitry V. Levin469fd102016-07-28 16:51:58 +000068 sed -r -n '
69 /^[[:space:]]*<1>/,/^[[:space:]]*<1><[^>]+>: Abbrev Number: 0/!d
70 /^[[:space:]]*<[^>]*><[^>]*>: Abbrev Number: 0/d
71 s/^[[:space:]]*<[[:xdigit:]]+>[[:space:]]+//
72 s/^[[:space:]]*((<[[:xdigit:]]+>){2}):[[:space:]]+/\1\n/
73 s/[[:space:]]+$//
Elvira Khabirova09294222015-08-04 01:47:02 +030074 p' "${f_d1}" > "${f_d2}"
Elliott Hughesb7556142018-02-20 17:03:16 -080075 gawk -v VAR_NAME="$VAR_NAME" -v ARCH_FLAG="${ARCH_FLAG}" \
Elvira Khabirova09294222015-08-04 01:47:02 +030076 -f "$MPERS_AWK" "${f_d2}" > "${f_h}"
77done