Code

fb_features: Added a header describing available features of the library.
authorSebastian Harl <sh@tokkee.org>
Thu, 15 Oct 2009 22:03:18 +0000 (00:03 +0200)
committerSebastian Harl <sh@tokkee.org>
Thu, 15 Oct 2009 22:03:18 +0000 (00:03 +0200)
This header provides various macros and functions that may be used to
determine the version of 'foobar'. The file is created automatically by
configure using the input file fb_features.h.in.

This allows for fine grained version checks at compile- and runtime.

.gitignore
configure.ac
src/Makefile.am
src/fb_features.h.in [new file with mode: 0644]
src/foobar.c

index b96a2c4042dac62420d270ade7b21d9393bec378..69fab010a69c0c8374063e8ab39a764d6073d917 100644 (file)
@@ -22,4 +22,5 @@ ltmain.sh
 *.lo
 *.o
 fb
+fb_features.h
 
index 47c9c092b62db4b33ab6ba39f9876f0b3d6a4609..6cc54b018e7e7368a72fe98119e631efb165791d 100644 (file)
@@ -139,9 +139,22 @@ build_date="`date --utc '+%F %T'` (UTC)"
 AC_DEFINE_UNQUOTED([BUILD_DATE], ["$build_date"],
                [Define to the date the package has been built on.])
 
+dnl Version information provided by fb_features.h.
+FB_VERSION_MAJOR=`echo $PACKAGE_VERSION | cut -d'.' -f1`
+FB_VERSION_MINOR=`echo $PACKAGE_VERSION | cut -d'.' -f2`
+FB_VERSION_PATCH=`echo $PACKAGE_VERSION | cut -d'.' -f3`
+FB_VERSION_EXTRA=`echo $PACKAGE_VERSION | cut -d'.' -f4-`
+FB_VERSION_STRING="$FB_VERSION_MAJOR.$FB_VERSION_MINOR.$FB_VERSION_PATCH"
+
+AC_SUBST(FB_VERSION_MAJOR)
+AC_SUBST(FB_VERSION_MINOR)
+AC_SUBST(FB_VERSION_PATCH)
+AC_SUBST(FB_VERSION_EXTRA)
+AC_SUBST(FB_VERSION_STRING)
+
 AC_CHECK_HEADERS(libgen.h)
 
-AC_CONFIG_FILES([Makefile src/Makefile])
+AC_CONFIG_FILES([Makefile src/Makefile src/fb_features.h])
 AC_OUTPUT
 
 cat <<EOF;
index 4e77ae3988e9333458a7b4ac566aa92cf6b64d6c..1c22316b43280d1e00ffc8cd1c4b78095b2ee3af 100644 (file)
@@ -1,9 +1,11 @@
 AM_CFLAGS = @STRICT_CFLAGS@
 
-include_HEADERS = foobar.h
+include_HEADERS = foobar.h fb_features.h
 lib_LTLIBRARIES = libfoobar.la
 
-libfoobar_la_SOURCES = foobar.c foobar.h
+BUILT_SOURCES = fb_features.h
+
+libfoobar_la_SOURCES = foobar.c foobar.h fb_features.h
 libfoobar_la_LDFLAGS = -version-info 0:0:0
 
 bin_PROGRAMS = fb
diff --git a/src/fb_features.h.in b/src/fb_features.h.in
new file mode 100644 (file)
index 0000000..3844c65
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * foobar - src/fb_features.h
+ * Copyright (C) 2009 Sebastian Harl <sh@tokkee.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; only version 2 of the License is applicable.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+/*
+ * A short description of this module...
+ */
+
+#ifndef FB_FEATURES_H
+#define FB_FEATURES_H 1
+
+#define FB_VERSION_MAJOR @FB_VERSION_MAJOR@
+#define FB_VERSION_MINOR @FB_VERSION_MINOR@
+#define FB_VERSION_PATCH @FB_VERSION_PATCH@
+
+#define FB_VERSION_EXTRA "@FB_VERSION_EXTRA@"
+
+#define FB_VERSION_STRING "@FB_VERSION_STRING@"
+
+#define FB_VERSION_ENCODE(major, minor, patch) \
+       ((major) * 10000 + (minor) * 100 + (patch))
+
+#define FB_VERSION FB_VERSION_ENCODE(FB_VERSION_MAJOR, FB_VERSION_MINOR, \
+               FB_VERSION_PATCH)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+unsigned int
+fb_version(void);
+
+const char *
+fb_version_string(void);
+
+const char *
+fb_version_extra(void);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* ! FB_FEATURES_H */
+
+/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
+
index 0accc0cef024cda0ecfe0abb73f73ca69918b3ba..385880ee82b4688db892bedc4403bca36946182d 100644 (file)
  */
 
 #include "foobar.h"
+#include "fb_features.h"
+
+/*
+ * public API
+ */
+
+unsigned int
+fb_version(void)
+{
+       return FB_VERSION;
+} /* fb_version */
+
+const char *
+fb_version_string(void)
+{
+       return FB_VERSION_STRING;
+} /* fb_version_string */
+
+const char *
+fb_version_extra(void)
+{
+       return FB_VERSION_EXTRA;
+} /* fb_version_extra */
 
 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */