Elvira Khabirova | 0929422 | 2015-08-04 01:47:02 +0300 | [diff] [blame] | 1 | #!/bin/sh -e |
| 2 | |
| 3 | export LC_ALL=C |
| 4 | |
| 5 | MPERS_AWK="${0%/*}/mpers.awk" |
| 6 | ARCH_FLAG=$1 |
| 7 | PARSER_FILE=$2 |
| 8 | |
| 9 | CC="${CC-gcc}" |
Dmitry V. Levin | 4b08afd | 2015-12-16 01:26:27 +0000 | [diff] [blame^] | 10 | CFLAGS="$CFLAGS -gdwarf-2 -c" |
Elvira Khabirova | 0929422 | 2015-08-04 01:47:02 +0300 | [diff] [blame] | 11 | CPP="${CPP-$CC -E}" |
| 12 | CPPFLAGS="$CPPFLAGS -MM -MG" |
| 13 | |
| 14 | VAR_NAME='mpers_target_var' |
| 15 | BITS_DIR="mpers${ARCH_FLAG}" |
| 16 | |
| 17 | mkdir -p ${BITS_DIR} |
| 18 | set -- $(sed -n \ |
| 19 | 's/^#[[:space:]]*include[[:space:]]\+DEF_MPERS_TYPE(\([^)[:space:]]*\))$/\1/p' \ |
| 20 | "${PARSER_FILE}") |
| 21 | for m_type; do |
| 22 | f_h="${BITS_DIR}/${m_type}.h" |
| 23 | f_c="${BITS_DIR}/${m_type}.c" |
| 24 | f_i="${BITS_DIR}/${m_type}.i" |
| 25 | f_o="${BITS_DIR}/${m_type}.o" |
| 26 | f_d1="${BITS_DIR}/${m_type}.d1" |
| 27 | f_d2="${BITS_DIR}/${m_type}.d2" |
| 28 | sed -e ' |
| 29 | /DEF_MPERS_TYPE('"${m_type}"')$/n |
| 30 | /DEF_MPERS_TYPE/d |
| 31 | /^[[:space:]]*#[[:space:]]*include[[:space:]]\+\"xlat\//d |
| 32 | /^#[[:space:]]*include[[:space:]]\+MPERS_DEFS$/ {s//'"${m_type} ${VAR_NAME}"';/;q} |
| 33 | ' "${PARSER_FILE}" > "${f_c}" |
| 34 | $CPP $CPPFLAGS "${f_c}" > "${f_i}" |
| 35 | grep -F -q "${m_type}.h" "${f_i}" || |
| 36 | continue |
| 37 | sed -i -e '/DEF_MPERS_TYPE/d' "${f_c}" |
| 38 | $CC $CFLAGS $ARCH_FLAG "${f_c}" -o "${f_o}" |
| 39 | readelf --debug-dump=info "${f_o}" > "${f_d1}" |
| 40 | sed -n ' |
| 41 | /^[[:space:]]*<1>/,/^[[:space:]]*<1><[^>]\+>: Abbrev Number: 0/!d |
| 42 | /^[[:space:]]*<[^>]\+><[^>]\+>: Abbrev Number: 0/d |
| 43 | s/^[[:space:]]*<[[:xdigit:]]\+>[[:space:]]\+// |
| 44 | s/^[[:space:]]*\(\(<[[:xdigit:]]\+>\)\{2\}\):[[:space:]]\+/\1\n/ |
| 45 | s/[[:space:]]\+$// |
| 46 | p' "${f_d1}" > "${f_d2}" |
| 47 | gawk -v VAR_NAME="$VAR_NAME" -v ARCH_FLAG="${ARCH_FLAG#-}" \ |
| 48 | -f "$MPERS_AWK" "${f_d2}" > "${f_h}" |
| 49 | done |