Implement xlat generator
authorMike Frysinger <vapier@gentoo.org>
Sun, 16 Feb 2014 06:59:20 +0000 (01:59 -0500)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 30 May 2014 21:29:40 +0000 (21:29 +0000)
* bootstrap: New file.
* xlat/gen.sh: Likewise.
* Makefile.am: Include xlat/Makemodule.am
(EXTRA_DIST): Add $(XLAT_INPUT_FILES), $(XLAT_HEADER_FILES), and
xlat/gen.sh.

Makefile.am
bootstrap [new file with mode: 0755]
xlat/gen.sh [new file with mode: 0755]

index a789b8caea0129150f39dab6170867f3411ecd10..7052157f2819cdf096b56862cc6606f227d83971 100644 (file)
@@ -14,6 +14,8 @@ ACLOCAL_AMFLAGS = -I m4
 AM_CFLAGS = $(WARN_CFLAGS)
 AM_CPPFLAGS = -I$(srcdir)/$(OS)/$(ARCH) -I$(srcdir)/$(OS) -I$(builddir)/$(OS)
 
+include xlat/Makemodule.am
+
 strace_SOURCES =       \
        aio.c           \
        bjm.c           \
@@ -213,6 +215,9 @@ EXTRA_DIST =                                \
        strace-log-merge                \
        strace.spec                     \
        syscallent.sh                   \
+       $(XLAT_INPUT_FILES)             \
+       $(XLAT_HEADER_FILES)            \
+       xlat/gen.sh                     \
        xlate.el
 
 .PHONY: srpm
diff --git a/bootstrap b/bootstrap
new file mode 100755 (executable)
index 0000000..196d8e4
--- /dev/null
+++ b/bootstrap
@@ -0,0 +1,3 @@
+#!/bin/sh
+./xlat/gen.sh
+exec autoreconf -f -i
diff --git a/xlat/gen.sh b/xlat/gen.sh
new file mode 100755 (executable)
index 0000000..23d5b8d
--- /dev/null
@@ -0,0 +1,96 @@
+#!/bin/sh
+
+usage() {
+       cat <<EOF
+Usage: $0 <input> <output>
+
+Generate xlat header files from <input> (a file or dir of files) and write
+the generated headers to <output>.
+EOF
+       exit 1
+}
+
+gen_header() {
+       local input="$1" output="$2" name="$3"
+       local line
+       echo "generating ${output}"
+       (
+       echo "/* Generated by $0 from $1; do not edit. */"
+       echo "const struct xlat ${name}[] = {"
+       while read line ; do
+               case ${line} in
+               /*|\#*|'')
+                       echo "${line}"
+                       ;;
+               *)
+                       echo "#ifdef ${line}"
+                       echo "  XLAT(${line}),"
+                       echo "#endif"
+                       ;;
+               esac
+       done < "${input}"
+       echo "  XLAT_END"
+       echo "};"
+       ) >"${output}"
+}
+
+gen_make() {
+       local output="$1"
+       local name
+       shift
+       echo "generating ${output}"
+       (
+               printf "XLAT_INPUT_FILES = "
+               printf 'xlat/%s.in ' "$@"
+               echo
+               printf "XLAT_HEADER_FILES = "
+               printf 'xlat/%s.h ' "$@"
+               echo
+               for name; do
+                       printf '$(top_srcdir)/xlat/%s.h: $(top_srcdir)/xlat/%s.in $(top_srcdir)/xlat/gen.sh\n' \
+                               "${name}" "${name}"
+                       echo '  $(AM_V_GEN)$(top_srcdir)/xlat/gen.sh $< $@'
+               done
+       ) >"${output}"
+}
+
+gen_git() {
+       local output="$1"
+       shift
+       echo "generating ${output}"
+       (
+               printf '/%s\n' .gitignore Makemodule.am
+               printf '/%s.h\n' "$@"
+       ) >"${output}"
+}
+
+main() {
+       case $# in
+       0) set -- "${0%/*}" "${0%/*}" ;;
+       2) ;;
+       *) usage ;;
+       esac
+
+       local input="$1"
+       local output="$2"
+       local name
+
+       if [ -d "${input}" ]; then
+               local f name names
+               for f in "${input}"/*.in; do
+                       name=${f##*/}
+                       name=${name%.in}
+                       gen_header "${f}" "${output}/${name}.h" "${name}" &
+                       names="${names} ${name}"
+               done
+               gen_git "${output}/.gitignore" ${names}
+               gen_make "${output}/Makemodule.am" ${names}
+               wait
+       else
+               name=${input##*/}
+               name=${name%.in}
+               gen_header "${input}" "${output}" "${name}"
+       fi
+}
+
+main "$@"