Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Import new version of libbucl including schema validation
Baptiste Daroussin committed 12 years ago
commit e7abd22266f791fcecd3a1e0123f6e3b0dad9940
parent f881a31
19 files changed +327 -73
modified configure.ac
@@ -41,6 +41,33 @@ AC_CHECK_HEADERS_ONCE([memory.h])
AC_CHECK_HEADERS_ONCE([inttypes.h])
AC_CHECK_HEADERS_ONCE([unistd.h])
AC_CHECK_HEADERS_ONCE([dlfcn.h])
+
AC_CHECK_HEADERS_ONCE([fcntl.h])
+

+
AC_CHECK_HEADERS_ONCE([sys/types.h])
+
AC_CHECK_HEADERS_ONCE([sys/stat.h])
+
AC_CHECK_HEADERS_ONCE([sys/param.h])
+
AC_CHECK_HEADERS_ONCE([sys/mman.h])
+
AC_CHECK_HEADERS_ONCE([stdlib.h])
+
AC_CHECK_HEADERS_ONCE([stddef.h])
+
AC_CHECK_HEADERS_ONCE([stdarg.h])
+
AC_CHECK_HEADERS_ONCE([stdbool.h])
+
AC_CHECK_HEADERS_ONCE([stdint.h])
+
AC_CHECK_HEADERS_ONCE([string.h])
+
AC_CHECK_HEADERS_ONCE([unistd.h])
+
AC_CHECK_HEADERS_ONCE([ctype.h])
+
AC_CHECK_HEADERS_ONCE([errno.h])
+
AC_CHECK_HEADERS_ONCE([limits.h])
+
AC_CHECK_HEADERS_ONCE([libgen.h])
+
AC_CHECK_HEADERS_ONCE([stdio.h])
+
AC_CHECK_HEADERS_ONCE([float.h])
+
AC_CHECK_HEADERS_ONCE([math.h])
+

+
AC_CHECK_HEADER([regex.h], [
+
	AC_DEFINE(HAVE_REGEX_H, 1, [Define to 1 if you have the <regex.h> header file.])
+
	],
+
	[AC_MSG_ERROR([unable to find the regex.h header])],
+
	[#include <sys/types.h>])
+


AC_CHECK_FUNCS_ONCE([posix_fallocate])
AC_CHECK_FUNCS_ONCE([usleep])
@@ -128,26 +155,6 @@ AC_CHECK_HEADER([sys/capability.h], [

])

-
AC_CHECK_HEADERS_ONCE([fcntl.h])
-
AC_CHECK_HEADERS_ONCE([sys/types.h])
-
AC_CHECK_HEADERS_ONCE([sys/stat.h])
-
AC_CHECK_HEADERS_ONCE([sys/param.h])
-
AC_CHECK_HEADERS_ONCE([sys/mman.h])
-
AC_CHECK_HEADERS_ONCE([stdlib.h])
-
AC_CHECK_HEADERS_ONCE([stddef.h])
-
AC_CHECK_HEADERS_ONCE([stdarg.h])
-
AC_CHECK_HEADERS_ONCE([stdbool.h])
-
AC_CHECK_HEADERS_ONCE([stdint.h])
-
AC_CHECK_HEADERS_ONCE([string.h])
-
AC_CHECK_HEADERS_ONCE([unistd.h])
-
AC_CHECK_HEADERS_ONCE([ctype.h])
-
AC_CHECK_HEADERS_ONCE([errno.h])
-
AC_CHECK_HEADERS_ONCE([limits.h])
-
AC_CHECK_HEADERS_ONCE([libgen.h])
-
AC_CHECK_HEADERS_ONCE([stdio.h])
-
AC_CHECK_HEADERS_ONCE([float.h])
-
AC_CHECK_HEADERS_ONCE([math.h])
-


AC_SUBST([LIBELF_LIB])
AC_SUBST([LIBELF_BUNDLED])
modified external/Makefile.am
@@ -141,6 +141,7 @@ ucl_common_cflags= -I$(top_srcdir)/external//libucl/uthash \
libucl_la_SOURCES=	libucl/src/ucl_emitter.c \
			libucl/src/ucl_hash.c \
			libucl/src/ucl_parser.c \
+
			libucl/src/ucl_schema.c \
			libucl/src/ucl_util.c \
			libucl/src/xxhash.c
libucl_la_CFLAGS=	$(ucl_common_cflags) -shared
modified external/libucl/Makefile.am
@@ -1,3 +1,7 @@
ACLOCAL_AMFLAGS = -I m4
-
EXTRA_DIST = uthash $(TESTS)
-
SUBDIRS = src tests

\ No newline at end of file
+
EXTRA_DIST = uthash doc README.md
+

+
pkgconfigdir = $(libdir)/pkgconfig
+
pkgconfig_DATA = libucl.pc
+

+
SUBDIRS = src tests utils

\ No newline at end of file
modified external/libucl/configure.ac
@@ -50,6 +50,14 @@ dnl Example of default-disabled feature
AC_ARG_ENABLE([urls], AS_HELP_STRING([--enable-urls], [Enable URLs fetch (requires libfetch or libcurl)]))
AC_ARG_ENABLE([signatures], AS_HELP_STRING([--enable-signatures], 
	[Enable signatures check (requires openssl)]))
+
AC_ARG_ENABLE([utils],
+
	[--enable-utils Build and install utils],
+
	[case "${enableval}" in
+
  		yes) utils=true ;;
+
  		no)  utils=false ;;
+
  		*) AC_MSG_ERROR([bad value ${enableval} for --enable-utils]) ;;
+
	esac],[utils=false])
