Add 'version' call to get true library version number.
authorRichard Jones <rjones@trick.home.annexia.org>
Fri, 10 Jul 2009 16:52:09 +0000 (17:52 +0100)
committerRichard Jones <rjones@trick.home.annexia.org>
Fri, 10 Jul 2009 16:52:09 +0000 (17:52 +0100)
This patch also changes the way that the version is specified
in configure.ac.  It is now made out of four parts (major, minor,
release and extra) and constructed for AC_INIT.

.gitignore
configure.ac
src/generator.ml
src/guestfs.c

index 92b29b6..13f25e8 100644 (file)
@@ -94,6 +94,7 @@ java/com/redhat/et/libguestfs/LV.java
 java/com/redhat/et/libguestfs/PV.java
 java/com/redhat/et/libguestfs/Stat.java
 java/com/redhat/et/libguestfs/StatVFS.java
+java/com/redhat/et/libguestfs/Version.java
 java/com/redhat/et/libguestfs/VG.java
 java/doc-stamp
 *.la
index 48b57ed..7f965b2 100644 (file)
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-AC_INIT([libguestfs],[1.0.57])
+# major/minor/release must be numbers
+m4_define([libguestfs_major],   [1])
+m4_define([libguestfs_minor],   [0])
+m4_define([libguestfs_release], [57])
+# extra can be any string
+m4_define([libguestfs_extra],   [])
+
+AC_INIT([libguestfs],libguestfs_major.libguestfs_minor.libguestfs_release[]libguestfs_extra)
 AM_INIT_AUTOMAKE([foreign])
 
 AC_CONFIG_MACRO_DIR([m4])
 
 AC_PROG_LIBTOOL
 
+dnl Split up the version string.
+AC_DEFINE([PACKAGE_VERSION_MAJOR],[libguestfs_major],[Major version number])
+AC_DEFINE([PACKAGE_VERSION_MINOR],[libguestfs_minor],[Minor version number])
+AC_DEFINE([PACKAGE_VERSION_RELEASE],[libguestfs_release],[Release number])
+AC_DEFINE([PACKAGE_VERSION_EXTRA],["libguestfs_extra"],[Extra version string])
+
 dnl Check for basic C environment.
 AC_PROG_CC_STDC
 AC_PROG_INSTALL
index 7c0e566..0904afc 100755 (executable)
@@ -636,6 +636,36 @@ qemu subprocess, then this will return an error.
 
 This is an internal call used for debugging and testing.");
 
+  ("version", (RStruct ("version", "version"), []), -1, [],
+   [InitBasicFS, Always, TestOutputStruct (
+      [["version"]], [CompareWithInt ("major", 1)])],
+   "get the library version number",
+   "\
+Return the libguestfs version number that the program is linked
+against.
+
+Note that because of dynamic linking this is not necessarily
+the version of libguestfs that you compiled against.  You can
+compile the program, and then at runtime dynamically link
+against a completely different C<libguestfs.so> library.
+
+This call was added in version C<1.0.58>.  In previous
+versions of libguestfs there was no way to get the version
+number.  From C code you can use ELF weak linking tricks to find out if
+this symbol exists (if it doesn't, then it's an earlier version).
+
+The call returns a structure with four elements.  The first
+three (C<major>, C<minor> and C<release>) are numbers and
+correspond to the usual version triplet.  The fourth element
+(C<extra>) is a string and is normally empty, but may be
+used for distro-specific information.
+
+To construct the original version string:
+C<$major.$minor.$release$extra>
+
+I<Note:> Don't use this call to test for availability
+of features.  Distro backports makes this unreliable.");
+
 ]
 
 (* daemon_functions are any functions which cause some action
@@ -2928,6 +2958,14 @@ let structs = [
     "ftyp", FChar;
     "name", FString;
   ];
+
+  (* Version numbers. *)
+  "version", [
+    "major", FInt64;
+    "minor", FInt64;
+    "release", FInt64;
+    "extra", FString;
+  ];
 ] (* end of structs *)
 
 (* Ugh, Java has to be different ..
@@ -2940,7 +2978,8 @@ let java_structs = [
   "lvm_lv", "LV";
   "stat", "Stat";
   "statvfs", "StatVFS";
-  "dirent", "Dirent"
+  "dirent", "Dirent";
+  "version", "Version";
 ]
 
 (* Used for testing language bindings. *)
index 7ab7200..f445ada 100644 (file)
@@ -697,6 +697,19 @@ guestfs_get_pid (guestfs_h *g)
   }
 }
 
+struct guestfs_version *
+guestfs_version (guestfs_h *g)
+{
+  struct guestfs_version *r;
+
+  r = safe_malloc (g, sizeof *r);
+  r->major = PACKAGE_VERSION_MAJOR;
+  r->minor = PACKAGE_VERSION_MINOR;
+  r->release = PACKAGE_VERSION_RELEASE;
+  r->extra = safe_strdup (g, PACKAGE_VERSION_EXTRA);
+  return r;
+}
+
 /* Add a string to the current command line. */
 static void
 incr_cmdline_size (guestfs_h *g)