Skip to content
Snippets Groups Projects
Commit e450beda authored by Ondřej Surý's avatar Ondřej Surý
Browse files

Remove bashisms from script/gen-cdefs.sh

parent 06b0d3d4
Branches
Tags
1 merge request!100allow generating most cdefs for lua
#!/bin/sh -e
echo "--[[ This file is generated by ./kres-gen.sh ]] ffi.cdef[[
"
printf -- "--[[ This file is generated by ./kres-gen.sh ]] ffi.cdef[[\n"
## Various types (mainly), from libknot and libkres
echo "
printf "
typedef struct knot_dump_style knot_dump_style_t;
extern const knot_dump_style_t KNOT_DUMP_STYLE_DEFAULT;
"
# The generator doesn't work well with typedefs of functions.
echo "
printf "
typedef struct knot_mm {
void *ctx, *alloc, *free;
} knot_mm_t;
......@@ -54,10 +53,10 @@ genResType "struct knot_rrset" | sed 's/\<owner\>/_owner/'
## Some definitions would need too many deps, so shorten them.
genResType "struct kr_query" | sed '/struct kr_nsrep/,$ d'
echo -e "\tchar _stub[];\n};"
printf "\tchar _stub[];\n};\n"
genResType "struct kr_context" | sed '/struct kr_cache/,$ d'
echo -e "\tchar _stub[];\n};"
printf "\tchar _stub[];\n};\n"
# Getting struct query_flag is a bit complex.
genResType "enum kr_query_flag" | sed -e 's/enum kr_query_flag/struct query_flag/' \
......@@ -123,5 +122,6 @@ EOF
kr_dnssec_key_match
EOF
echo "]]"
printf "]]\n"
exit 0
......@@ -7,12 +7,16 @@ if [ "$2" != types ] && [ "$2" != functions ]; then
exit 1
fi
if type -P gdb >/dev/null; then :; else
if ! command -v gdb >/dev/null; then
echo "Failed to find gdb" >&2
exit 1
fi
library="$(PATH="$(pwd)/lib:$(pkg-config libknot --variable=libdir)" type -P "$1.so")"
case "$1" in
libknot) library="$(PATH="$(pkg-config libknot --variable=libdir)" command -v "$1.so")" ;;
*) library="$(PATH="$(pwd)/lib" command -v "$1.so")"
esac
if [ -z "$library" ]; then
echo "$1 not found. Note: only .so platforms work currently." >&2
exit 1
......@@ -22,7 +26,7 @@ GDB="gdb -quiet -symbols=$library"
grep -v '^#\|^$' | while read ident; do
output="$(
if [ "$2" == functions ]; then
if [ "$2" = functions ]; then
$GDB --ex "info functions ^$ident\$" --ex quit \
| sed '1,/^All functions/ d; /^File .*:$/ d'
continue
......@@ -49,3 +53,4 @@ grep -v '^#\|^$' | while read ident; do
echo "$output" | grep -v '^$'
done
exit 0
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