Commit fd9102a9 authored by Kir Kolyshkin's avatar Kir Kolyshkin Committed by Cyrill Gorcunov

gen-offsets.h: refactor

These changes are mostly for better readability and style.
The only actual difference (in the output produced) is the last item.

(1) Use UPPERCASE variable names

(2) Simplify names (get rid of name_ prefix for everything)

(3) Rename variables:
- name_ifndef to INC_GUARD,
- name_prefix_offset to PREFIX,
- name_bin to BINARY.

(4) Replace sed with tr for simplicity

(5) Replace grep with awk condition

(6) Don't escape every $ and " inside AWK_CMD, just quote the full string

(7) Use cat and 'here document' instead of many echoes

(8) Simplify hexdump arguments, use single -e option

(9) Insert our name into 'Generated by' comment.
Signed-off-by: 's avatarKir Kolyshkin <kir@openvz.org>
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent 8a8ce9b3
#!/bin/sh
name_ifndef=$1
name_prefix_offset=$2
name_blob=$3
name_objname=$4
name_bin=$5
awk_cmd="{ print \"#define $name_prefix_offset\" \$3 \" 0x\" \$1; }"
echo "/* Autogenerated file, don't edit */"
echo "#ifndef $name_ifndef"
echo "#define $name_ifndef"
echo ""
nm $name_objname | grep ' [Tt] ' | sed -e 's/\./_/g' | awk "$awk_cmd"
echo ""
echo "static char $name_blob[] = {"
hexdump -v -e '"\t"' -e '8/1 "0x%02x, "' -e '"\n"' $name_bin
echo "};"
echo ""
echo "#endif /* $name_ifndef */"
INC_GUARD=$1
PREFIX=$2
BLOB=$3
OBJNAME=$4
BINARY=$5
AWK_CMD='$2 ~ /^[tT]$/ { print "#define '$PREFIX'" $3 " 0x" $1; }'
cat << EOF
/* Autogenerated by $0, do not edit */
#ifndef $INC_GUARD
#define $INC_GUARD
EOF
nm $OBJNAME | tr . _ | awk "$AWK_CMD"
cat << EOF
static char $BLOB[] = {
EOF
hexdump -v -e '"\t" 8/1 "0x%02x, " "\n"' $BINARY
cat << EOF
};
#endif /* $INC_GUARD */
EOF
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment