From e40e2d0b887fd48bb9fc2b61bee558abc0043c25 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 16 Oct 2009 00:03:18 +0200 Subject: [PATCH] fb_features: Added a header describing available features of the library. 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 | 1 + configure.ac | 15 ++++++++++- src/Makefile.am | 6 +++-- src/fb_features.h.in | 60 ++++++++++++++++++++++++++++++++++++++++++++ src/foobar.c | 23 +++++++++++++++++ 5 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 src/fb_features.h.in diff --git a/.gitignore b/.gitignore index b96a2c4..69fab01 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,5 @@ ltmain.sh *.lo *.o fb +fb_features.h diff --git a/configure.ac b/configure.ac index 47c9c09..6cc54b0 100644 --- a/configure.ac +++ b/configure.ac @@ -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 < + * + * 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 : */ + diff --git a/src/foobar.c b/src/foobar.c index 0accc0c..385880e 100644 --- a/src/foobar.c +++ b/src/foobar.c @@ -21,6 +21,29 @@ */ #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 : */ -- 2.30.2