automatically detect flags supported by matiec and find correct path
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 06 May 2016 19:14:10 +0300
changeset 1515 da8bf5aa275f
parent 1514 968e7898d66b
child 1516 9db0b436fbb3
automatically detect flags supported by matiec and find correct path
for matiec C library files

This makes possible to use an old matiec and the new one.
ProjectController.py
--- a/ProjectController.py	Fri May 06 18:04:40 2016 +0300
+++ b/ProjectController.py	Fri May 06 19:14:10 2016 +0300
@@ -141,7 +141,7 @@
 
         self.iec2c_path = os.path.join(base_folder, "matiec", "iec2c"+(".exe" if wx.Platform == '__WXMSW__' else ""))
         self.ieclib_path = os.path.join(base_folder, "matiec", "lib")
-        self.ieclib_c_path = os.path.join(base_folder, "matiec", "lib", "C")
+        self.ieclib_c_path = self._getMatIecCPath()
 
         # Setup debug information
         self.IECdebug_datas = {}
@@ -629,11 +629,43 @@
         plc_file.close()
         return True
 
+
+    def _getMatIecCPath(self):
+        path=''
+        paths=[
+            os.path.join(base_folder, "matiec", "lib", "C"),
+            os.path.join(base_folder, "matiec", "lib") ]
+        for p in paths:
+            filename=os.path.join(p, "iec_types.h")
+            if (os.path.isfile(filename)):
+                path = p
+                break
+        return path
+
+    def _getMatIecOptions(self):
+        buildpath = self._getBuildPath()
+        buildcmd = "\"%s\" -h"%(self.iec2c_path)
+        options =["-f", "-l", "-p"]
+
+        buildopt = ""
+        try:
+            # Invoke compiler. Output files are listed to stdout, errors to stderr
+            status, result, err_result = ProcessLogger(self.logger, buildcmd,
+                no_stdout=True, no_stderr=True).spin()
+        except Exception,e:
+            return buildopt
+
+        for opt in options:
+            if opt in result:
+                buildopt = buildopt + " " + opt
+        return buildopt
+
     def _Compile_ST_to_SoftPLC(self):
         self.logger.write(_("Compiling IEC Program into C code...\n"))
         buildpath = self._getBuildPath()
-        buildcmd = "\"%s\" -f -l -p -I \"%s\" -T \"%s\" \"%s\""%(
+        buildcmd = "\"%s\" %s -I \"%s\" -T \"%s\" \"%s\""%(
                          self.iec2c_path,
+                         self._getMatIecOptions(),
                          self.ieclib_path,
                          buildpath,
                          self._getIECcodepath())