Move the tagtbl.c generator monster awk out of Makefile.am
authorPanu Matilainen <pmatilai@redhat.com>
Sun, 6 Apr 2008 16:18:44 +0000 (19:18 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Sun, 6 Apr 2008 16:18:44 +0000 (19:18 +0300)
- stick it into a separate script, reformat so it's possible to actually
  read it...

rpmdb/Makefile.am
rpmdb/gentagtbl.sh [new file with mode: 0755]

index c423a48..0a97144 100644 (file)
@@ -11,6 +11,7 @@ AM_CPPFLAGS += @WITH_LIBELF_INCLUDE@
 check_PROGRAMS =
 EXTRA_PROGRAMS =
 CLEANFILES =
+EXTRA_DIST = gentagtbl.sh
 
 usrlibdir = $(libdir)
 usrlib_LTLIBRARIES = librpmdb.la
@@ -36,20 +37,8 @@ else
 librpmdb_la_LIBADD += @WITH_DB_LIB@
 endif
 
-tagtbl.c: Makefile.am $(top_srcdir)/lib/rpmtag.h 
-       @echo '#include "system.h"' > $@
-       @echo '#include <rpm/header.h>' >> $@
-       @echo '#include <rpm/rpmtag.h>' >> $@
-       @echo '#include "debug.h"' >> $@
-       @echo '' >> $@
-       @echo 'static const struct headerTagTableEntry_s rpmTagTbl[] = {' >> $@
-       ${AWK} '/[\t ](RPMTAG_[A-Z0-9]*)[ \t]+([0-9]*)/ && !/internal/ {tt = "NULL"; ta = "ANY"; if ($$5 == "c") {tt = "CHAR"; ta = "SCALAR"} if ($$5 == "c[]") {tt = "CHAR"; ta = "ARRAY"} if ($$5 == "h") {tt = "INT16"; ta = "SCALAR"} if ($$5 == "h[]") {tt = "INT16"; ta = "ARRAY"} if ($$5 == "i") {tt = "INT32"; ta = "SCALAR"} if ($$5 == "i[]") {tt = "INT32"; ta = "ARRAY"} if ($$5 == "l") {tt = "INT64"; ta = "SCALAR"} if ($$5 == "l[]") {tt = "INT64"; ta = "ARRAY"} if ($$5 == "s") {tt = "STRING"; ta = "SCALAR"} if ($$5 == "s[]") {tt = "STRING_ARRAY"; ta = "ARRAY"} if ($$5 == "s{}") {tt = "I18NSTRING"; ta = "SCALAR"} if ($$5 == "x") {tt = "BIN"; ta = "SCALAR"} if ($$2 == "=") { printf("\t{ \"%s\",  %s      RPM_%s_TYPE + RPM_%s_RETURN_TYPE },\n", $$1, $$3, tt, ta) } else { printf("\t{ \"%s\",  %s,     RPM_%s_TYPE + RPM_%s_RETURN_TYPE  },\n", $$2, $$3, tt, ta) } }' < ${top_srcdir}/lib/rpmtag.h | sort >> $@
-       @echo ' { NULL, 0, 0 }' >> $@
-       @echo '};' >> $@
-       @echo '' >> $@
-       @echo 'const struct headerTagTableEntry_s * const rpmTagTable = rpmTagTbl;' >> $@
-       @echo '' >> $@
-       @echo 'const int rpmTagTableSize = sizeof(rpmTagTbl) / sizeof(rpmTagTbl[0]) - 1;' >> $@
+tagtbl.c: Makefile.am $(top_srcdir)/lib/rpmtag.h gentagtbl.sh
+       @AWK=${AWK} ${SHELL} gentagtbl.sh $(top_srcdir)/lib/rpmtag.h > $@
 BUILT_SOURCES = tagtbl.c
 
 if WITH_INTERNAL_DB
diff --git a/rpmdb/gentagtbl.sh b/rpmdb/gentagtbl.sh
new file mode 100755 (executable)
index 0000000..a4d6744
--- /dev/null
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+cat << EOF
+#include "system.h"
+#include <rpm/header.h>
+#include <rpm/rpmtag.h>
+#include "debug.h"
+
+static const struct headerTagTableEntry_s rpmTagTbl[] = {
+EOF
+
+${AWK} '/[\t ](RPMTAG_[A-Z0-9]*)[ \t]+([0-9]*)/ && !/internal/ {
+       tt = "NULL"
+       ta = "ANY"
+       if ($5 == "c") {
+               tt = "CHAR"
+               ta = "SCALAR"
+       }
+       if ($5 == "c[]") {
+               tt = "CHAR"
+               ta = "ARRAY"
+       } 
+       if ($5 == "h") {
+               tt = "INT16"
+               ta = "SCALAR"
+       }
+       if ($5 == "h[]") {
+               tt = "INT16"
+               ta = "ARRAY"
+       }
+       if ($5 == "i") {
+               tt = "INT32"
+               ta = "SCALAR"
+       }
+       if ($5 == "i[]") {
+               tt = "INT32"
+               ta = "ARRAY"
+       }
+       if ($5 == "l") {
+               tt = "INT64"
+               ta = "SCALAR"
+       }
+       if ($5 == "l[]") {
+               tt = "INT64"
+               ta = "ARRAY"
+       }
+       if ($5 == "s") {
+               tt = "STRING"
+               ta = "SCALAR"
+       }
+       if ($5 == "s[]") {
+               tt = "STRING_ARRAY"
+               ta = "ARRAY"
+       }
+       if ($5 == "s{}") {
+               tt = "I18NSTRING"
+               ta = "SCALAR"
+       } 
+       if ($5 == "x") {
+               tt = "BIN"
+               ta = "SCALAR"
+       }
+       if ($2 == "=") {
+               printf("    { \"%s\", %s RPM_%s_TYPE + RPM_%s_RETURN_TYPE },\n", $1, $3, tt, ta)
+       } else {
+               printf("    { \"%s\", %s, RPM_%s_TYPE + RPM_%s_RETURN_TYPE  },\n", $2, $3, tt, ta)
+       }
+}' < $1 | sort
+
+cat << EOF
+    { NULL, 0, 0 }
+};
+
+const struct headerTagTableEntry_s * const rpmTagTable = rpmTagTbl;
+const int rpmTagTableSize = sizeof(rpmTagTbl) / sizeof(rpmTagTbl[0]) - 1;
+EOF
+