Merge pull request #74 from alainmarcel/alainmarcel-patch-1

search paths for builtin.tcl, pkg/, python/
diff --git a/src/API/PythonAPI.cpp b/src/API/PythonAPI.cpp
index 90ee59c..ee445f7 100644
--- a/src/API/PythonAPI.cpp
+++ b/src/API/PythonAPI.cpp
@@ -67,6 +67,8 @@
 
 bool PythonAPI::m_strictMode = false;
 
+std::string PythonAPI::m_builtinPath;
+
 PythonAPI::PythonAPI() {}
 
 PythonAPI::PythonAPI(const PythonAPI& orig) {}
@@ -149,24 +151,19 @@
 
   std::string waivers = m_programPath + "/python/slwaivers.py";
   bool waiverLoaded = loadScript_(waivers);
-
-  const char* home = getenv("HOME");
-  if (home) {
-    waivers = std::string(home) + "/slwaivers.py";
-    waiverLoaded = loadScript_(waivers) || waiverLoaded;
-  }
-
+  waivers =  "/usr/lib/surelog/slwaivers.py";
+  waiverLoaded = loadScript_(waivers) || waiverLoaded;
+  waivers =  "/usr/local/lib/surelog/slwaivers.py";
+  waiverLoaded = loadScript_(waivers) || waiverLoaded;
   waivers = "./slwaivers.py";
   waiverLoaded = loadScript_(waivers) || waiverLoaded;
 
   std::string format = m_programPath + "/python/slformatmsg.py";
   bool messageFormatLoaded = loadScript_(format);
-
-  if (home) {
-    format = std::string(home) + "/slformatmsg.py";
-    messageFormatLoaded = loadScript_(format) || messageFormatLoaded;
-  }
-
+  format = "/usr/lib/surelog/slformatmsg.py";
+  messageFormatLoaded = loadScript_(format) || messageFormatLoaded;
+  format = "/usr/local/lib/surelog/slformatmsg.py";
+  messageFormatLoaded = loadScript_(format) || messageFormatLoaded;
   format = "./slformatmsg.py";
   messageFormatLoaded = loadScript_(format) || messageFormatLoaded;
 
@@ -182,22 +179,28 @@
     if (FileUtils::fileExists(listener)) m_listenerScript = listener;
     m_listenerLoaded = loadScript_(listener);
 
-    if (home) {
-      listener = std::string(home) + "/slSV3_1aPythonListener.py";
-      if (FileUtils::fileExists(listener)) m_listenerScript = listener;
-      m_listenerLoaded = loadScript_(listener) || m_listenerLoaded;
-    }
-
+    listener = "/usr/lib/surelog/slSV3_1aPythonListener.py";
+    if (FileUtils::fileExists(listener)) m_listenerScript = listener;
+    m_listenerLoaded = loadScript_(listener) || m_listenerLoaded;
+    listener = "/usr/local/lib/surelog/slSV3_1aPythonListener.py";
+    if (FileUtils::fileExists(listener)) m_listenerScript = listener;
+    m_listenerLoaded = loadScript_(listener) || m_listenerLoaded;
     listener = "./slSV3_1aPythonListener.py";
     if (FileUtils::fileExists(listener)) m_listenerScript = listener;
     m_listenerLoaded = loadScript_(listener) || m_listenerLoaded;
   }
 }
 
-void PythonAPI::init(const char** argv) {
+void PythonAPI::init(int argc, const char** argv) {
   m_programPath = argv[0];
   m_programPath = StringUtils::rtrim(m_programPath, '/');
-
+  for (int i = 1; i < argc; i++) {
+      if (!strcmp(argv[i], "-builtin")) {
+          if (i < argc - 1) {
+            m_builtinPath = argv[i + 1];
+          }
+      } 
+  }
   Py_SetProgramName((wchar_t*)argv[0]); /* optional but recommended */
 
   PyImport_AppendInittab("slapi", &PyInit_slapi);
diff --git a/src/API/PythonAPI.h b/src/API/PythonAPI.h
index 74ac368..236513a 100644
--- a/src/API/PythonAPI.h
+++ b/src/API/PythonAPI.h
@@ -37,7 +37,7 @@
   PythonAPI(const PythonAPI& orig);
   virtual ~PythonAPI();
   /* Main interpreter (in main thread) */
-  static void init(const char** argv);
+  static void init(int argc, const char** argv);
   static void shutdown();
   static PyThreadState* getMainInterp() { return m_mainThreadState; }
 
@@ -71,6 +71,7 @@
   static bool m_listenerLoaded;
   static std::string m_listenerScript;
   static bool m_strictMode;
+  static std::string m_builtinPath;
 };
 
 };  // namespace SURELOG
