From 472b6e7845a68d73ed49f160c64e4412b3bfa908 Mon Sep 17 00:00:00 2001 From: fche Date: Mon, 26 Mar 2001 19:18:34 +0000 Subject: [PATCH] * function improvement [include/ChangeLog] 2001-03-26 Frank Ch. Eigler * sidmiscutil.h (sid_file_search_path): New function for returning a canonical file search path based on SID_LIBRARY_PATH and SID_EXEC_PREFIX. (find_sid_data_file): New function to use the above to locate sid data files. * configure.in (SID_EXEC_PREFIX): AC_DEFINE. * configure, sidconfutil.h: Regenerated. [component/cfgroot/ChangeLog] 2001-03-26 Frank Ch. Eigler * compConfig.cxx (configure): Use find_sid_data_file to locate given sid config file. * Makefile.am (AM_CXXFLAGS): Remove. * Makefile.in: Regenerated. [component/memory/ChangeLog] 2001-03-26 Frank Ch. Eigler * generic.cxx (image{load,store,mmap}_handler): Use find_sid_data_file to locate image-file. [component/tcl/ChangeLog] 2001-03-26 Frank Ch. Eigler * compTcl.cxx (scan_files): Use sid_file_search_path to locate tcl component sources. * Makefile.am (AM_CXXFLAGS): Remove definition. * Makefile.in: Regenerated. --- sid/component/cfgroot/ChangeLog | 7 ++++ sid/component/cfgroot/Makefile.am | 1 - sid/component/cfgroot/Makefile.in | 1 - sid/component/cfgroot/compConfig.cxx | 5 ++- sid/component/memory/ChangeLog | 5 +++ sid/component/memory/generic.cxx | 8 ++-- sid/component/tcl/ChangeLog | 7 ++++ sid/component/tcl/Makefile.am | 1 - sid/component/tcl/Makefile.in | 1 - sid/component/tcl/compTcl.cxx | 36 +++--------------- sid/include/ChangeLog | 10 +++++ sid/include/configure | 10 +++++ sid/include/configure.in | 7 ++++ sid/include/sidconfutil.in | 3 ++ sid/include/sidmiscutil.h | 72 +++++++++++++++++++++++++++++++++++- 15 files changed, 133 insertions(+), 41 deletions(-) diff --git a/sid/component/cfgroot/ChangeLog b/sid/component/cfgroot/ChangeLog index e14e231cc2..6a3abe6f39 100644 --- a/sid/component/cfgroot/ChangeLog +++ b/sid/component/cfgroot/ChangeLog @@ -1,3 +1,10 @@ +2001-03-26 Frank Ch. Eigler + + * compConfig.cxx (configure): Use find_sid_data_file to locate + given sid config file. + * Makefile.am (AM_CXXFLAGS): Remove. + * Makefile.in: Regenerated. + 2001-03-21 Ben Elliston * Makefile.in: Regenerate. diff --git a/sid/component/cfgroot/Makefile.am b/sid/component/cfgroot/Makefile.am index 51ddef2a43..b2227a42bb 100644 --- a/sid/component/cfgroot/Makefile.am +++ b/sid/component/cfgroot/Makefile.am @@ -8,7 +8,6 @@ SUBDIRS = @subdirs@ pkglib_LTLIBRARIES = libconfig.la INCLUDES = -I. -I../../include -I$(srcdir)/../../include -I$(srcdir)/libltdl -AM_CXXFLAGS = -DSID_EXEC_PREFIX=\"$(exec_prefix)\" libconfig_la_SOURCES = compConfig.cxx libconfig_la_LDFLAGS = -module -no-undefined diff --git a/sid/component/cfgroot/Makefile.in b/sid/component/cfgroot/Makefile.in index 99f8524965..9371812586 100644 --- a/sid/component/cfgroot/Makefile.in +++ b/sid/component/cfgroot/Makefile.in @@ -86,7 +86,6 @@ SUBDIRS = @subdirs@ pkglib_LTLIBRARIES = libconfig.la INCLUDES = -I. -I../../include -I$(srcdir)/../../include -I$(srcdir)/libltdl -AM_CXXFLAGS = -DSID_EXEC_PREFIX=\"$(exec_prefix)\" libconfig_la_SOURCES = compConfig.cxx libconfig_la_LDFLAGS = -module -no-undefined diff --git a/sid/component/cfgroot/compConfig.cxx b/sid/component/cfgroot/compConfig.cxx index 56e43ca855..af3cc38166 100644 --- a/sid/component/cfgroot/compConfig.cxx +++ b/sid/component/cfgroot/compConfig.cxx @@ -1,7 +1,7 @@ // compConfig.cxx - The cfgroot component: configuration parsing, root // of component creation and management. -*- C++ -*- -// Copyright (C) 1999, 2000 Red Hat. +// Copyright (C) 1999-2001 Red Hat. // This file is part of SID and is licensed under the GPL. // See the file COPYING.SID for conditions for redistribution. @@ -74,6 +74,7 @@ using sidutil::parse_attribute; using sidutil::std_error_string; using sidutil::recursion_limited; using sidutil::recursion_record; +using sidutil::find_sid_data_file; // This component reads a flat config file, and acts as a root @@ -483,7 +484,7 @@ cfgroot_component::configure(const std::string& name) unsigned last_line_num = this->line_num; this->line_num = 1; - ifstream cfile(this->config_file.c_str()); + ifstream cfile(find_sid_data_file(this->config_file).c_str()); if(! cfile.good()) { cerr << config_file << ": " << std_error_string() << endl; diff --git a/sid/component/memory/ChangeLog b/sid/component/memory/ChangeLog index 6f4defe56f..45a21804cf 100644 --- a/sid/component/memory/ChangeLog +++ b/sid/component/memory/ChangeLog @@ -1,3 +1,8 @@ + 2001-03-26 Frank Ch. Eigler + + * generic.cxx (image{load,store,mmap}_handler): Use find_sid_data_file + to locate image-file. + 2001-03-16 Frank Ch. Eigler * generic.cxx (imagemmap_handler): Enforce minimum mmap file size. diff --git a/sid/component/memory/generic.cxx b/sid/component/memory/generic.cxx index bf87e6890e..97c42eda25 100644 --- a/sid/component/memory/generic.cxx +++ b/sid/component/memory/generic.cxx @@ -47,6 +47,7 @@ using sidutil::make_attribute; using sidutil::parse_attribute; using sidutil::string2stream; using sidutil::stream2string; +using sidutil::find_sid_data_file; // ---------------------------------------------------------------------------- @@ -138,7 +139,7 @@ generic_memory::imageload_handler (host_int_4) return; } - ifstream f (this->image_file_name.c_str(), ios::binary | ios::in); + ifstream f (find_sid_data_file(this->image_file_name).c_str(), ios::binary | ios::in); if (! f.good()) { cerr << "memory: error opening " << this->image_file_name << ": " @@ -167,7 +168,8 @@ generic_memory::imagestore_handler (host_int_4) return; } - ofstream f (this->image_file_name.c_str(), ios::binary | ios::out | ios::trunc); + ofstream f (find_sid_data_file(this->image_file_name).c_str(), + ios::binary | ios::out | ios::trunc); if (! f.good()) { cerr << "memory: error opening " << this->image_file_name << ": " @@ -213,7 +215,7 @@ generic_memory::imagemmap_handler (host_int_4) return; } - int fd = open (this->image_file_name.c_str(), O_RDWR); + int fd = open (find_sid_data_file(this->image_file_name).c_str(), O_RDWR); if (fd < 0) { cerr << "memory: cannot open image-file during image-mmap:" << std_error_string() << endl; diff --git a/sid/component/tcl/ChangeLog b/sid/component/tcl/ChangeLog index cade92f4cc..d9029a3c7d 100644 --- a/sid/component/tcl/ChangeLog +++ b/sid/component/tcl/ChangeLog @@ -1,3 +1,10 @@ +2001-03-26 Frank Ch. Eigler + + * compTcl.cxx (scan_files): Use sid_file_search_path to locate tcl + component sources. + * Makefile.am (AM_CXXFLAGS): Remove definition. + * Makefile.in: Regenerated. + 2001-03-21 Ben Elliston * Makefile.in: Regenerate. diff --git a/sid/component/tcl/Makefile.am b/sid/component/tcl/Makefile.am index f48d35b3f4..ac17d62e5e 100644 --- a/sid/component/tcl/Makefile.am +++ b/sid/component/tcl/Makefile.am @@ -6,7 +6,6 @@ ACLOCAL_AMFLAGS = -I ../../config pkglib_LTLIBRARIES = libtclapi.la INCLUDES = -I. -I../../include -I$(srcdir)/../../include -AM_CXXFLAGS = -DSID_EXEC_PREFIX=\"$(exec_prefix)\" pkgdata_DATA = sid-control-tksm.tk hw-visual-probe-bus.blt bridge-tcl.tcl bridge-tk.tk bridge-blt.blt bridge-tcl.txt sid-api-trace.tcl hw-visual-probe-pin.tk noinst_DATA = tester.tcl diff --git a/sid/component/tcl/Makefile.in b/sid/component/tcl/Makefile.in index dc9b1dfb86..c0375620e8 100644 --- a/sid/component/tcl/Makefile.in +++ b/sid/component/tcl/Makefile.in @@ -83,7 +83,6 @@ ACLOCAL_AMFLAGS = -I ../../config pkglib_LTLIBRARIES = libtclapi.la INCLUDES = -I. -I../../include -I$(srcdir)/../../include -AM_CXXFLAGS = -DSID_EXEC_PREFIX=\"$(exec_prefix)\" pkgdata_DATA = sid-control-tksm.tk hw-visual-probe-bus.blt bridge-tcl.tcl bridge-tk.tk bridge-blt.blt bridge-tcl.txt sid-api-trace.tcl hw-visual-probe-pin.tk noinst_DATA = tester.tcl diff --git a/sid/component/tcl/compTcl.cxx b/sid/component/tcl/compTcl.cxx index 6da5e67b4a..c81de96893 100644 --- a/sid/component/tcl/compTcl.cxx +++ b/sid/component/tcl/compTcl.cxx @@ -1,6 +1,6 @@ // compTcl.cxx - Tcl bridge component. -*- C++ -*- -// Copyright (C) 1999, 2000 Red Hat. +// Copyright (C) 1999-2001 Red Hat. // This file is part of SID and is licensed under the GPL. // See the file COPYING.SID for conditions for redistribution. @@ -94,6 +94,7 @@ namespace tcl_api_component using sidutil::bijection; using sidutil::std_error_string; using sidutil::tokenize; + using sidutil::sid_file_search_path; #ifndef DISABLE_THIS_COMPONENT @@ -2059,35 +2060,7 @@ scan_files (const string& dotless_extension) file_map_t files; string extension = string(".") + dotless_extension; - vector search_directories; - - char* slp = getenv ("SID_LIBRARY_PATH"); // run-time configuration - if (slp) - { - search_directories = tokenize (slp, ":"); - } - - char* sep = getenv ("SID_EXEC_PREFIX"); // install-time configuration -#ifdef HAVE_CYGWIN_CONV_TO_FULL_POSIX_PATH - char conv_fn[PATH_MAX*2]; - if (sep) - { - int rc = cygwin_conv_to_full_posix_path (sep, conv_fn); - if (rc != 0) - cerr << "tcl-bridge: cygwin_conv_to_full_posix_path failed: " - << std_error_string () << endl; - else - sep = conv_fn; - } -#endif - if (!sep) sep = SID_EXEC_PREFIX; // build-time configuration - // We really just want to get to pkgdatadir, which is $prefix/share/sidcomp. - // Guess exec-prefix == prefix - string pkglibdir1 = string(sep) + string("/share/sidcomp"); - search_directories.push_back (pkglibdir1); - // Guess exec-prefix == prefix/H-HOST - string pkglibdir2 = string(sep) + string("/../share/sidcomp"); - search_directories.push_back (pkglibdir2); + vector search_directories = sid_file_search_path (); #ifndef HAVE_OPENDIR #error "Need opendir!" @@ -2095,7 +2068,8 @@ scan_files (const string& dotless_extension) for (unsigned i=0; i + + * sidmiscutil.h (sid_file_search_path): New function for returning + a canonical file search path based on SID_LIBRARY_PATH and + SID_EXEC_PREFIX. + (find_sid_data_file): New function to use the above to locate sid + data files. + * configure.in (SID_EXEC_PREFIX): AC_DEFINE. + * configure, sidconfutil.h: Regenerated. + 2001-03-21 Ben Elliston * Makefile.in: Regenerate. diff --git a/sid/include/configure b/sid/include/configure index 8df72f1f1c..d0d66b34d1 100755 --- a/sid/include/configure +++ b/sid/include/configure @@ -1312,6 +1312,16 @@ fi echo "$ac_t""$sid_cv_builtin_expect" 1>&6 +if test "${exec_prefix}" = "NONE"; then + sid_exec_prefix=${prefix} +else + sid_exec_prefix=${exec_prefix} +fi +cat >> confdefs.h < confcache <<\EOF # This file is a shell script that caches the results of configure diff --git a/sid/include/configure.in b/sid/include/configure.in index ebb725f30e..13a61c2a9e 100644 --- a/sid/include/configure.in +++ b/sid/include/configure.in @@ -59,5 +59,12 @@ fi AC_MSG_RESULT([$sid_cv_builtin_expect]) +if test "${exec_prefix}" = "NONE"; then + sid_exec_prefix=${prefix} +else + sid_exec_prefix=${exec_prefix} +fi +AC_DEFINE_UNQUOTED(SID_EXEC_PREFIX,"$sid_exec_prefix",[Define to build-time exec-prefix]) + dnl Outputs AC_OUTPUT(Makefile) diff --git a/sid/include/sidconfutil.in b/sid/include/sidconfutil.in index 49fc9bb04b..63fca35372 100644 --- a/sid/include/sidconfutil.in +++ b/sid/include/sidconfutil.in @@ -33,3 +33,6 @@ /* Define if compiler supports __builtin_expect */ #undef HAVE_BUILTIN_EXPECT +/* Define to build-time exec-prefix */ +#undef SID_EXEC_PREFIX + diff --git a/sid/include/sidmiscutil.h b/sid/include/sidmiscutil.h index b465eb7c9a..44845f0a6e 100644 --- a/sid/include/sidmiscutil.h +++ b/sid/include/sidmiscutil.h @@ -1,6 +1,6 @@ // sidmiscutil.h - Useful utility classes. -*- C++ -*- -// Copyright (C) 1999, 2000 Red Hat. +// Copyright (C) 1999-2001 Red Hat. // This file is part of SID and is licensed under the GPL. // See the file COPYING.SID for conditions for redistribution. @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -304,6 +305,75 @@ namespace sidutil #endif return std::string(error_message); } + + + // Return a vector of directory names, where the SID_LIBRARY_PATH + // and SID_EXEC_PREFIX environment variables are pointing. Convert + // all paths to POSIX form on Cygwin. + inline std::vector + sid_file_search_path () + { + vector search_directories; + + char* slp = getenv ("SID_LIBRARY_PATH"); // run-time configuration + if (slp) + { + search_directories = tokenize (slp, ":"); + } + + char* sep = getenv ("SID_EXEC_PREFIX"); // install-time configuration +#ifdef __CYGWIN__ + char conv_fn[PATH_MAX*2]; + if (sep) + { + int rc = cygwin_conv_to_full_posix_path (sep, conv_fn); + if (rc != 0) + cerr << "sid_file_search_path: cygwin_conv_to_full_posix_path failed: " + << std_error_string () << endl; + else + sep = conv_fn; + } +#endif + if (!sep) sep = SID_EXEC_PREFIX; // build-time configuration + // We really just want to get to pkgdatadir, which is $prefix/share + // Guess exec-prefix == prefix + string pkglibdir1 = string(sep) + string("/share"); + search_directories.push_back (pkglibdir1); + // Guess exec-prefix == prefix/H-HOST + string pkglibdir2 = string(sep) + string("/../share"); + search_directories.push_back (pkglibdir2); + + return search_directories; + } + + + // Look around cwd, the standard search dirs (.../sid) + // At worst, return the given name. + inline std::string + find_sid_data_file (const std::string& file) + { + std::vector file_path = sid_file_search_path (); + std::vector path; + + path.push_back (string("")); // no prefix + for (unsigned i=0; i