Revision: 77585
          http://sourceforge.net/p/brlcad/code/77585
Author:   starseeker
Date:     2020-10-23 02:51:54 +0000 (Fri, 23 Oct 2020)
Log Message:
-----------
Add utilities

Added Paths:
-----------
    brlcad/branches/extbuild/src/other/ext/CMake/buildpath_replace.cxx.in
    brlcad/branches/extbuild/src/other/ext/CMake/rpath_replace.cxx.in
    brlcad/branches/extbuild/src/other/ext/CMake/tcl_replace.cxx.in

Added: brlcad/branches/extbuild/src/other/ext/CMake/buildpath_replace.cxx.in
===================================================================
--- brlcad/branches/extbuild/src/other/ext/CMake/buildpath_replace.cxx.in       
                        (rev 0)
+++ brlcad/branches/extbuild/src/other/ext/CMake/buildpath_replace.cxx.in       
2020-10-23 02:51:54 UTC (rev 77585)
@@ -0,0 +1,62 @@
+#include <cstdio>
+#include <fstream>
+#include <iostream>
+#include <regex>
+#include <string>
+
+int main(int argc, const char **argv)
+{
+    int verbose = @EXTPROJ_VERBOSE@;
+    std::smatch m;
+    std::string build_path("@CMAKE_BINARY_DIR@");
+    std::string install_path = std::string("@CMAKE_INSTALL_PREFIX@");
+
+    // Because the input path might be anything, we need to quote it for
+    // processing - see https://stackoverflow.com/a/40195721
+    std::regex schars { R"([-[\]{}()*+?.,\^$|#\s])" };
+    std::string bp_sanetized = std::regex_replace(build_path, schars, 
R"(\$&)");
+    std::regex build_path_regex(bp_sanetized);
+
+    if (argc < 1) {
+       std::cerr << "Error: no file specified for processing.\n";
+       return -1;
+    }
+
+    for (int i = 1; i < argc; i++) {
+       std::string cline;
+       std::string nfile_contents;
+       std::ifstream fs;
+       fs.open(argv[i]);
+       if (!fs.is_open()) {
+           std::cerr << "Error: file " << argv[i] << " could not be opened.\n";
+           return -1;
+       } else {
+           std::cerr << "-- Patching " << argv[i] << "\n";
+       }
+
+       while (std::getline(fs, cline)) {
+           std::string nline = std::regex_replace(cline, build_path_regex, 
install_path);
+           nfile_contents.append(nline);
+           nfile_contents.append("\n");
+           if (nline != cline && verbose > 1) {
+               std::cerr << "   Changed line: " << cline << " -> " << nline << 
"\n";
+           }
+       }
+
+       fs.close();
+
+       std::ofstream ofs(argv[i], std::ios::trunc);
+       ofs << nfile_contents;
+       ofs.close();
+    }
+}
+
+// Local Variables:
+// tab-width: 8
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: t
+// c-file-style: "stroustrup"
+// End:
+// ex: shiftwidth=4 tabstop=8
+


Property changes on: 
brlcad/branches/extbuild/src/other/ext/CMake/buildpath_replace.cxx.in
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: brlcad/branches/extbuild/src/other/ext/CMake/rpath_replace.cxx.in
===================================================================
--- brlcad/branches/extbuild/src/other/ext/CMake/rpath_replace.cxx.in           
                (rev 0)
+++ brlcad/branches/extbuild/src/other/ext/CMake/rpath_replace.cxx.in   
2020-10-23 02:51:54 UTC (rev 77585)
@@ -0,0 +1,58 @@
+#include <cstdio>
+#include <fstream>
+#include <iostream>
+#include <regex>
+#include <string>
+
+int main(int argc, const char **argv)
+{
+    int verbose = @EXTPROJ_VERBOSE@;
+    std::regex old_rpath("-rpath,\\$\\{LIB_RUNTIME_DIR\\}");
+    if (argc < 3) {
+       std::cerr << "Error: no file specified for processing or missing RPATH 
to set.\n";
+       return -1;
+    }
+    std::string new_rpath = std::string("-rpath,") + std::string(argv[1]);
+
+    for (int i = 2; i < argc; i++) {
+       std::string cline;
+       std::string nfile_contents;
+       std::ifstream fs;
+       fs.open(argv[i]);
+       if (!fs.is_open()) {
+           std::cerr << "Error: file " << argv[i] << " could not be opened.\n";
+           return -1;
+       } else {
+           if (verbose) {
+               std::cerr << "Patching " << argv[i] << "\n";
+           }
+       }
+
+       while (std::getline(fs, cline)) {
+           std::string nline = std::regex_replace(cline, old_rpath, new_rpath);
+           nfile_contents.append(nline);
+           nfile_contents.append("\n");
+           if (nline != cline) {
+               if (verbose > 1) {
+                   std::cerr << "   Changed line: " << cline << " -> " << 
nline << "\n";
+               }
+           }
+       }
+
+       fs.close();
+
+       std::ofstream ofs(argv[i], std::ios::trunc);
+       ofs << nfile_contents;
+       ofs.close();
+    }
+}
+
+// Local Variables:
+// tab-width: 8
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: t
+// c-file-style: "stroustrup"
+// End:
+// ex: shiftwidth=4 tabstop=8
+


Property changes on: 
brlcad/branches/extbuild/src/other/ext/CMake/rpath_replace.cxx.in
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: brlcad/branches/extbuild/src/other/ext/CMake/tcl_replace.cxx.in
===================================================================
--- brlcad/branches/extbuild/src/other/ext/CMake/tcl_replace.cxx.in             
                (rev 0)
+++ brlcad/branches/extbuild/src/other/ext/CMake/tcl_replace.cxx.in     
2020-10-23 02:51:54 UTC (rev 77585)
@@ -0,0 +1,158 @@
+#include <cstdio>
+#include <fstream>
+#include <iostream>
+#include <regex>
+#include <string>
+#include <vector>
+
+static const char *sep = "/";
+static const char *CMAKE_INSTALL_PREFIX = "@CMAKE_INSTALL_PREFIX@";
+static const char *LIB_DIR = "@LIB_DIR@";
+static const char *BIN_DIR = "@BIN_DIR@";
+static const char *INCLUDE_DIR = "@INCLUDE_DIR@";
+static const char *MAN_DIR = "@MAN_DIR@";
+static const char *PKG_DIR = "tcl8.@TCL_MINOR_VERSION@";
+static const char *TKTABLE_RUNTIME_DIR = "Tktable@TKTABLE_VERSION@";
+
+static const char *ZLIB_NAME = "@ZLIB_NAME@";
+static const char *DEFLATE_NAME = "@DEFLATE_NAME@";
+
+int main(int argc, const char **argv)
+{
+    int verbose = 1;
+    if (argc < 2) {
+       std::cerr << "Error: no file specified for processing or missing RPATH 
to set.\n";
+       return -1;
+    }
+
+    std::vector<std::regex> regexes;
+    std::vector<std::string> strings;
+
+    std::regex tcllib_regex("sizeof[(]TCL_LIBRARY[)]");
+    regexes.push_back(tcllib_regex);
+    std::string tcllib_new  = std::string("sizeof(\"") + 
std::string(CMAKE_INSTALL_PREFIX) + std::string(sep) + std::string(LIB_DIR) + 
std::string("\")");
+    strings.push_back(tcllib_new);
+
+    std::regex tcllib2_regex("= TCL_LIBRARY;");
+    regexes.push_back(tcllib2_regex);
+    std::string tcllib2_new  = std::string("= \"") + 
std::string(CMAKE_INSTALL_PREFIX) + std::string(sep) + std::string(LIB_DIR) + 
std::string("\";");
+    strings.push_back(tcllib2_new);
+
+    std::regex tclpkg_regex("TCL_PACKAGE_PATH");
+    regexes.push_back(tclpkg_regex);
+    std::string tclpkg_new  = std::string("\"") + 
std::string(CMAKE_INSTALL_PREFIX) + std::string(sep) + std::string(LIB_DIR) + 
std::string(sep) + std::string(PKG_DIR) + std::string("\"");
+    strings.push_back(tclpkg_new);
+
+    std::regex run_libdir_regex("CFG_RUNTIME_LIBDIR");
+    regexes.push_back(run_libdir_regex);
+    std::string run_libdir_new  = std::string("\"") + 
std::string(CMAKE_INSTALL_PREFIX) + std::string(sep) + std::string(LIB_DIR) + 
std::string("\"");
+    strings.push_back(run_libdir_new);
+
+    std::regex run_bindir_regex("CFG_RUNTIME_BINDIR");
+    regexes.push_back(run_bindir_regex);
+    std::string run_bindir_new  = std::string("\"") + 
std::string(CMAKE_INSTALL_PREFIX) + std::string(sep) + std::string(BIN_DIR) + 
std::string("\"");
+    strings.push_back(run_bindir_new);
+
+    std::regex run_srcdir_regex("CFG_RUNTIME_SCRDIR");
+    regexes.push_back(run_srcdir_regex);
+    std::string run_srcdir_new  = std::string("\"") + 
std::string(CMAKE_INSTALL_PREFIX) + std::string(sep) + std::string(LIB_DIR) + 
std::string(sep) + std::string(PKG_DIR) + std::string("\"");
+    strings.push_back(run_srcdir_new);
+
+    std::regex run_incdir_regex("CFG_RUNTIME_INCDIR");
+    regexes.push_back(run_incdir_regex);
+    std::string run_incdir_new  = std::string("\"") + 
std::string(CMAKE_INSTALL_PREFIX) + std::string(sep) + std::string(INCLUDE_DIR) 
+ std::string("\"");
+    strings.push_back(run_incdir_new);
+
+    std::regex run_mandir_regex("CFG_RUNTIME_DOCDIR");
+    regexes.push_back(run_mandir_regex);
+    std::string run_mandir_new  = std::string("\"") + 
std::string(CMAKE_INSTALL_PREFIX) + std::string(sep) + std::string(MAN_DIR) + 
std::string("\"");
+    strings.push_back(run_mandir_new);
+
+    std::regex inst_libdir_regex("CFG_INSTALL_LIBDIR");
+    regexes.push_back(inst_libdir_regex);
+    std::string inst_libdir_new  = std::string("\"") + 
std::string(CMAKE_INSTALL_PREFIX) + std::string(sep) + std::string(LIB_DIR) + 
std::string("\"");
+    strings.push_back(inst_libdir_new);
+
+    std::regex inst_bindir_regex("CFG_INSTALL_BINDIR");
+    regexes.push_back(inst_bindir_regex);
+    std::string inst_bindir_new  = std::string("\"") + 
std::string(CMAKE_INSTALL_PREFIX) + std::string(sep) + std::string(BIN_DIR) + 
std::string("\"");
+    strings.push_back(inst_bindir_new);
+
+    std::regex inst_srcdir_regex("CFG_INSTALL_SCRDIR");
+    regexes.push_back(inst_srcdir_regex);
+    std::string inst_srcdir_new  = std::string("\"") + 
std::string(CMAKE_INSTALL_PREFIX) + std::string(sep) + std::string(LIB_DIR) + 
std::string(sep) + std::string(PKG_DIR) + std::string("\"");
+    strings.push_back(inst_srcdir_new);
+
+    std::regex inst_incdir_regex("CFG_INSTALL_INCDIR");
+    regexes.push_back(inst_incdir_regex);
+    std::string inst_incdir_new  = std::string("\"") + 
std::string(CMAKE_INSTALL_PREFIX) + std::string(sep) + std::string(INCLUDE_DIR) 
+ std::string("\"");
+    strings.push_back(inst_incdir_new);
+
+    std::regex inst_mandir_regex("CFG_INSTALL_DOCDIR");
+    regexes.push_back(inst_mandir_regex);
+    std::string inst_mandir_new  = std::string("\"") + 
std::string(CMAKE_INSTALL_PREFIX) + std::string(sep) + std::string(MAN_DIR) + 
std::string("\"");
+    strings.push_back(inst_mandir_new);
+
+    std::regex tbl_runtimedir_regex("TBL_RUNTIME_DIR");
+    regexes.push_back(tbl_runtimedir_regex);
+    std::string tbl_runtimedir_new  = std::string("\"") + 
std::string(CMAKE_INSTALL_PREFIX) + std::string(sep) + std::string(LIB_DIR) + 
std::string(TKTABLE_RUNTIME_DIR) + std::string("\"");
+    strings.push_back(tbl_runtimedir_new);
+
+    std::regex zname_regex("for ac_lib in z");
+    regexes.push_back(zname_regex);
+    std::string zname_new  = std::string("for ac_lib in ") + 
std::string(ZLIB_NAME);
+    strings.push_back(zname_new);
+
+    std::regex deflate_regex("deflateSetHeader");
+    regexes.push_back(deflate_regex);
+    std::string deflate_new  = std::string(DEFLATE_NAME);
+    strings.push_back(deflate_new);
+
+    for (int i = 1; i < argc; i++) {
+       std::string cline;
+       std::string nfile_contents;
+       std::ifstream fs;
+       fs.open(argv[i]);
+       if (!fs.is_open()) {
+           std::cerr << "Error: file " << argv[i] << " could not be opened.\n";
+           return -1;
+       } else {
+           if (verbose) {
+               std::cerr << "Patching " << argv[i] << "\n";
+           }
+       }
+
+       while (std::getline(fs, cline)) {
+           std::string nline = cline;
+           for (size_t j = 0; j < regexes.size(); j++) {
+               if (strings[j].length() > 0) {
+                   std::string nline2 = std::regex_replace(nline, regexes[j], 
strings[j]);
+                   nline = nline2;
+               }
+           }
+           nfile_contents.append(nline);
+           nfile_contents.append("\n");
+           if (nline != cline) {
+               if (verbose > 1) {
+                   std::cerr << "   Changed line: " << cline << " -> " << 
nline << "\n";
+               }
+           }
+       }
+
+       fs.close();
+
+       std::ofstream ofs(argv[i], std::ios::trunc);
+       ofs << nfile_contents;
+       ofs.close();
+    }
+}
+
+// Local Variables:
+// tab-width: 8
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: t
+// c-file-style: "stroustrup"
+// End:
+// ex: shiftwidth=4 tabstop=8
+


Property changes on: 
brlcad/branches/extbuild/src/other/ext/CMake/tcl_replace.cxx.in
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to