diff --git a/src/CommandLine/CommandLineParser.cpp b/src/CommandLine/CommandLineParser.cpp
index b5f57d5..9b7e855 100644
--- a/src/CommandLine/CommandLineParser.cpp
+++ b/src/CommandLine/CommandLineParser.cpp
@@ -145,7 +145,8 @@
     "  -noinfo               Filters out INFO messages",
     "  -nonote               Filters out NOTE messages",
     "  -nowarning            Filters out WARNING messages",
-    "  -o <path>             Turns on all compilation stages, produces all "
+    "  -o <path>             Turns on all compilation stages, produces all ",
+    "  -builtin <path>       Alternative path to builtin.sv, python/ and pkg/ dirs",        
     "outputs under that path",
     "  --help               This help",
     "  --version            Surelog version"
@@ -354,13 +355,33 @@
   std::string exe_name = argv[0];
   std::string exe_path = FileUtils::getPathName(exe_name);
   m_precompiledDirId = m_symbolTable->registerSymbol(exe_path + "pkg/");
+  if (!FileUtils::fileExists(exe_path + "pkg/")) {
+    if (FileUtils::fileExists("/usr/lib/surelog/pkg/")) {
+      m_precompiledDirId = m_symbolTable->registerSymbol("/usr/lib/surelog/pkg/");   
+    }
+  if (FileUtils::fileExists("/usr/local/lib/surelog/pkg/")) {
+      m_precompiledDirId = m_symbolTable->registerSymbol("/usr/local/lib/surelog/pkg/");   
+    }
+  }
+  
   std::string built_in_verilog = exe_path + "/sv/builtin.sv";
+  if (!FileUtils::fileExists(built_in_verilog)) {
+    built_in_verilog = "/usr/lib/surelog/sv/builtin.sv";
+    if (!FileUtils::fileExists("/usr/lib/surelog/sv/builtin.sv")) {
+      built_in_verilog = "/usr/local/lib/surelog/sv/builtin.sv";   
+    }
+  }
+  
   std::vector<std::string> all_arguments;
   std::vector<std::string> cmd_line;
   for (int i = 1; i < argc; i++) {
     cmd_line.push_back(argv[i]);
-
-      if (!strcmp (argv[i], "-l"))
+      if (!strcmp(argv[i], "-builtin")) {
+          if (i < argc - 1) {
+            m_builtinPath = argv[i + 1];
+            built_in_verilog = m_builtinPath + "/builtin.sv";
+          }
+      } else if (!strcmp (argv[i], "-l"))
         {
           if (i < argc - 1)
             {
diff --git a/src/CommandLine/CommandLineParser.hpp b/src/CommandLine/CommandLineParser.hpp
index 7121567..7ebe7bd 100644
--- a/src/CommandLine/CommandLineParser.hpp
+++ b/src/CommandLine/CommandLineParser.hpp
@@ -122,7 +122,7 @@
   bool createCache() { return m_createCache; }
   const std::string currentDateTime();
   bool parseBuiltIn();
-
+  std::string getBuiltInPath() { return m_builtinPath; }
  private:
   bool plus_arguments_(const std::string& s);
   void processArgs_(std::vector<std::string>& args,
@@ -199,6 +199,7 @@
   bool m_parseBuiltIn;
   bool m_ppOutputFileLocation;
   bool m_logFileSpecified;
+  std::string m_builtinPath;
 };
 
 };  // namespace SURELOG
diff --git a/src/main.cpp b/src/main.cpp
index 7856bf7..d9efe97 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -106,7 +106,7 @@
     }
   
   if (python_mode)
-    SURELOG::PythonAPI::init(argv);
+    SURELOG::PythonAPI::init(argc, argv);
   
   if (diff_comp_mode == true)
     {