Эх сурвалжийг харах

Merge modbus.h and version.h

The library is now simpler to include (only one <modbus.h>)
To avoid confusion MB_VERSION defines have been renamed to
LIBMODBUS_VERSION.
Stéphane Raimbault 14 жил өмнө
parent
commit
93ce136561
7 өөрчлөгдсөн 75 нэмэгдсэн , 103 устгасан
  1. 2 2
      .gitignore
  2. 24 24
      configure.ac
  3. 5 5
      src/Makefile.am
  4. 3 3
      src/modbus.c
  5. 38 3
      src/modbus.h.in
  6. 0 63
      src/version.h.in
  7. 3 3
      tests/version.c

+ 2 - 2
.gitignore

@@ -20,7 +20,7 @@ libtool
 ltmain.sh
 missing
 libmodbus.pc
-version.h
+modbus.h
 .deps
 .libs
 *.la
@@ -34,4 +34,4 @@ tests/random-test-master
 tests/random-test-slave
 tests/unit-test-master
 tests/unit-test-slave
-tests/version
+tests/version

+ 24 - 24
configure.ac

@@ -3,47 +3,47 @@
 # An even micro number indicates a released version
 #
 # Making a point release:
-# - increase mb_version_micro to the next even number
+# - increase libmodbus_version_micro to the next even number
 #
 # After the release:
-# - increase mb_version_minor to the next odd number
+# - increase libmodbus_version_minor to the next odd number
 #
-# Take care to update the libtool versioning when required (MB_LD_*).
+# Take care to update the libtool versioning when required (LIBMODBUS_LD_*).
 # http://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
 #
-m4_define([mb_version_major], [2])
-m4_define([mb_version_minor], [1])
-m4_define([mb_version_micro], [1])
+m4_define([libmodbus_version_major], [2])
+m4_define([libmodbus_version_minor], [1])
+m4_define([libmodbus_version_micro], [1])
 
