#!/bin/bash
-set -o pipefail -o errexit
+# Run with "ninja kres-gen" to re-generate kres-gen.lua
+set -o pipefail -o errexit -o nounset
cd "$(dirname ${0})"
CDEFS="../../scripts/gen-cdefs.sh"
+LIBKRES="${MESON_BUILD_ROOT}/lib/libkres.so"
-# Write to .kres-gen.lua.tmp instead of STDOUT
-exec 1<&-
-exec 1<>.kres-gen.lua.tmp
-err_handle() {
+# Write to kres-gen.lua instead of stdout
+mv kres-gen.lua{,.bak} ||:
+exec 1>&-
+exec 1<>kres-gen.lua
+
+restore() {
+ exec 1>&-
+ mv kres-gen.lua{.bak,} ||:
(>&2 echo "Failed to re-generate kres-gen.lua! Missing debugsymbols?")
- rm -f .kres-gen.lua.tmp
}
-trap err_handle ERR INT TERM
+trap restore ERR INT TERM
### Dev's guide
#
typedef void (*trace_callback_f)(struct kr_request *);
"
-${CDEFS} libkres types <<-EOF
+${CDEFS} ${LIBKRES} types <<-EOF
knot_section_t
knot_rrinfo_t
knot_dname_t
EOF
genResType() {
- echo "$1" | ${CDEFS} libkres types
+ echo "$1" | ${CDEFS} ${LIBKRES} types
}
# No simple way to fixup this rename in ./kres.lua AFAIK.
genResType "knot_rrset_t" | sed 's/\<owner\>/_owner/; s/\<ttl\>/_ttl/'
-${CDEFS} libkres types <<-EOF
+${CDEFS} ${LIBKRES} types <<-EOF
knot_pkt_t
knot_edns_options_t
knot_pktsection_t
EOF
## libkres API
-${CDEFS} libkres functions <<-EOF
+${CDEFS} ${LIBKRES} functions <<-EOF
# Resolution request
kr_resolve_plan
kr_resolve_pool
printf "]]\n"
-mv .kres-gen-lua.tmp kres-gen.lua
-(>&2 echo "Successfully re-generated "${PWD}/kres-gen.lua")
+rm kres-gen.lua.bak ||:
+(>&2 echo "Successfully re-generated ${PWD}/kres-gen.lua")
exit 0
case "$1" in
libknot) library="$(PATH="$(pkg-config libknot --variable=libdir)" command -v "$1.so")" ;;
libzscanner) library="$(PATH="$(pkg-config libzscanner --variable=libdir)" command -v "$1.so")" ;;
- *) library="$(PATH="$(pwd)/lib" command -v "$1.so")"
+ *) library="$(command -v "$1")" # use absolute path to library
esac
if [ -z "$library" ]; then
output="$(echo "$output" | sed 's/\buint\b/unsigned int/g')"
# GDB 8.2+ added source line prefix to output
output="$(echo "$output" | sed 's/^[0-9]\+:[[:space:]]*//g')"
+ # use tabs instead of spaces
+ output="$(echo "$output" | sed 's/ /\t/g')"
# abort on empty output
if [ -z "$(echo "$output" | tr -d "\n;")" ]; then