Răsfoiți Sursa

Add a windows scripting host configure file.
Simply run cscript configure.js from the win32 directory to generate
the files needed to create the modbus DLL.

oldfaber 13 ani în urmă
părinte
comite
208a337e1d
4 a modificat fișierele cu 366 adăugiri și 9 ștergeri
  1. 8 8
      src/win32/README.win32
  2. 167 0
      src/win32/config.h.win32
  3. 190 0
      src/win32/configure.js
  4. 1 1
      src/win32/modbus.rc

+ 8 - 8
src/win32/README.win32

@@ -1,17 +1,17 @@
 Intro
 -----
 
-This directory contains the project file for Visual Studio 2008 to build a
-modbus.dll.
+
+This directory contains the project file for Visual Studio 2008 to build 
+modbus.dll and the import library modbus.lib.
+
 
 The project file searches for D:/include/msvc_std to find stdint.h.
 See ../../README.md
 
-config.h and modbus-version.h were generated using a Windows native experimental
-port of zsh and Microsoft cl.
-
 
-TODO
-----
+config.h and ../modbus-version.h are generated using configure.js.
+Run 
+    cscript configurs.js
+to generate these files.
 
-Fix the ugly need to have config.h and modbus-version.h in this directory.

+ 167 - 0
src/win32/config.h.win32

@@ -0,0 +1,167 @@
+/* config.h.  Generated from config.h.in by configure.  */
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+/* #undef HAVE_ARPA_INET_H */
+
+/* Define to 1 if you have the declaration of `TIOCSRS485', and to 0 if you
+   don't. */
+/* #undef HAVE_DECL_TIOCSRS485 */
+
+/* Define to 1 if you have the declaration of `__CYGWIN__', and to 0 if you
+   don't. */
+/* #undef HAVE_DECL___CYGWIN__ */
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+/* #undef HAVE_DLFCN_H */
+
+/* Define to 1 if you have the <errno.h> header file. */
+#define HAVE_ERRNO_H 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the `fork' function. */
+/* #undef HAVE_FORK */
+
+/* Define to 1 if you have the `getaddrinfo' function. */
+/* #undef HAVE_GETADDRINFO */
+
+/* Define to 1 if you have the `gettimeofday' function. */
+/* #undef HAVE_GETTIMEOFDAY */
+
+/* Define to 1 if you have the `inet_ntoa' function. */
+/* #undef HAVE_INET_NTOA */
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the <limits.h> header file. */
+#define HAVE_LIMITS_H 1
+
+/* Define to 1 if you have the <linux/serial.h> header file. */
+/* #undef HAVE_LINUX_SERIAL_H */
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `memset' function. */
+#define HAVE_MEMSET 1
+
+/* Define to 1 if you have the <netdb.h> header file. */
+/* #undef HAVE_NETDB_H */
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+/* #undef HAVE_NETINET_IN_H */
+
+/* Define to 1 if you have the <netinet/tcp.h> header file. */
+/* #undef HAVE_NETINET_TCP_H */
+
+/* Define to 1 if you have the `select' function. */
+/* #undef HAVE_SELECT */
+
+/* Define to 1 if you have the `socket' function. */
+/* #undef HAVE_SOCKET */
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `strerror' function. */
+#define HAVE_STRERROR 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+/* #undef HAVE_STRINGS_H */
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the `strlcpy' function. */
+/* #undef HAVE_STRLCPY */
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+/* #undef HAVE_SYS_IOCTL_H */
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+/* #undef HAVE_SYS_SOCKET_H */
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+/* #undef HAVE_SYS_TIME_H */
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <termios.h> header file. */
+/* #undef HAVE_TERMIOS_H */
+
+/* Define to 1 if you have the <time.h> header file. */
+#define HAVE_TIME_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+/* #undef HAVE_UNISTD_H */
+
+/* Define to 1 if you have the `vfork' function. */
+/* #undef HAVE_VFORK */
+
+/* Define to 1 if you have the <vfork.h> header file. */
+/* #undef HAVE_VFORK_H */
+
+/* Define to 1 if you have the <winsock2.h> header file. */
+#define HAVE_WINSOCK2_H 1
+
+/* Define to 1 if `fork' works. */
+/* #undef HAVE_WORKING_FORK */
+
+/* Define to 1 if `vfork' works. */
+/* #undef HAVE_WORKING_VFORK */
+
+/* Define to the sub-directory in which libtool stores uninstalled libraries.
+   */
+/* #undef LT_OBJDIR */
+
+/* Name of package */
+#define PACKAGE "libmodbus"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "https://github.com/stephane/libmodbus/issues"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "libmodbus"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "libmodbus @LIBMODBUS_VERSION@"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "libmodbus"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL ""
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "@LIBMODBUS_VERSION@"
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+/* #undef TIME_WITH_SYS_TIME */
+
+/* Version number of package */
+#define VERSION "@LIBMODBUS_VERSION@"
+
+/* Define to empty if `const' does not conform to ANSI C. */
+/* #undef const */
+
+/* Define to `int' if <sys/types.h> does not define. */
+/* #undef pid_t */
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+/* #undef size_t */
+
+/* Define as `fork' if `vfork' does not work. */
+#define vfork fork

