Commit 93ce13656103cbb459ebd630d055a008dbb059f3

Authored by Stéphane Raimbault
1 parent 4a38de0a

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.
.gitignore
@@ -20,7 +20,7 @@ libtool @@ -20,7 +20,7 @@ libtool
20 ltmain.sh 20 ltmain.sh
21 missing 21 missing
22 libmodbus.pc 22 libmodbus.pc
23 -version.h 23 +modbus.h
24 .deps 24 .deps
25 .libs 25 .libs
26 *.la 26 *.la
@@ -34,4 +34,4 @@ tests/random-test-master @@ -34,4 +34,4 @@ tests/random-test-master
34 tests/random-test-slave 34 tests/random-test-slave
35 tests/unit-test-master 35 tests/unit-test-master
36 tests/unit-test-slave 36 tests/unit-test-slave
37 -tests/version  
38 \ No newline at end of file 37 \ No newline at end of file
  38 +tests/version
configure.ac
@@ -3,47 +3,47 @@ @@ -3,47 +3,47 @@
3 # An even micro number indicates a released version 3 # An even micro number indicates a released version
4 # 4 #
5 # Making a point release: 5 # Making a point release:
6 -# - increase mb_version_micro to the next even number 6 +# - increase libmodbus_version_micro to the next even number
7 # 7 #
8 # After the release: 8 # After the release:
9 -# - increase mb_version_minor to the next odd number 9 +# - increase libmodbus_version_minor to the next odd number
10 # 10 #
11 -# Take care to update the libtool versioning when required (MB_LD_*). 11 +# Take care to update the libtool versioning when required (LIBMODBUS_LD_*).
12 # http://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html 12 # http://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
13 # 13 #
14 -m4_define([mb_version_major], [2])  
15 -m4_define([mb_version_minor], [1])  
16 -m4_define([mb_version_micro], [1]) 14 +m4_define([libmodbus_version_major], [2])
  15 +m4_define([libmodbus_version_minor], [1])
  16 +m4_define([libmodbus_version_micro], [1])
17 17
18 -m4_define([mb_release_status],  
19 - [m4_if(m4_eval(mb_version_minor % 2), [1], [snapshot], 18 +m4_define([libmodbus_release_status],
  19 + [m4_if(m4_eval(libmodbus_version_minor % 2), [1], [snapshot],
20 [release])]) 20 [release])])
21 21
22 -m4_define([mb_version], [mb_version_major.mb_version_minor.mb_version_micro]) 22 +m4_define([libmodbus_version], [libmodbus_version_major.libmodbus_version_minor.libmodbus_version_micro])
23 23
24 AC_PREREQ(2.63) 24 AC_PREREQ(2.63)
25 -AC_INIT([libmodbus],[mb_version],[stephane.raimbault@gmail.com]) 25 +AC_INIT([libmodbus],[libmodbus_version],[stephane.raimbault@gmail.com])
26 AC_CONFIG_SRCDIR([src/modbus.c]) 26 AC_CONFIG_SRCDIR([src/modbus.c])
27 AC_CONFIG_HEADERS([config.h]) 27 AC_CONFIG_HEADERS([config.h])
28 AM_INIT_AUTOMAKE([foreign]) 28 AM_INIT_AUTOMAKE([foreign])
29 # enable nice build output on automake1.11 29 # enable nice build output on automake1.11
30 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) 30 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
31 31
32 -MB_VERSION_MAJOR=mb_version_major  
33 -MB_VERSION_MINOR=mb_version_minor  
34 -MB_VERSION_MICRO=mb_version_micro  
35 -MB_VERSION=mb_version  
36 -AC_SUBST(MB_VERSION_MAJOR)  
37 -AC_SUBST(MB_VERSION_MINOR)  
38 -AC_SUBST(MB_VERSION_MICRO)  
39 -AC_SUBST(MB_VERSION) 32 +LIBMODBUS_VERSION_MAJOR=libmodbus_version_major
  33 +LIBMODBUS_VERSION_MINOR=libmodbus_version_minor
  34 +LIBMODBUS_VERSION_MICRO=libmodbus_version_micro
  35 +LIBMODBUS_VERSION=libmodbus_version
  36 +AC_SUBST(LIBMODBUS_VERSION_MAJOR)
  37 +AC_SUBST(LIBMODBUS_VERSION_MINOR)
  38 +AC_SUBST(LIBMODBUS_VERSION_MICRO)
  39 +AC_SUBST(LIBMODBUS_VERSION)