+
AM_CONDITIONAL([UTILS], [test x$utils = xtrue])

AS_IF([test "x$enable_signatures" = "xyes"], [
	AC_SEARCH_LIBS([EVP_MD_CTX_create], [crypto], [
@@ -58,13 +66,25 @@ AS_IF([test "x$enable_signatures" = "xyes"], [
		LIBS_EXTRA="${LIBS_EXTRA} -lcrypto"
		], [AC_MSG_ERROR([unable to find the EVP_MD_CTX_create() function])])
])
-
AC_SEARCH_LIBS([clock_gettime], [rt], [], [AC_MSG_ERROR([unable to find clock_gettime() function])])
-
	
+

+
AC_SEARCH_LIBS([clock_gettime], [rt], [], [
+
	AC_CHECK_HEADER([mach/mach_time.h], [
+
		AC_DEFINE(HAVE_MACH_MACH_TIME_H, 1, [Define to 1 on Darwin])
+
	], [AC_MSG_ERROR([unable to find clock_gettime or mach_absolute_time])])
+
])
+
AC_SEARCH_LIBS([remainder], [m], [], [AC_MSG_ERROR([unable to find remainder() function])])
+

+
AC_CHECK_HEADER([regex.h], [
+
	AC_DEFINE(HAVE_REGEX_H, 1, [Define to 1 if you have the <regex.h> header file.])
+
	], 
+
	[AC_MSG_ERROR([unable to find the regex.h header])],
+
	[#include <sys/types.h>])
+

AS_IF([test "x$enable_urls" = "xyes"], [	
	AC_CHECK_HEADER([fetch.h], [
		AC_DEFINE(HAVE_FETCH_H, 1, [Define to 1 if you have the <fetch.h> header file.])
		AC_CHECK_LIB(fetch, fetchXGet, [
-
			AC_DEFINE(HAVE_LIBFETCH, 1, [Define to 1 if you have the 'fetch' library (-fetch).])
+
			AC_DEFINE(HAVE_LIBFETCH, 1, [Define to 1 if you have the 'fetch' library (-lfetch).])
			LIBFETCH_LIBS="-lfetch"
			have_libfetch="yes"
			LIBS_EXTRA="${LIBS_EXTRA} -lfetch"
@@ -89,9 +109,12 @@ AS_IF([test "x$enable_urls" = "xyes"], [
	AC_SUBST(CURL_CFLAGS)
])

+
AC_SUBST(LIBS_EXTRA)
+

AC_CONFIG_FILES(Makefile \
	src/Makefile \
	tests/Makefile \
+
	utils/Makefile \
	libucl.pc)
AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
AC_OUTPUT
modified external/libucl/libucl.pc.in
@@ -8,4 +8,4 @@ Description: Universal configuration library
Version: @UCL_VERSION@
Libs: -L${libdir} -lucl
Libs.private: @LIBS_EXTRA@
-
Cflags: -I${includedir}/ @EXTRA_CFLAGS@
+
Cflags: -I${includedir}/
modified external/libucl/src/Makefile.am
@@ -16,4 +16,8 @@ libucl_la_LIBADD= @LIBFETCH_LIBS@ \
					@CURL_LIBS@

include_HEADERS=	$(top_srcdir)/include/ucl.h
-

+
noinst_HEADERS=	ucl_internal.h \
+
				xxhash.h \
+
				ucl_hash.h \
+
				ucl_chartable.h \
+
				tree.h
modified external/libucl/src/ucl_emitter.c
@@ -25,15 +25,15 @@
#include "config.h"
#endif

+
#include "ucl.h"
+
#include "ucl_internal.h"
+
#include "ucl_chartable.h"
#ifdef HAVE_FLOAT_H
#include <float.h>
#endif
#ifdef HAVE_MATH_H
#include <math.h>
#endif
-
#include "ucl.h"
-
#include "ucl_internal.h"
-
#include "ucl_chartable.h"

/**
 * @file rcl_emitter.c
modified external/libucl/src/ucl_internal.h
@@ -26,6 +26,26 @@

#ifdef HAVE_CONFIG_H
#include "config.h"
+
#else
+
/* Help embedded builds */
+
#define HAVE_SYS_TYPES_H
+
#define HAVE_SYS_MMAN_H
+
#define HAVE_SYS_STAT_H
+
#define HAVE_SYS_PARAM_H
+
#define HAVE_LIMITS_H
+
#define HAVE_FCNTL_H
+
#define HAVE_ERRNO_H
+
#define HAVE_UNISTD_H
+
#define HAVE_CTYPE_H
+
#define HAVE_STDIO_H
+
#define HAVE_STRING_H
+
#define HAVE_FLOAT_H
+
#define HAVE_LIBGEN_H
+
#define HAVE_MATH_H
+
#define HAVE_STDBOOL_H
+
#define HAVE_STDINT_H
+
#define HAVE_STDARG_H
+
#define HAVE_REGEX_H
#endif

#ifdef HAVE_SYS_TYPES_H
modified external/libucl/src/ucl_schema.c
@@ -33,6 +33,16 @@
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
+
#ifdef HAVE_REGEX_H
+
#include <regex.h>
+
#endif
+
#ifdef HAVE_MATH_H
+
#include <math.h>
+
#endif
+

+
static bool ucl_schema_validate (ucl_object_t *schema,
+
		ucl_object_t *obj, bool try_array,
+
		struct ucl_schema_error *err);

static bool
ucl_string_to_type (const char *input, ucl_type_t *res)
@@ -119,6 +129,29 @@ ucl_schema_create_error (struct ucl_schema_error *err,
}

/*
+
 * Check whether we have a pattern specified
+
 */
+
static ucl_object_t *
+
ucl_schema_test_pattern (ucl_object_t *obj, const char *pattern)
+
{
+
	regex_t reg;
+
	ucl_object_t *res = NULL, *elt;
+
	ucl_object_iter_t iter = NULL;
+

+
	if (regcomp (&reg, pattern, REG_EXTENDED | REG_NOSUB) == 0) {
+
		while ((elt = ucl_iterate_object (obj, &iter, true)) != NULL) {
+
			if (regexec (&reg, ucl_object_key (elt), 0, NULL, 0) == 0) {
+
				res = elt;
+
				break;
+
			}
+
		}
+
		regfree (&reg);
+
	}
+

+
	return res;
+
}
+

+
/*
 * Validate object
 */
static bool
@@ -126,7 +159,7 @@ ucl_schema_validate_object (ucl_object_t *schema,
		ucl_object_t *obj, struct ucl_schema_error *err)
{
	ucl_object_t *elt, *prop, *found, *additional_schema = NULL,
-
			*required = NULL;
+
			*required = NULL, *pat, *pelt;
	ucl_object_iter_t iter = NULL, piter = NULL;
	bool ret = true, allow_additional = true;
	int64_t minmax;
@@ -134,10 +167,11 @@ ucl_schema_validate_object (ucl_object_t *schema,
	while (ret && (elt = ucl_iterate_object (schema, &iter, true)) != NULL) {
		if (elt->type == UCL_OBJECT &&
				strcmp (ucl_object_key (elt), "properties") == 0) {
+
			piter = NULL;
			while (ret && (prop = ucl_iterate_object (elt, &piter, true)) != NULL) {
				found = ucl_object_find_key (obj, ucl_object_key (prop));
				if (found) {
-
					ret = ucl_object_validate (prop, found, err);
+
					ret = ucl_schema_validate (prop, found, true, err);
				}
			}
		}
@@ -190,7 +224,15 @@ ucl_schema_validate_object (ucl_object_t *schema,
				break;
			}
		}
-
		/* XXX: propertyPatterns */
+
		else if (strcmp (ucl_object_key (elt), "patternProperties") == 0) {
+
			piter = NULL;
+
			while (ret && (prop = ucl_iterate_object (elt, &piter, true)) != NULL) {
+
				found = ucl_schema_test_pattern (obj, ucl_object_key (prop));
+
				if (found) {
+
					ret = ucl_schema_validate (prop, found, true, err);
+
				}
+
			}
+
		}
	}

	if (ret) {
@@ -200,17 +242,28 @@ ucl_schema_validate_object (ucl_object_t *schema,
			iter = NULL;
			prop = ucl_object_find_key (schema, "properties");
			while ((elt = ucl_iterate_object (obj, &iter, true)) != NULL) {
-
				if (prop == NULL ||
-
					(found = ucl_object_find_key (prop, ucl_object_key (elt))) == NULL) {
+
				found = ucl_object_find_key (prop, ucl_object_key (elt));
+
				if (found == NULL) {
+
					/* Try patternProperties */
+
					piter = NULL;
+
					pat = ucl_object_find_key (schema, "patternProperties");
+
					while ((pelt = ucl_iterate_object (pat, &piter, true)) != NULL) {
+
						found = ucl_schema_test_pattern (obj, ucl_object_key (pelt));
+
						if (found != NULL) {
+
							break;
+
						}
+
					}
+
				}
+
				if (found == NULL) {
					if (!allow_additional) {
						ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
-
								"object has undefined property %s",
+
								"object has non-allowed property %s",
								ucl_object_key (elt));
						ret = false;
						break;
					}
					else if (additional_schema != NULL) {
-
						if (!ucl_object_validate (additional_schema, elt, err)) {
+
						if (!ucl_schema_validate (additional_schema, elt, true, err)) {
							ret = false;
							break;
						}
@@ -245,17 +298,26 @@ ucl_schema_validate_number (ucl_object_t *schema,
	ucl_object_iter_t iter = NULL;
	bool ret = true, exclusive = false;
	double constraint, val;
+
	const double alpha = 1e-16;

	while (ret && (elt = ucl_iterate_object (schema, &iter, true)) != NULL) {
-
		if (elt->type == UCL_INT &&
-
			strcmp (ucl_object_key (elt), "multipleOf") == 0) {
-
			val = ucl_object_toint (elt);
-
			if (val <= 0) {
+
		if ((elt->type == UCL_FLOAT || elt->type == UCL_INT) &&
+
				strcmp (ucl_object_key (elt), "multipleOf") == 0) {
+
			constraint = ucl_object_todouble (elt);
+
			if (constraint <= 0) {
				ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, elt,
						"multipleOf must be greater than zero");
				ret = false;
				break;
			}
+
			val = ucl_object_todouble (obj);
+
			if (fabs (remainder (val, constraint)) > alpha) {
+
				ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
+
						"number %.4f is not multiple of %.4f, remainder is %.7f",
+
						val, constraint);
+
				ret = false;
+
				break;
+
			}
		}
		else if ((elt->type == UCL_FLOAT || elt->type == UCL_INT) &&
			strcmp (ucl_object_key (elt), "maximum") == 0) {
@@ -403,7 +465,7 @@ ucl_schema_validate_array (ucl_object_t *schema,
				found = obj->value.av;
				while (ret && (it = ucl_iterate_object (elt, &piter, true)) != NULL) {
					if (found) {
-
						ret = ucl_object_validate (it, found, err);
+
						ret = ucl_schema_validate (it, found, false, err);
						found = found->next;
					}
				}
@@ -415,7 +477,7 @@ ucl_schema_validate_array (ucl_object_t *schema,
			else if (elt->type == UCL_OBJECT) {
				/* Validate all items using the specified schema */
				while (ret && (it = ucl_iterate_object (obj, &piter, true)) != NULL) {
-
					ret = ucl_object_validate (elt, it, err);
+
					ret = ucl_schema_validate (elt, it, false, err);
				}
			}
			else {
@@ -475,14 +537,13 @@ ucl_schema_validate_array (ucl_object_t *schema,
			if (first_unvalidated != NULL) {
				if (!allow_additional) {
					ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
-
							"object has undefined property %s",
-
							ucl_object_key (elt));
+
							"array has undefined item");
					ret = false;
				}
				else if (additional_schema != NULL) {
					elt = first_unvalidated;
					while (elt) {
-
						if (!ucl_object_validate (additional_schema, elt, err)) {
+
						if (!ucl_schema_validate (additional_schema, elt, false, err)) {
							ret = false;
							break;
						}
@@ -556,17 +617,111 @@ ucl_schema_type_is_allowed (ucl_object_t *type, ucl_object_t *obj,
	return false;
}

-
bool
-
ucl_object_validate (ucl_object_t *schema,
-
		ucl_object_t *obj, struct ucl_schema_error *err)
+
/*
+
 * Check if object is equal to one of elements of enum
+
 */
+
static bool
+
ucl_schema_validate_enum (ucl_object_t *en, ucl_object_t *obj,
+
		struct ucl_schema_error *err)
{
+
	ucl_object_iter_t iter = NULL;
	ucl_object_t *elt;
+
	bool ret = false;
+

+
	while ((elt = ucl_iterate_object (en, &iter, true)) != NULL) {
+
		if (ucl_object_compare (elt, obj) == 0) {
+
			ret = true;
+
			break;
+
		}
+
	}
+

+
	if (!ret) {
+
		ucl_schema_create_error (err, UCL_SCHEMA_CONSTRAINT, obj,
+
				"object is not one of enumerated patterns");
+
	}
+

+
	return ret;
+
}
+

+
static bool
+
ucl_schema_validate (ucl_object_t *schema,
+
		ucl_object_t *obj, bool try_array,
+
		struct ucl_schema_error *err)
+
{
+
	ucl_object_t *elt, *cur;
+
	ucl_object_iter_t iter = NULL;
+
	bool ret;

	if (schema->type != UCL_OBJECT) {
		ucl_schema_create_error (err, UCL_SCHEMA_INVALID_SCHEMA, schema,
				"schema is %s instead of object", ucl_object_type_to_string (schema->type));
		return false;
	}
+

+
	elt = ucl_object_find_key (schema, "enum");
+
	if (elt != NULL && elt->type == UCL_ARRAY) {
+
		if (!ucl_schema_validate_enum (elt, obj, err)) {
+
			return false;
+
		}
+
	}
+

+
	elt = ucl_object_find_key (schema, "allOf");
+
	if (elt != NULL && elt->type == UCL_ARRAY) {
+
		iter = NULL;
+
		while ((cur = ucl_iterate_object (elt, &iter, true)) != NULL) {
+
			ret = ucl_schema_validate (cur, obj, true, err);
+
			if (!ret) {
+
				return false;
+
			}
+
		}
+
	}
+

+
	elt = ucl_object_find_key (schema, "anyOf");
+
	if (elt != NULL && elt->type == UCL_ARRAY) {
+
		iter = NULL;
+
		while ((cur = ucl_iterate_object (elt, &iter, true)) != NULL) {
+
			ret = ucl_schema_validate (cur, obj, true, err);
+
			if (ret) {
+
				break;
+
			}
+
		}
+
		if (!ret) {
+
			return false;
+
		}
+
		else {
+
			/* Reset error */
+
			err->code = UCL_SCHEMA_OK;
+
		}
+
	}
+

+
	elt = ucl_object_find_key (schema, "oneOf");
+
	if (elt != NULL && elt->type == UCL_ARRAY) {
+
		iter = NULL;
+
		while ((cur = ucl_iterate_object (elt, &iter, true)) != NULL) {
+
			if (!ret) {
+
				ret = ucl_schema_validate (cur, obj, true, err);
+
			}
+
			else if (ucl_schema_validate (cur, obj, true, err)) {
+
				ret = false;
+
				break;
+
			}
+
		}
+
		if (!ret) {
+
			return false;
+
		}
+
	}
+

+
	elt = ucl_object_find_key (schema, "not");
+
	if (elt != NULL && elt->type == UCL_OBJECT) {
+
		if (ucl_schema_validate (elt, obj, true, err)) {
+
			return false;
+
		}
+
		else {
+
			/* Reset error */
+
			err->code = UCL_SCHEMA_OK;
+
		}
+
	}
+

	elt = ucl_object_find_key (schema, "type");

	if (!ucl_schema_type_is_allowed (elt, obj, err)) {
@@ -593,3 +748,10 @@ ucl_object_validate (ucl_object_t *schema,

	return true;
}
+

+
bool
+
ucl_object_validate (ucl_object_t *schema,
+
		ucl_object_t *obj, struct ucl_schema_error *err)
+
{
+
	return ucl_schema_validate (schema, obj, true, err);
+
}
modified external/libucl/src/ucl_util.c
@@ -1294,6 +1294,10 @@ ucl_iterate_object (ucl_object_t *obj, ucl_object_iter_t *iter, bool expand_valu
{
	ucl_object_t *elt;

+
	if (obj == NULL || iter == NULL) {
+
		return NULL;
+
	}
+

	if (expand_values) {
		switch (obj->type) {
		case UCL_OBJECT:
modified external/libucl/tests/Makefile.am
@@ -1,8 +1,13 @@
+
EXTRA_DIST = $(TESTS) basic schema generate.res rcl_test.json.xz
+

TESTS = basic.test \
		generate.test \
		schema.test \
		speed.test
-
TESTS_ENVIRONMENT = $(SH) TEST_DIR=$(top_srcdir)/tests
+
TESTS_ENVIRONMENT = $(SH) \
+
			TEST_DIR=$(top_srcdir)/tests \
+
			TEST_OUT_DIR=$(top_builddir)/tests \
+
			TEST_BINARY_DIR=$(top_builddir)/tests

common_test_cflags = -I$(top_srcdir)/include \
					-I$(top_srcdir)/src \
@@ -21,7 +26,7 @@ test_generate_SOURCES = test_generate.c
test_generate_LDADD = $(common_test_ldadd)
test_generate_CFLAGS = $(common_test_cflags)

-
test_schema_SOURCES = test_generate.c
+
test_schema_SOURCES = test_schema.c
test_schema_LDADD = $(common_test_ldadd)
test_schema_CFLAGS = $(common_test_cflags)

modified external/libucl/tests/basic.test
@@ -1,25 +1,26 @@
#!/bin/sh

-
PROG=test_basic
+
PROG=${TEST_BINARY_DIR}/test_basic

for _tin in ${TEST_DIR}/basic/*.in ; do
	_t=`echo $_tin | sed -e 's/.in$//'`
-
	$PROG $_t.in $_t.out
+
	_out=${TEST_OUT_DIR}/basic.out
+
	$PROG $_t.in $_out
	if [ $? -ne 0 ] ; then
		echo "Test: $_t failed, output:"
-
		cat $_t.out
-
		rm $_t.out
+
		cat $_out
+
		rm $_out
		exit 1
	fi
	if [ -f $_t.res ] ; then
-
	diff -s $_t.out $_t.res -u 2>/dev/null
+
	diff -s $_out $_t.res -u 2>/dev/null
		if [ $? -ne 0 ] ; then
-
			rm $_t.out
+
			rm $_out
			echo "Test: $_t output missmatch"
			exit 1
		fi
	fi
-
	rm $_t.out
+
	rm $_out
done


modified external/libucl/tests/generate.test
@@ -1,13 +1,13 @@
#!/bin/sh

-
PROG=test_generate
+
PROG=${TEST_BINARY_DIR}/test_generate

-
$PROG ${TEST_DIR}/generate.out
-
diff -s ${TEST_DIR}/generate.out ${TEST_DIR}/generate.res -u 2>/dev/null
+
$PROG ${TEST_OUT_DIR}/generate.out
+
diff -s ${TEST_OUT_DIR}/generate.out ${TEST_DIR}/generate.res -u 2>/dev/null
if [ $? -ne 0 ] ; then
-
	rm ${TEST_DIR}/generate.out
+
	rm ${TEST_OUT_DIR}/generate.out
	echo "Test: generate.res output missmatch"
	exit 1
fi
-
rm ${TEST_DIR}/generate.out
+
rm ${TEST_OUT_DIR}/generate.out

modified external/libucl/tests/schema.test
@@ -1,9 +1,9 @@
#!/bin/sh

-
PROG=test_schema
+
PROG=${TEST_BINARY_DIR}/test_schema
rm /tmp/_ucl_test_schema.out ||true
for i in ${TEST_DIR}/schema/*.json ; do
	_name=`basename $i`
	printf "running schema test suite $_name... "
-
	cat $i | $4 >> /tmp/_ucl_test_schema.out && ( echo "OK" ) || ( echo "Fail" )
+
	$PROG >> /tmp/_ucl_test_schema.out < $i && ( echo "OK" ) || ( echo "Fail" )
done
modified external/libucl/tests/speed.test
@@ -1,21 +1,21 @@
#!/bin/sh

-
PROG=test_speed
+
PROG=${TEST_BINARY_DIR}/test_speed

sh -c "xz -c < /dev/null > /dev/null"
echo 'Running speed tests'
for _tin in ${TEST_DIR}/*.xz ; do
	echo "Unpacking $_tin..."
-
	xz -cd < $_tin > ${TEST_DIR}/test_file
+
	xz -cd < $_tin > ${TEST_OUT_DIR}/test_file
	# Preread file to cheat benchmark!
-
	cat ${TEST_DIR}/test_file > /dev/null
+
	cat ${TEST_OUT_DIR}/test_file > /dev/null
	echo "Starting benchmarking for $_tin..."
-
	$PROG ${TEST_DIR}/test_file
+
	$PROG ${TEST_OUT_DIR}/test_file
	if [ $? -ne 0 ] ; then
		echo "Test: $_tin failed"
-
		rm ${TEST_DIR}/test_file
+
		rm ${TEST_OUT_DIR}/test_file
		exit 1
	fi
-
	rm ${TEST_DIR}/test_file
+
	rm ${TEST_OUT_DIR}/test_file
done

modified external/libucl/tests/test_speed.c
@@ -32,8 +32,10 @@
#include <time.h>

#ifdef __APPLE__
+
#ifdef HAVE_MACH_MACH_TIME_H
#include <mach/mach_time.h>
#endif
+
#endif

#include "ucl.h"

added external/libucl/utils/Makefile.am
@@ -0,0 +1,19 @@
+
common_utils_cflags = -I$(top_srcdir)/include \
+
					-I$(top_srcdir)/src \
+
					-I$(top_srcdir)/uthash
+
common_utils_ldadd = $(top_builddir)/src/libucl.la
+

+
ucl_chargen_SOURCES = chargen.c
+
ucl_chargen_LDADD = $(common_utils_ldadd)
+
ucl_chargen_CFLAGS = $(common_utils_cflags)
+

+
ucl_objdump_SOURCES = objdump.c
+
ucl_objdump_LDADD = $(common_utils_ldadd)
+
ucl_objdump_CFLAGS = $(common_utils_cflags)
+

+
if UTILS
+
UTL = ucl_chargen ucl_objdump
+
else
+
UTL =
+
endif
+
bin_PROGRAMS = $(UTL)

\ No newline at end of file
modified libpkg/Makefile.am
@@ -50,7 +50,8 @@ libpkg_la_LIBADD= $(top_builddir)/external/libucl.la \
			-larchive \
			-lfetch \
			-lutil \
-
			-lcrypto
+
			-lcrypto \
+
			-lm

libpkg_la_LDFLAGS=	-version-info 2 -pthread
lib_LTLIBRARIES=	libpkg.la libpkg_static.la
modified src/Makefile.am
@@ -91,7 +91,8 @@ pkg_static_LDADD= $(top_builddir)/libpkg/libpkg_static.la \
			-llzma \
			-lssl \
			-lcrypto \
-
			-lmd
+
			-lmd \
+
			-lm
pkg_static_LDFLAGS=	-all-static -pthread
sbin_PROGRAMS=		pkg pkg-static