+ 190 - 0
src/win32/configure.js

@@ -0,0 +1,190 @@
+/* Configure script for modbus.dll, specific for Windows with Scripting Host.
+ * 
+ * Inspired by configure.js from libxml2
+ *
+ * oldfaber  < oldfaber _at_ gmail _dot_ com >
+ *
+ */
+
+/* The source directory, relative to the one where this file resides. */
+var srcDir = "..";
+/* Base name of what we are building. */
+var baseName = "modbus";
+/* Configure file template and output file */
+var configFile = srcDir + "\\..\\configure.ac";
+/* Input and output files for the modbus-version.h include */
+var newfile;
+/* Version strings for the binary distribution. Will be filled later in the code. */
+var verMajor;
+var verMinor;
+var verMicro;
+/* modbus features. */
+var testRun = false;
+/* Win32 build options. NOT used yet */
+var compiler = "msvc";
+/* Local stuff */
+var error = 0;
+
+/* Helper function, transforms the option variable into the 'Enabled'
+   or 'Disabled' string. */
+function boolToStr(opt)
+{
+	if (opt == false)
+		return "no";
+	else if (opt == true)
+		return "yes";
+	error = 1;
+	return "*** undefined ***";
+}
+
+/* Helper function, transforms the argument string into a boolean
+   value. */
+function strToBool(opt)
+{
+	if (opt == 0 || opt == "no")
+		return false;
+	else if (opt == 1 || opt == "yes")
+		return true;
+	error = 1;
+	return false;
+}
+
+/* Displays the details about how to use this script. */
+function usage()
+{
+	var txt;
+	txt = "Usage:\n";
+	txt += "  cscript " + WScript.ScriptName + " <options>\n";
+	txt += "  cscript " + WScript.ScriptName + " help\n\n";
+	txt += "Options can be specified in the form <option>=<value>, where the value is\n";
+	txt += "either 'yes' or 'no', if not stated otherwise.\n\n";
+	txt += "\nModbus library configure options, default value given in parentheses:\n\n";
+	txt += "  test-run:  Run configure without creating files (" + (testRun? "yes" : "no")  + ")\n";
+	txt += "\nWin32 build options, default value given in parentheses:\n\n";
+	txt += "  compiler:   Compiler to be used [msvc|mingw|bcb] (" + compiler + ")\n";
+	WScript.Echo(txt);
+}
+
+/* read the version from the configuration file */
+function readVersion()
+{
+	var fso, cf, ln, s;
+	fso = new ActiveXObject("Scripting.FileSystemObject");
+	cf = fso.OpenTextFile(configFile, 1);
+	while (cf.AtEndOfStream != true) {
+		ln = cf.ReadLine();
+		s = new String(ln);
+		if       (s.search(/^m4_define\(\[libmodbus_version_major/) != -1) {
+			verMajor = s.substr(s.indexOf(",") + 3, 1)
+		} else if(s.search(/^m4_define\(\[libmodbus_version_minor/) != -1) {
+			verMinor = s.substr(s.indexOf(",") + 3, 1)
+		} else if(s.search(/^m4_define\(\[libmodbus_version_micro/) != -1) {
+			verMicro = s.substr(s.indexOf(",") + 3, 1)
+		}
+	}
+	cf.Close();
+}
+
+/* create the versioned file */
+function createVersionedFile(newfile, unversioned)
+{
+	var fso, ofi, of, ln, s;
+	fso = new ActiveXObject("Scripting.FileSystemObject");
+	ofi = fso.OpenTextFile(unversioned, 1);
+	if (!testRun) {
+		of = fso.CreateTextFile(newfile, true);
+	}
+	while (ofi.AtEndOfStream != true) {
+		ln = ofi.ReadLine();
+		s = new String(ln);
+		if        (!testRun && s.search(/\@LIBMODBUS_VERSION_MAJOR\@/) != -1) {
+			of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MAJOR\@/, verMajor));
+		} else if (!testRun && s.search(/\@LIBMODBUS_VERSION_MINOR\@/) != -1) {
+			of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MINOR\@/, verMinor));
+		} else if (!testRun && s.search(/\@LIBMODBUS_VERSION_MICRO\@/) != -1) {
+			of.WriteLine(s.replace(/\@LIBMODBUS_VERSION_MICRO\@/, verMicro));
+		} else if (!testRun && s.search(/\@LIBMODBUS_VERSION\@/) != -1) {
+			of.WriteLine(s.replace(/\@LIBMODBUS_VERSION\@/, verMajor+"."+verMinor+"."+verMicro));
+		} else {
+			if (!testRun) 
+				of.WriteLine(ln);
+		}
+	}
+	ofi.Close();
+	if (!testRun) 
+		of.Close();
+}
+
+
+/*
+ * main(),
+ * Execution begins here.
+ */
+
+// Parse the command-line arguments.
+for (i = 0; (i < WScript.Arguments.length) && (error == 0); i++) {
+	var arg, opt;
+	arg = WScript.Arguments(i);
+	opt = arg.substring(0, arg.indexOf("="));
+	if (opt.length == 0)
+		opt = arg.substring(0, arg.indexOf(":"));
+	if (opt.length > 0) {
+		if (opt == "dry-run")
+			testRun = strToBool(arg.substring(opt.length + 1, arg.length));
+		else if (opt == "compiler")
+			compiler = arg.substring(opt.length + 1, arg.length);
+		else
+			error = 1;
+	} else if (i == 0) {
+		if (arg == "help") {
+			usage();
+			WScript.Quit(0);
+		}
+	} else {
+		error = 1;
+	}
+}
+
+
+// If we fail here, it is because the user supplied an unrecognised argument.
+if (error != 0) {
+	usage();
+	WScript.Quit(error);
+}
+
+// Read the the version.
+readVersion();
+if (error != 0) {
+	WScript.Echo("Version discovery failed, aborting.");
+	WScript.Quit(error);
+}
+
+var outVerString = baseName + " version: " + verMajor + "." + verMinor + "." + verMicro;
+// WScript.Echo(outVerString);
+
+newfile = srcDir + "\\modbus-version.h"
+createVersionedFile(newfile, srcDir + "\\modbus-version.h.in");
+if (error != 0) {
+	WScript.Echo("Creation of " + newfile + " failed, aborting.");
+	WScript.Quit(error);
+}
+
+newfile = "modbus.dll.manifest"
+createVersionedFile(newfile, "modbus.dll.manifest.in");
+if (error != 0) {
+	WScript.Echo("Creation of " + newfile + " failed, aborting.");
+	WScript.Quit(error);
+}
+
+newfile = "config.h"
+createVersionedFile(newfile, "config.h.win32");
+if (error != 0) {
+	WScript.Echo("Creation of " + newfile + " failed, aborting.");
+	WScript.Quit(error);
+}
+
+// Display the final configuration. 
+var txtOut = "\nLIBMODBUS configuration completed\n";
+WScript.Echo(txtOut);
+
+

+ 1 - 1
src/win32/modbus.rc

@@ -1,7 +1,7 @@
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include "config.h"
-#include "modbus-version.h"
+#include "../modbus-version.h"
 
 #define VERSTRING PACKAGE_VERSION