-m4_define([mb_release_status],
-            [m4_if(m4_eval(mb_version_minor % 2), [1], [snapshot],
+m4_define([libmodbus_release_status],
+            [m4_if(m4_eval(libmodbus_version_minor % 2), [1], [snapshot],
                [release])])
 
-m4_define([mb_version], [mb_version_major.mb_version_minor.mb_version_micro])
+m4_define([libmodbus_version], [libmodbus_version_major.libmodbus_version_minor.libmodbus_version_micro])
 
 AC_PREREQ(2.63)
-AC_INIT([libmodbus],[mb_version],[stephane.raimbault@gmail.com])
+AC_INIT([libmodbus],[libmodbus_version],[stephane.raimbault@gmail.com])
 AC_CONFIG_SRCDIR([src/modbus.c])
 AC_CONFIG_HEADERS([config.h])
 AM_INIT_AUTOMAKE([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)
+LIBMODBUS_VERSION_MAJOR=libmodbus_version_major
+LIBMODBUS_VERSION_MINOR=libmodbus_version_minor
+LIBMODBUS_VERSION_MICRO=libmodbus_version_micro
+LIBMODBUS_VERSION=libmodbus_version
+AC_SUBST(LIBMODBUS_VERSION_MAJOR)
+AC_SUBST(LIBMODBUS_VERSION_MINOR)
+AC_SUBST(LIBMODBUS_VERSION_MICRO)
+AC_SUBST(LIBMODBUS_VERSION)
 
 # ABI version
-MB_LD_CURRENT=3
-MB_LD_REVISION=0
-MB_LD_AGE=0
-MB_LT_LDFLAGS="-version-info $MB_LD_CURRENT:$MB_LD_REVISION:$MB_LD_AGE"
-AC_SUBST(MB_LT_LDFLAGS)
+LIBMODBUS_LD_CURRENT=3
+LIBMODBUS_LD_REVISION=0
+LIBMODBUS_LD_AGE=0
+LIBMODBUS_LT_LDFLAGS="-version-info $LIBMODBUS_LD_CURRENT:$LIBMODBUS_LD_REVISION:$LIBMODBUS_LD_AGE"
+AC_SUBST(LIBMODBUS_LT_LDFLAGS)
 
 # Checks for programs.
 AC_PROG_CC
@@ -75,7 +75,7 @@ AC_CHECK_FUNCS([gettimeofday inet_ntoa memset select socket strerror])
 AC_CONFIG_FILES([
         Makefile
         src/Makefile
-        src/version.h
+        src/modbus.h
         tests/Makefile
         libmodbus.pc
 ])

+ 5 - 5
src/Makefile.am

@@ -1,11 +1,11 @@
 lib_LTLIBRARIES = libmodbus.la
-libmodbus_la_SOURCES = modbus.c modbus.h version.h
-libmodbus_la_LDFLAGS = $(MB_LT_LDFLAGS)
+libmodbus_la_SOURCES = modbus.c modbus.h
+libmodbus_la_LDFLAGS = $(LIBMODBUS_LT_LDFLAGS)
 
 # Include files to install
 libmodbusincludedir = $(includedir)
-libmodbusinclude_HEADERS = modbus.h version.h
+libmodbusinclude_HEADERS = modbus.h
 
-DISTCLEANFILES = version.h
-EXTRA_DIST = version.h.in
+DISTCLEANFILES = modbus.h
+EXTRA_DIST = modbus.h.in
 CLEANFILES = *~

+ 3 - 3
src/modbus.c

@@ -65,9 +65,9 @@
 #include "modbus.h"
 
 /* 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;
+const unsigned int libmodbus_version_major = LIBMODBUS_VERSION_MAJOR;
+const unsigned int libmodbus_version_minor = LIBMODBUS_VERSION_MINOR;
+const unsigned int libmodbus_version_micro = LIBMODBUS_VERSION_MICRO;
 
 /* This structure reduces the number of params in functions and so
  * optimizes the speed of execution (~ 37%). */

+ 38 - 3
src/modbus.h → src/modbus.h.in

@@ -33,8 +33,6 @@
 #include <netinet/tcp.h>
 #include <arpa/inet.h>
 
-#include <modbus/version.h>
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -157,9 +155,46 @@ enum {
 #define EMBUNKEXC  (EMBXGTAR + 4)
 #define EMBMDATA   (EMBXGTAR + 5)
 
-/* Internal using */
+/* Internal use */
 #define MSG_LENGTH_UNDEFINED -1
 
+/* The major version of libmb, (1, if %LIBMODBUS_VERSION is 1.2.3) */
+#define LIBMODBUS_VERSION_MAJOR (@LIBMODBUS_VERSION_MAJOR@)
+
+/* The minor version of libmb (2, if %LIBMODBUS_VERSION is 1.2.3) */
+#define LIBMODBUS_VERSION_MINOR (@LIBMODBUS_VERSION_MINOR@)
+
+/* The micro version of libmb (3, if %LIBMODBUS_VERSION is 1.2.3) */
+#define LIBMODBUS_VERSION_MICRO (@LIBMODBUS_VERSION_MICRO@)
+
+/* The full version of libmb, like 1.2.3 */
+#define LIBMODBUS_VERSION        @LIBMODBUS_VERSION@
+
+/* The full version of libmb, in string form (suited for
+ * string concatenation)
+ */
+#define LIBMODBUS_VERSION_STRING "@LIBMODBUS_VERSION@"
+
+/* Numerically encoded version libmb, like 0x010203 */
+#define LIBMODBUS_VERSION_HEX ((LIBMODBUS_MAJOR_VERSION << 24) | \
+                               (LIBMODBUS_MINOR_VERSION << 16) | \
+                               (LIBMODBUS_MICRO_VERSION << 8))
+
+/* Evaluates to True if the version of libmb is greater than @major, @minor and
+ * @micro 
+ */
+#define LIBMODBUS_VERSION_CHECK(major,minor,micro) \
+        (LIBMODBUS_VERSION_MAJOR > (major) ||      \
+        (LIBMODBUS_VERSION_MAJOR == (major) &&     \
+         LIBMODBUS_VERSION_MINOR > (minor)) ||     \
+        (LIBMODBUS_VERSION_MAJOR == (major) &&     \
+         LIBMODBUS_VERSION_MINOR == (minor) &&     \
+         LIBMODBUS_VERSION_MICRO >= (micro)))
+
+extern const unsigned int libmodbus_version_major;
+extern const unsigned int libmodbus_version_minor;
+extern const unsigned int libmodbus_version_micro;
+
 typedef enum { RTU=0, TCP } type_com_t;
 
 /* This structure is byte-aligned */

+ 0 - 63
src/version.h.in

@@ -1,63 +0,0 @@
-/*
- * 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_ */

+ 3 - 3
tests/version.c

@@ -20,11 +20,11 @@
 
 int main(void)
 {
-        printf("Compiled with libmodbus version %s\n", MB_VERSION_STRING);
+        printf("Compiled with libmodbus version %s\n", LIBMODBUS_VERSION_STRING);
         printf("Linked with libmodbus version %d.%d.%d\n",
-               mb_version_major, mb_version_minor, mb_version_micro);
+               libmodbus_version_major, libmodbus_version_minor, libmodbus_version_micro);
 
-        if (MB_VERSION_CHECK(2, 1, 0)) {
+        if (LIBMODBUS_VERSION_CHECK(2, 1, 0)) {
                 printf("The functions to read/write float values are available.\n");
         }
         return 0;