40 40
41 # ABI version 41 # ABI version
42 -MB_LD_CURRENT=3  
43 -MB_LD_REVISION=0  
44 -MB_LD_AGE=0  
45 -MB_LT_LDFLAGS="-version-info $MB_LD_CURRENT:$MB_LD_REVISION:$MB_LD_AGE"  
46 -AC_SUBST(MB_LT_LDFLAGS) 42 +LIBMODBUS_LD_CURRENT=3
  43 +LIBMODBUS_LD_REVISION=0
  44 +LIBMODBUS_LD_AGE=0
  45 +LIBMODBUS_LT_LDFLAGS="-version-info $LIBMODBUS_LD_CURRENT:$LIBMODBUS_LD_REVISION:$LIBMODBUS_LD_AGE"
  46 +AC_SUBST(LIBMODBUS_LT_LDFLAGS)
47 47
48 # Checks for programs. 48 # Checks for programs.
49 AC_PROG_CC 49 AC_PROG_CC
@@ -75,7 +75,7 @@ AC_CHECK_FUNCS([gettimeofday inet_ntoa memset select socket strerror]) @@ -75,7 +75,7 @@ AC_CHECK_FUNCS([gettimeofday inet_ntoa memset select socket strerror])
75 AC_CONFIG_FILES([ 75 AC_CONFIG_FILES([
76 Makefile 76 Makefile
77 src/Makefile 77 src/Makefile
78 - src/version.h 78 + src/modbus.h
79 tests/Makefile 79 tests/Makefile
80 libmodbus.pc 80 libmodbus.pc
81 ]) 81 ])
src/Makefile.am
1 lib_LTLIBRARIES = libmodbus.la 1 lib_LTLIBRARIES = libmodbus.la
2 -libmodbus_la_SOURCES = modbus.c modbus.h version.h  
3 -libmodbus_la_LDFLAGS = $(MB_LT_LDFLAGS) 2 +libmodbus_la_SOURCES = modbus.c modbus.h
  3 +libmodbus_la_LDFLAGS = $(LIBMODBUS_LT_LDFLAGS)
4 4
5 # Include files to install 5 # Include files to install
6 libmodbusincludedir = $(includedir) 6 libmodbusincludedir = $(includedir)
7 -libmodbusinclude_HEADERS = modbus.h version.h 7 +libmodbusinclude_HEADERS = modbus.h
8 8
9 -DISTCLEANFILES = version.h  
10 -EXTRA_DIST = version.h.in 9 +DISTCLEANFILES = modbus.h
  10 +EXTRA_DIST = modbus.h.in
11 CLEANFILES = *~ 11 CLEANFILES = *~
src/modbus.c
@@ -65,9 +65,9 @@ @@ -65,9 +65,9 @@
65 #include "modbus.h" 65 #include "modbus.h"
66 66
67 /* Exported version */ 67 /* Exported version */
68 -const unsigned int mb_version_major = MB_VERSION_MAJOR;  
69 -const unsigned int mb_version_minor = MB_VERSION_MINOR;  
70 -const unsigned int mb_version_micro = MB_VERSION_MICRO; 68 +const unsigned int libmodbus_version_major = LIBMODBUS_VERSION_MAJOR;
  69 +const unsigned int libmodbus_version_minor = LIBMODBUS_VERSION_MINOR;
  70 +const unsigned int libmodbus_version_micro = LIBMODBUS_VERSION_MICRO;
