Index: ChangeLog
===================================================================
--- ChangeLog	(revision 5763)
+++ ChangeLog	(revision 5764)
@@ -12,4 +12,5 @@
 	* Added support for configureable memmgr backend (Closes: #334)
 	* Moved notify debugging support out of roard into plugin debug-notify.
+	* Added support to roar-config to check versions (Closes: #336)
 
 v. 1.0beta7 - Tue Oct 23 2012 23:28 CEST
Index: doc/man1/roar-config.1
===================================================================
--- doc/man1/roar-config.1	(revision 5748)
+++ doc/man1/roar-config.1	(revision 5764)
@@ -10,4 +10,6 @@
 
 roar-config \-\-version
+
+roar-config \-\-compare-versions VERSIONA OPERATOR VERSIONB
 
 roar-config [{\-\-output-pc|\-\-output-normal}] [\-\-libs] [\-\-cflags] [LIB]
@@ -25,4 +27,16 @@
 \fB--version\fR
 Show version of library
+
+.TP
+\fB--compare-versions VERSIONA OPERATOR VERSIONB\fR
+Compares version VERSIONA against version VERSIONB using operator OPERATOR.
+Both versions must be in dotted format (e.g. 1.0.8) or the special keyword "current".
+This keyword represents the current used version.
+
+Operator may be "eq" (equal), "ne" (not equal), "gt" (greater than), "ge" (greater than or equal),
+"lt" (less than) or "le" (less than or equal).
+
+This function is mostly useful to check for minimum required or maximum supported versions of libroar
+in configure scripts.
 
 .TP
Index: roarclients/roar-config.c
===================================================================
--- roarclients/roar-config.c	(revision 5748)
+++ roarclients/roar-config.c	(revision 5764)
@@ -53,4 +53,83 @@
 }, * flags_ptr = NULL;
 
+struct version {
+ int major, minor, revision;
+};
+
+static struct version parse_version(const char * version) {
+ struct version ret = {-1, -1, -1};
+ char * next;
+
+ if ( !strcasecmp(version, "current") )
+  version = COMMON_VERSION;
+
+ ret.major    = strtoll(version, &next, 0);
+ ret.minor    = strtoll(next+1, &next, 0);
+ ret.revision = strtoll(next+1, &next, 0);
+
+ return ret;
+}
+
+static int compare_versions_eq(struct version a, struct version b) {
+ return a.major == b.major && a.minor == b.minor && a.revision == b.revision;
+}
+
+static int compare_versions_gt(struct version a, struct version b) {
+ if ( a.major > b.major )
+  return 1;
+ if ( a.minor > b.minor )
+  return 1;
+ if ( a.revision > b.revision )
+  return 1;
+ return 0;
+}
+
+static int compare_versions_ge(struct version a, struct version b) {
+ return compare_versions_gt(a, b) || compare_versions_eq(a, b);
+}
+
+static int compare_versions_lt(struct version a, struct version b) {
+ return compare_versions_gt(b, a);
+}
+
+static int compare_versions_le(struct version a, struct version b) {
+ return compare_versions_lt(a, b) || compare_versions_eq(a, b);
+}
+
+static const struct {
+ const char * op;
+ int neg;
+ int (*func)(struct version a, struct version b);
+} compare_versions_funcs[] = {
+ {"eq", 0, compare_versions_eq},
+ {"ne", 1, compare_versions_eq},
+ {"gt", 0, compare_versions_gt},
+ {"ge", 0, compare_versions_ge},
+ {"lt", 0, compare_versions_lt},
+ {"le", 0, compare_versions_le}
+};
+
+static int compare_versions(const char * a, const char * op, const char * b) {
+ struct version va = parse_version(a);
+ struct version vb = parse_version(b);
+ size_t i;
+ int ret;
+
+ ROAR_DBG("compare_versions(a='%s', op='%s', b='%s'): {%i, %i, %i} <%s> {%i, %i, %i}\n", a, op, b, va.major, va.minor, va.revision, op, vb.major, vb.minor, vb.revision);
+
+ for (i = 0; i < (sizeof(compare_versions_funcs)/sizeof(*compare_versions_funcs)); i++) {
+  if ( !strcasecmp(compare_versions_funcs[i].op, op) ) {
+   ret = compare_versions_funcs[i].func(va, vb);
+   if ( compare_versions_funcs[i].neg )
+    ret = ret ? 0 : 1;
+
+   return ret ? 0 : 32;
+  }
+ }
+
+ ROAR_ERR("compare_versions(*): Operator \"%s\" not found.", op);
+ return 1;
+}
+
 void print_path(const char * name, int null_as_universal, const char * product, const char * provider) {
  char * path = roar_libroar_get_path(name, null_as_universal, product, provider);
@@ -63,4 +142,5 @@
 void usage (void) {
  printf("Usage: roar-config --version\n"
+        "       roar-config --compare-versions VERSIONA OPERATOR VERSIONB\n"
         "       roar-config [{--output-pc|--output-normal}] [--libs] [--cflags] [LIB]\n"
         "       roar-config [--product PRODUCT] [--provider PROVIDER] [--universal] --path PATH\n");
@@ -70,4 +150,6 @@
  printf(
         "  --version           - Show version of library\n"
+        "  --compare-versions A OP B\n"
+        "                      - Compare version A against B with operator OP.\n"
         "  --path NAME         - Print path NAME\n"
         "  --product PRODUCT   - Product string for --path\n"
@@ -105,4 +187,6 @@
    usage();
    return 0;
+  } else if ( !strcmp(argv[i], "--compare-versions") ) {
+   return compare_versions(argv[i+1], argv[i+2], argv[i+3]);
   } else if ( !strcmp(argv[i], "--product") ) {
    product = argv[++i];
