diff options
-rw-r--r-- | Makefile.am | 11 | ||||
-rw-r--r-- | configure.ac | 7 | ||||
-rw-r--r-- | rpmeval.c | 25 | ||||
-rwxr-xr-x | tests.sh | 18 | ||||
-rwxr-xr-x | tests/macros.sh | 28 |
5 files changed, 88 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am index 3a4270b..a7dd254 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,6 +38,12 @@ BUILT_SOURCES = macros-perarch make_macrosfiles.sh pkglibdir = @RPMVENDORDIR@ +bin_PROGRAMS = rpmeval + +rpmeval_SOURCES = rpmeval.c + +rpmeval_LDFLAGS = -lrpm + pkglib_DATA = \ $(pkg_data) \ $(pkg_gdata) @@ -75,12 +81,15 @@ install-data-local: $(macrosfiles) $(install_sh_DATA) $${i}.macros $(DESTDIR)$(RPMVENDORDIR)/$${i}-$(RPMOS)/macros; \ done -.PHONY: ChangeLog +.PHONY: ChangeLog test ChangeLog: LC_ALL=C svn2cl --accum rm -f *.bak +test: $(pkg_gdata) $(pkg_gscripts) $(macrosfiles) + sh tests.sh + CLEANFILES = $(pkg_gdata) $(pkg_gscripts) $(macrosfiles) \ macros-perarch \ make_macrosfiles.sh diff --git a/configure.ac b/configure.ac index bce1b20..d7374e1 100644 --- a/configure.ac +++ b/configure.ac @@ -10,11 +10,17 @@ AM_INIT_AUTOMAKE(1.9) AC_CONFIG_SRCDIR # Checks for programs. +AC_PROG_CC AC_PROG_INSTALL +AC_PROG_LIBTOOL AC_CONFIG_FILES([ Makefile ]) +AC_CHECK_LIB([rpmio], [rpmLoadMacroFile]) +AC_HEADER_STDC +AC_CHECK_HEADERS([string.h rpm/rpmmacros.h rpm/rpmlib.h]) + case "${target_cpu}" in *86|athlon|k6) RPMALLARCH="i386 i486 i586 i686 k6 athlon pentium3 pentium4" @@ -99,4 +105,5 @@ if test $with_rpmsysconfdir; then fi AC_SUBST(RPMSYSCONFDIR) + AC_OUTPUT diff --git a/rpmeval.c b/rpmeval.c new file mode 100644 index 0000000..c377dec --- /dev/null +++ b/rpmeval.c @@ -0,0 +1,25 @@ +/* $Id$ */ + +#include <rpm/rpmlib.h> +#include <rpm/rpmmacro.h> + +int main(int argc, char **argv) +{ + int rc; + char *results; + if (argc != 3) { + fprintf(stdout, "Not enough argument: %d\n", argc); + return 1; + } + if (rc = rpmReadConfigFiles(NULL, NULL)) { + fprintf(stderr, "Cannot load configuration\n"); + return rc; + } + if (rc = rpmLoadMacroFile(rpmGlobalMacroContext, argv[1])) { + fprintf(stderr, "Cannot read %s\n", argv[1]); + return rc; + } + results = rpmExpand(argv[2], NULL); + fprintf(stdout, "%s\n", results); + return 0; +} diff --git a/tests.sh b/tests.sh new file mode 100755 index 0000000..99c333b --- /dev/null +++ b/tests.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +# $Id$ + +allerrs=0 + +for i in tests/*.sh; do + /bin/sh ${i} + err=$? + if [ $err -ne 0 ]; then + echo "${i}: $err test(s) failed" + allerrs=$[ $allerrs + $err ] + else + echo "${i}: All test succefully passed" + fi +done + +exit $allerrs diff --git a/tests/macros.sh b/tests/macros.sh new file mode 100755 index 0000000..519e7b4 --- /dev/null +++ b/tests/macros.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +# $Id$ + +RPMEVAL=./rpmeval + +err=0 + +mcheck() { + macro=$1 + is=$2 + echo -n "${macro}... " + res=`$RPMEVAL macros ${macro}` + if [ "X${res}" != "X${is}" ]; then + echo "give ${res} not ${is}" + err=$[ $err + 1] + else + echo "OK" + fi +} + +mcheck %_var /var +mcheck %_localstatedir /var/lib +mcheck %_bindir /usr/bin +mcheck %_sbindir /usr/sbin +mcheck %_prefix /usr + +exit $err |