71 71
72 /* This structure reduces the number of params in functions and so 72 /* This structure reduces the number of params in functions and so
73 * optimizes the speed of execution (~ 37%). */ 73 * optimizes the speed of execution (~ 37%). */
src/modbus.h renamed to src/modbus.h.in
@@ -33,8 +33,6 @@ @@ -33,8 +33,6 @@
33 #include <netinet/tcp.h> 33 #include <netinet/tcp.h>
34 #include <arpa/inet.h> 34 #include <arpa/inet.h>
35 35
36 -#include <modbus/version.h>  
37 -  
38 #ifdef __cplusplus 36 #ifdef __cplusplus
39 extern "C" { 37 extern "C" {
40 #endif 38 #endif
@@ -157,9 +155,46 @@ enum { @@ -157,9 +155,46 @@ enum {
157 #define EMBUNKEXC (EMBXGTAR + 4) 155 #define EMBUNKEXC (EMBXGTAR + 4)
158 #define EMBMDATA (EMBXGTAR + 5) 156 #define EMBMDATA (EMBXGTAR + 5)
159 157
160 -/* Internal using */ 158 +/* Internal use */
161 #define MSG_LENGTH_UNDEFINED -1 159 #define MSG_LENGTH_UNDEFINED -1
162 160
  161 +/* The major version of libmb, (1, if %LIBMODBUS_VERSION is 1.2.3) */
  162 +#define LIBMODBUS_VERSION_MAJOR (@LIBMODBUS_VERSION_MAJOR@)
  163 +
  164 +/* The minor version of libmb (2, if %LIBMODBUS_VERSION is 1.2.3) */
  165 +#define LIBMODBUS_VERSION_MINOR (@LIBMODBUS_VERSION_MINOR@)
  166 +
  167 +/* The micro version of libmb (3, if %LIBMODBUS_VERSION is 1.2.3) */
  168 +#define LIBMODBUS_VERSION_MICRO (@LIBMODBUS_VERSION_MICRO@)
  169 +
  170 +/* The full version of libmb, like 1.2.3 */
  171 +#define LIBMODBUS_VERSION @LIBMODBUS_VERSION@
  172 +
  173 +/* The full version of libmb, in string form (suited for
  174 + * string concatenation)
  175 + */
  176 +#define LIBMODBUS_VERSION_STRING "@LIBMODBUS_VERSION@"
  177 +
  178 +/* Numerically encoded version libmb, like 0x010203 */
  179 +#define LIBMODBUS_VERSION_HEX ((LIBMODBUS_MAJOR_VERSION << 24) | \
  180 + (LIBMODBUS_MINOR_VERSION << 16) | \
  181 + (LIBMODBUS_MICRO_VERSION << 8))
  182 +
  183 +/* Evaluates to True if the version of libmb is greater than @major, @minor and
  184 + * @micro
  185 + */
  186 +#define LIBMODBUS_VERSION_CHECK(major,minor,micro) \
  187 + (LIBMODBUS_VERSION_MAJOR > (major) || \
  188 + (LIBMODBUS_VERSION_MAJOR == (major) && \
  189 + LIBMODBUS_VERSION_MINOR > (minor)) || \
  190 + (LIBMODBUS_VERSION_MAJOR == (major) && \
  191 + LIBMODBUS_VERSION_MINOR == (minor) && \
  192 + LIBMODBUS_VERSION_MICRO >= (micro)))
  193 +
  194 +extern const unsigned int libmodbus_version_major;
  195 +extern const unsigned int libmodbus_version_minor;
  196 +extern const unsigned int libmodbus_version_micro;
  197 +
163 typedef enum { RTU=0, TCP } type_com_t; 198 typedef enum { RTU=0, TCP } type_com_t;
164 199
165 /* This structure is byte-aligned */ 200 /* This structure is byte-aligned */
src/version.h.in deleted
1 -/*  
2 - * Copyright © 2010 Stéphane Raimbault <stephane.raimbault@gmail.com>  
3 - *  
4 - * This program is free software: you can redistribute it and/or modify  
5 - * it under the terms of the GNU Lesser Public License as published by  
6 - * the Free Software Foundation; either version 3 of the License, or  
7 - * (at your option) any later version.  
8 - *  
9 - * This program is distributed in the hope that it will be useful,  
10 - * but WITHOUT ANY WARRANTY; without even the implied warranty of  
11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
12 - * GNU Lesser Public License for more details.  
13 - *  
14 - * You should have received a copy of the GNU Lesser Public License  
15 - * along with this program. If not, see <http://www.gnu.org/licenses/>.  
16 - */  
17 -  
18 -#ifndef _MB_VERSION_H_  
19 -#define _MB_VERSION_H_  
20 -  
21 -#ifdef __cplusplus  
22 -extern "C" {  
23 -#endif  
24 -  
25 -/* The major version of libmb, (1, if %MB_VERSION is 1.2.3) */  
26 -#define MB_VERSION_MAJOR (@MB_VERSION_MAJOR@)  
27 -  
28 -/* The minor version of libmb (2, if %MB_VERSION is 1.2.3) */  
29 -#define MB_VERSION_MINOR (@MB_VERSION_MINOR@)  
30 -  
31 -/* The micro version of libmb (3, if %MB_VERSION is 1.2.3) */  
32 -#define MB_VERSION_MICRO (@MB_VERSION_MICRO@)  
33 -  
34 -/* The full version of libmb, like 1.2.3 */  
35 -#define MB_VERSION @MB_VERSION@  
36 -  
37 -/* The full version of libmb, in string form (suited for  
38 - * string concatenation)  
39 - */  
40 -#define MB_VERSION_STRING "@MB_VERSION@"  
41 -  
42 -/* Numerically encoded version libmb, like 0x010203 */  
43 -#define MB_VERSION_HEX ((MB_MAJOR_VERSION << 24) | \  
44 - (MB_MINOR_VERSION << 16) | \  
45 - (MB_MICRO_VERSION << 8))  
46 -  
47 -/* Evaluates to True if the version of libmb is greater than @major, @minor  
48 - * and @micro  
49 - */  
50 -#define MB_VERSION_CHECK(major,minor,micro) \  
51 - (MB_VERSION_MAJOR > (major) || \  
52 - (MB_VERSION_MAJOR == (major) && MB_VERSION_MINOR > (minor)) || \  
53 - (MB_VERSION_MAJOR == (major) && MB_VERSION_MINOR == (minor) && MB_VERSION_MICRO >= (micro)))  
54 -  
55 -extern const unsigned int mb_version_major;  
56 -extern const unsigned int mb_version_minor;  
57 -extern const unsigned int mb_version_micro;  
58 -  
59 -#ifdef __cplusplus  
60 -}  
61 -#endif  
62 -  
63 -#endif /* _MB_VERSION_H_ */  
tests/version.c
@@ -20,11 +20,11 @@ @@ -20,11 +20,11 @@
20 20
21 int main(void) 21 int main(void)
22 { 22 {
23 - printf("Compiled with libmodbus version %s\n", MB_VERSION_STRING); 23 + printf("Compiled with libmodbus version %s\n", LIBMODBUS_VERSION_STRING);
24 printf("Linked with libmodbus version %d.%d.%d\n", 24 printf("Linked with libmodbus version %d.%d.%d\n",
25 - mb_version_major, mb_version_minor, mb_version_micro); 25 + libmodbus_version_major, libmodbus_version_minor, libmodbus_version_micro);
26 26
27 - if (MB_VERSION_CHECK(2, 1, 0)) { 27 + if (LIBMODBUS_VERSION_CHECK(2, 1, 0)) {
28 printf("The functions to read/write float values are available.\n"); 28 printf("The functions to read/write float values are available.\n");
29 } 29 }
30 return 0; 30 return 0;