فهرست منبع

Add versioning infrastructure

Inspired by the Clutter project and work done by Florian Forster.
Stéphane Raimbault 15 سال پیش
والد
کامیت
95fd206f79
9فایلهای تغییر یافته به همراه160 افزوده شده و 10 حذف شده
  1. 2 0
      .gitignore
  2. 8 1
      NEWS
  3. 39 4
      configure.ac
  4. 5 4
      modbus/Makefile.am
  5. 5 0
      modbus/modbus.c
  6. 2 0
      modbus/modbus.h
  7. 63 0
      modbus/version.h.in
  8. 5 1
      tests/Makefile.am
  9. 31 0
      tests/version.c

+ 2 - 0
.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

+ 8 - 1
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

+ 39 - 4
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

+ 5 - 4
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 = *~

+ 5 - 0
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 {

+ 2 - 0
modbus/modbus.h

@@ -33,6 +33,8 @@
 #include <netinet/tcp.h>
 #include <arpa/inet.h>
 
+#include <modbus/version.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif

+ 63 - 0
modbus/version.h.in

@@ -0,0 +1,63 @@
+/*
+ * Copyright © 2010 Stéphane Raimbault <stephane.raimbault@gmail.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#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_ */

+ 5 - 1
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 = *~

+ 31 - 0
tests/version.c

@@ -0,0 +1,31 @@
+/*
+ * Copyright © 2010 Stéphane Raimbault <stephane.raimbault@gmail.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <modbus/modbus.h>
+
+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;
+}