Add pixman_version function and related macros
authorCarl Worth <cworth@cworth.org>
Mon, 24 Mar 2008 21:51:09 +0000 (14:51 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 25 Mar 2008 19:38:01 +0000 (12:38 -0700)
The complete new API here makes available compile-tim version checks:

PIXMAN_VERSION
PIXMAN_VERSION_STRING
PIXMAN_VERSION_ENCODE

as well as run-time version checks:

pixman_version()
pixman_version_string()

.gitignore
configure.ac
pixman/Makefile.am
pixman/pixman-version.c [new file with mode: 0644]
pixman/pixman-version.h.in [new file with mode: 0644]
pixman/pixman.h

index 2c736c1..70b7b64 100644 (file)
@@ -26,6 +26,7 @@ stamp-h?
 config.h
 config.h.in
 .*.swp
+pixman/pixman-version.h
 test/composite-test
 test/fetch-test
 test/gradient-test
index 63ee2c5..e39f4c0 100644 (file)
@@ -72,8 +72,12 @@ m4_define([lt_age], [pixman_minor])
 
 LT_VERSION_INFO="lt_current:lt_revision:lt_age"
 
-PIXMAN_MAJOR=pixman_major
-AC_SUBST(PIXMAN_MAJOR)
+PIXMAN_VERSION_MAJOR=pixman_major()
+AC_SUBST(PIXMAN_VERSION_MAJOR)
+PIXMAN_VERSION_MINOR=pixman_minor()
+AC_SUBST(PIXMAN_VERSION_MINOR)
+PIXMAN_VERSION_MICRO=pixman_micro()
+AC_SUBST(PIXMAN_VERSION_MICRO)
 
 AC_SUBST(LT_VERSION_INFO)
 
@@ -212,4 +216,5 @@ AC_SUBST(DEP_LIBS)
 AC_OUTPUT([pixman-1.pc
            Makefile
           pixman/Makefile
+          pixman/pixman-version.h
           test/Makefile])
index 37d892b..ff3997b 100644 (file)
@@ -21,10 +21,11 @@ libpixman_1_la_SOURCES =            \
        pixman-edge-imp.h       \
        pixman-trap.c           \
        pixman-compute-region.c \
-       pixman-timer.c
+       pixman-timer.c          \
+       pixman-version.c
 
 libpixmanincludedir = $(includedir)/pixman-1/
-libpixmaninclude_HEADERS = pixman.h
+libpixmaninclude_HEADERS = pixman.h pixman-version.h
 
 # mmx code
 if USE_MMX
diff --git a/pixman/pixman-version.c b/pixman/pixman-version.c
new file mode 100644 (file)
index 0000000..58ac057
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright © 2008 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Carl D. Worth <cworth@cworth.org>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "pixman-private.h"
+
+/**
+ * pixman_version:
+ *
+ * Returns the version of the pixman library encoded in a single
+ * integer as per %PIXMAN_VERSION_ENCODE. The encoding ensures that
+ * later versions compare greater than earlier versions.
+ *
+ * A run-time comparison to check that pixman's version is greater than
+ * or equal to version X.Y.Z could be performed as follows:
+ *
+ * <informalexample><programlisting>
+ * if (pixman_version() >= PIXMAN_VERSION_ENCODE(X,Y,Z)) {...}
+ * </programlisting></informalexample>
+ *
+ * See also pixman_version_string() as well as the compile-time
+ * equivalents %PIXMAN_VERSION and %PIXMAN_VERSION_STRING.
+ *
+ * Return value: the encoded version.
+ **/
+int
+pixman_version (void)
+{
+    return PIXMAN_VERSION;
+}
+
+/**
+ * pixman_version_string:
+ *
+ * Returns the version of the pixman library as a human-readable string
+ * of the form "X.Y.Z".
+ *
+ * See also pixman_version() as well as the compile-time equivalents
+ * %PIXMAN_VERSION_STRING and %PIXMAN_VERSION.
+ *
+ * Return value: a string containing the version.
+ **/
+const char*
+pixman_version_string (void)
+{
+    return PIXMAN_VERSION_STRING;
+}
diff --git a/pixman/pixman-version.h.in b/pixman/pixman-version.h.in
new file mode 100644 (file)
index 0000000..ce86312
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright © 2008 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Carl D. Worth <cworth@cworth.org>
+ */
+
+#ifndef PIXMAN_VERSION_H__
+#define PIXMAN_VERSION_H__
+
+#define PIXMAN_VERSION_MAJOR @PIXMAN_VERSION_MAJOR@
+#define PIXMAN_VERSION_MINOR @PIXMAN_VERSION_MINOR@
+#define PIXMAN_VERSION_MICRO @PIXMAN_VERSION_MICRO@
+
+#define PIXMAN_VERSION_STRING "@PIXMAN_VERSION_MAJOR@.@PIXMAN_VERSION_MINOR@.@PIXMAN_VERSION_MICRO@"
+
+#define PIXMAN_VERSION_ENCODE(major, minor, micro) (   \
+         ((major) * 10000)                             \
+       + ((minor) *   100)                             \
+       + ((micro) *     1))
+
+#define PIXMAN_VERSION PIXMAN_VERSION_ENCODE(  \
+       PIXMAN_VERSION_MAJOR,                   \
+       PIXMAN_VERSION_MINOR,                   \
+       PIXMAN_VERSION_MICRO)
+
+#endif /* PIXMAN_VERSION_H__ */
index 2965acd..c4c5c3b 100644 (file)
@@ -69,6 +69,8 @@ SOFTWARE.
 #ifndef PIXMAN_H__
 #define PIXMAN_H__
 
+#include <pixman-version.h>
+
 /*
  * Standard integers
  */
@@ -272,6 +274,12 @@ typedef enum
     PIXMAN_REGION_PART
 } pixman_region_overlap_t;
 
+PIXMAN_EXPORT
+int                    pixman_version (void);
+
+PIXMAN_EXPORT
+const char*            pixman_version_string (void);
+
 /* This function exists only to make it possible to preserve the X ABI - it should
  * go away at first opportunity.
  */