diff --git a/.gitignore b/.gitignore index efb7ed1..c351f56 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ libtool ltmain.sh missing modbus.pc +version.h .deps .libs *.la @@ -33,3 +34,4 @@ tests/random-test-master tests/random-test-slave tests/unit-test-master tests/unit-test-slave +tests/version \ No newline at end of file diff --git a/NEWS b/NEWS index 0451fc4..81d8965 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,11 @@ -libmodbus 2.2.0 (2009-XX-01) +libmodbus 2.1.1 (2010-XX-XX) +============================ + +- Versioning infrastructure. + Inspired by the Clutter project and the work done by Florian Forster. +- Renamed src directory to modbus + +libmodbus 2.1.0 (2010-03-24) ============================ - New API to read and write float values by Stéphane Raimbault and Florian diff --git a/configure.ac b/configure.ac index f69e7c4..a1cb638 100644 --- a/configure.ac +++ b/configure.ac @@ -1,14 +1,48 @@ -# -*- Autoconf -*- -# Process this file with autoconf to produce a configure script. +# libmodbus package version number, (as distinct from shared library version) +# An odd micro number indicates in-progress development from Git +# An even micro number indicates a released version +# +# Making a point release: +# - increase mb_version_micro to the next even number +# +# After the release: +# - increase mb_version_minor to the next odd number +# +# mb_version_ld increases at each new minor version because minor versions +# are used to change API/ABI +# +m4_define([mb_version_major], [2]) +m4_define([mb_version_minor], [1]) +m4_define([mb_version_micro], [1]) + +m4_define([mb_release_status], + [m4_if(m4_eval(mb_version_minor % 2), [1], [snapshot], + [release])]) + +m4_define([mb_version], [mb_version_major.mb_version_minor.mb_version_micro]) +m4_define([mb_version_ld], [m4_eval(mb_version_major + mb_version_minor)]) AC_PREREQ(2.63) -AC_INIT([libmodbus],[2.1.0],[stephane.raimbault@gmail.com]) +AC_INIT([libmodbus],[mb_version],[stephane.raimbault@gmail.com]) AC_CONFIG_SRCDIR([modbus/modbus.c]) AC_CONFIG_HEADERS([config.h]) AM_INIT_AUTOMAKE([1.11 foreign]) # enable nice build output on automake1.11 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) +MB_VERSION_MAJOR=mb_version_major +MB_VERSION_MINOR=mb_version_minor +MB_VERSION_MICRO=mb_version_micro +MB_VERSION=mb_version +AC_SUBST(MB_VERSION_MAJOR) +AC_SUBST(MB_VERSION_MINOR) +AC_SUBST(MB_VERSION_MICRO) +AC_SUBST(MB_VERSION) + +MB_VERSION_LD=mb_version_ld +MB_LT_LDFLAGS="-version-info $MB_VERSION_LD:0:0" +AC_SUBST(MB_LT_LDFLAGS) + # Checks for programs. AC_PROG_CC AC_PROG_CXX @@ -39,7 +73,8 @@ AC_CHECK_FUNCS([gettimeofday inet_ntoa memset select socket strerror]) AC_CONFIG_FILES([ Makefile modbus/Makefile + modbus/version.h tests/Makefile - modbus.pc + libmodbus.pc ]) AC_OUTPUT diff --git a/modbus/Makefile.am b/modbus/Makefile.am index 60fa7aa..d905b48 100644 --- a/modbus/Makefile.am +++ b/modbus/Makefile.am @@ -1,10 +1,11 @@ lib_LTLIBRARIES = libmodbus.la -libmodbus_la_SOURCES = modbus.c modbus.h -libmodbus_la_LDFLAGS = -version-info 2:0:0 -service_CFLAGS = -I$(top_srcdir)/ +libmodbus_la_SOURCES = modbus.c modbus.h version.h +libmodbus_la_LDFLAGS = $(MB_LT_LDFLAGS) # Include files to install libmodbusincludedir = $(includedir)/modbus -libmodbusinclude_HEADERS = modbus.h +libmodbusinclude_HEADERS = modbus.h version.h +DISTCLEANFILES = version.h +EXTRA_DIST = version.h.in CLEANFILES = *~ diff --git a/modbus/modbus.c b/modbus/modbus.c index 28ff67e..d2ec62f 100644 --- a/modbus/modbus.c +++ b/modbus/modbus.c @@ -65,6 +65,11 @@ #define UNKNOWN_ERROR_MSG "Not defined in modbus specification" +/* Exported version */ +const unsigned int mb_version_major = MB_VERSION_MAJOR; +const unsigned int mb_version_minor = MB_VERSION_MINOR; +const unsigned int mb_version_micro = MB_VERSION_MICRO; + /* This structure reduces the number of params in functions and so * optimizes the speed of execution (~ 37%). */ typedef struct { diff --git a/modbus/modbus.h b/modbus/modbus.h index ea74b9c..986dddd 100644 --- a/modbus/modbus.h +++ b/modbus/modbus.h @@ -33,6 +33,8 @@ #include #include +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/modbus/version.h.in b/modbus/version.h.in new file mode 100644 index 0000000..aa19138 --- /dev/null +++ b/modbus/version.h.in @@ -0,0 +1,63 @@ +/* + * Copyright © 2010 Stéphane Raimbault + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with this program. If not, see . + */ + +#ifndef _MB_VERSION_H_ +#define _MB_VERSION_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* The major version of libmb, (1, if %MB_VERSION is 1.2.3) */ +#define MB_VERSION_MAJOR (@MB_VERSION_MAJOR@) + +/* The minor version of libmb (2, if %MB_VERSION is 1.2.3) */ +#define MB_VERSION_MINOR (@MB_VERSION_MINOR@) + +/* The micro version of libmb (3, if %MB_VERSION is 1.2.3) */ +#define MB_VERSION_MICRO (@MB_VERSION_MICRO@) + +/* The full version of libmb, like 1.2.3 */ +#define MB_VERSION @MB_VERSION@ + +/* The full version of libmb, in string form (suited for + * string concatenation) + */ +#define MB_VERSION_STRING "@MB_VERSION@" + +/* Numerically encoded version libmb, like 0x010203 */ +#define MB_VERSION_HEX ((MB_MAJOR_VERSION << 24) | \ + (MB_MINOR_VERSION << 16) | \ + (MB_MICRO_VERSION << 8)) + +/* Evaluates to True if the version of libmb is greater than @major, @minor + * and @micro + */ +#define MB_VERSION_CHECK(major,minor,micro) \ + (MB_VERSION_MAJOR > (major) || \ + (MB_VERSION_MAJOR == (major) && MB_VERSION_MINOR > (minor)) || \ + (MB_VERSION_MAJOR == (major) && MB_VERSION_MINOR == (minor) && MB_VERSION_MICRO >= (micro))) + +extern const unsigned int mb_version_major; +extern const unsigned int mb_version_minor; +extern const unsigned int mb_version_micro; + +#ifdef __cplusplus +} +#endif + +#endif /* _MB_VERSION_H_ */ diff --git a/tests/Makefile.am b/tests/Makefile.am index 46185e4..b6d79b1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -7,7 +7,8 @@ noinst_PROGRAMS = \ unit-test-master \ bandwidth-slave-one \ bandwidth-slave-many-up \ - bandwidth-master + bandwidth-master \ + version common_ldflags = \ $(top_builddir)/modbus/libmodbus.la @@ -33,5 +34,8 @@ bandwidth_slave_many_up_LDADD = $(common_ldflags) bandwidth_master_SOURCES = bandwidth-master.c bandwidth_master_LDADD = $(common_ldflags) +version_SOURCES = version.c +version_LDADD = $(common_ldflags) + INCLUDES = -I$(top_srcdir) CLEANFILES = *~ diff --git a/tests/version.c b/tests/version.c new file mode 100644 index 0000000..dc281a1 --- /dev/null +++ b/tests/version.c @@ -0,0 +1,31 @@ +/* + * Copyright © 2010 Stéphane Raimbault + * + * 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; either version 3 of the License, or + * (at your option) any later version. + * + * 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, see . + */ + +#include +#include + +int main(void) +{ + printf("Compiled with libmodbus version %s\n", MB_VERSION_STRING); + printf("Linked with libmodbus version %d.%d.%d\n", + mb_version_major, mb_version_minor, mb_version_micro); + + if (MB_VERSION_CHECK(2, 1, 0)) { + printf("The functions to read/write float values are available.\n"); + } + return 0; +}