From 4c9a892d009c5b8f1952cf3450dda32148af887e Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Sun, 7 Sep 2014 14:31:18 +1000 Subject: Refactor the rld-rtems support to remove the globals. --- rld-cc.cpp | 3 +- rld-rtems.cpp | 162 +++++++++++++++++++++++++++++++++++++--------------------- rld-rtems.h | 38 ++++++++------ rld.h | 5 -- rtems-ld.cpp | 17 +++--- rtems-tld.cpp | 49 +++++++++++++----- 6 files changed, 174 insertions(+), 100 deletions(-) diff --git a/rld-cc.cpp b/rld-cc.cpp index 5fe7f89..29eebbb 100644 --- a/rld-cc.cpp +++ b/rld-cc.cpp @@ -21,6 +21,7 @@ #include #include #include +#include namespace rld { @@ -423,7 +424,7 @@ namespace rld { std::string cmd = cc_name; if (!exec_prefix.empty ()) - cmd = exec_prefix + "-rtems" + rld::rtems_version () + '-' + cmd; + cmd = exec_prefix + "-rtems" + rld::rtems::version () + '-' + cmd; args.push_back (cmd); } } diff --git a/rld-rtems.cpp b/rld-rtems.cpp index c96bd62..d85f845 100644 --- a/rld-rtems.cpp +++ b/rld-rtems.cpp @@ -16,6 +16,7 @@ #include #include +#include #include @@ -23,69 +24,37 @@ namespace rld { namespace rtems { - std::string version = "4.11"; - std::string path; - bool installed; - std::string arch_bsp; + static std::string _version = "4.11"; + static std::string _path; + static std::string _arch_bsp; - const std::string - arch (const std::string& ab) - { - std::string::size_type slash = ab.find_first_of ('/'); - if (slash == std::string::npos) - throw rld::error ("Invalid BSP name", ab); - return ab.substr (0, slash); - std::string bsp = ab.substr (slash + 1); - } - - const std::string - bsp (const std::string& ab) - { - std::string::size_type slash = ab.find_first_of ('/'); - if (slash == std::string::npos) - throw rld::error ("Invalid BSP name", ab); - return ab.substr (slash + 1); - } - - const std::string - rtems_arch_prefix (const std::string& ab) - { - return arch (ab) + "-rtems" + version; - } - - const std::string - rtems_arch_bsp (const std::string& ab) - { - return rtems_arch_prefix (ab) + '-' + bsp (ab); - } - - void + static void load_cc () { path::paths parts; std::string rtems_pkgconfig; std::string bsp; - if (path.empty ()) - throw rld::error ("Not set; see -r", "RTEMS path"); + if (_path.empty ()) + throw rld::error ("Not set", "RTEMS path"); - bsp = rtems_arch_bsp (arch_bsp); + bsp = rtems_arch_bsp (); parts.push_back ("lib"); parts.push_back ("pkgconfig"); - rld::path::path_join (path, parts, rtems_pkgconfig); + rld::path::path_join (path (), parts, rtems_pkgconfig); if (!path::check_directory (rtems_pkgconfig)) - throw rld::error ("Invalid RTEMS path", path); + throw rld::error ("Invalid RTEMS path", path ()); rld::path::path_join (rtems_pkgconfig, bsp + ".pc", rtems_pkgconfig); if (!path::check_file (rtems_pkgconfig)) - throw rld::error ("RTEMS BSP not found", arch_bsp); + throw rld::error ("RTEMS BSP not found", arch_bsp ()); if (rld::verbose () >= RLD_VERBOSE_INFO) - std::cout << " rtems: " << arch_bsp << ": " + std::cout << " rtems: " << _arch_bsp << ": " << rtems_pkgconfig << std::endl; pkgconfig::package pkg (rtems_pkgconfig); @@ -95,18 +64,19 @@ namespace rld */ std::string name; if (!pkg.get ("name", name)) - throw rld::error ("RTEMS BSP no name in pkgconfig file", arch_bsp); + throw rld::error ("RTEMS BSP no name in pkgconfig file", _arch_bsp); if (name != bsp) - throw rld::error ("RTEMS BSP does not match the name in pkgconfig file", arch_bsp); + throw rld::error ("RTEMS BSP does not match the name in pkgconfig file", + _arch_bsp); std::string flags; if (pkg.get ("CPPFLAGS", flags)) { - rld::cc::append_flags (flags, arch (arch_bsp), path, rld::cc::ft_cppflags); + rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_cppflags); if (rld::verbose () >= RLD_VERBOSE_INFO) - std::cout << " rtems: " << arch_bsp + std::cout << " rtems: " << arch_bsp () << ": CPPFLAGS=" << rld::cc::get_flags (rld::cc::ft_cppflags) << std::endl; @@ -114,22 +84,22 @@ namespace rld if (pkg.get ("CFLAGS", flags)) { - rld::cc::append_flags (flags, arch (arch_bsp), path, rld::cc::ft_cflags); + rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_cflags); if (rld::verbose () >= RLD_VERBOSE_INFO) { - std::cout << " rtems: " << arch_bsp + std::cout << " rtems: " << arch_bsp () << ": CFLAGS=" << rld::cc::get_flags (rld::cc::ft_cflags) << std::endl; - std::cout << " rtems: " << arch_bsp + std::cout << " rtems: " << _arch_bsp << ": WARNINGS=" << rld::cc::get_flags (rld::cc::fg_warning_flags) << std::endl; - std::cout << " rtems: " << arch_bsp + std::cout << " rtems: " << arch_bsp () << ": INCLUDES=" << rld::cc::get_flags (rld::cc::fg_include_flags) << std::endl; - std::cout << " rtems: " << arch_bsp + std::cout << " rtems: " << arch_bsp () << ": MACHINES=" << rld::cc::get_flags (rld::cc::fg_machine_flags) << std::endl; - std::cout << " rtems: " << arch_bsp + std::cout << " rtems: " << arch_bsp () << ": SPECS=" << rld::cc::get_flags (rld::cc::fg_spec_flags) << std::endl; } @@ -137,23 +107,99 @@ namespace rld if (pkg.get ("CXXFLAGS", flags)) { - rld::cc::append_flags (flags, arch (arch_bsp), path, rld::cc::ft_cxxflags); + rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_cxxflags); if (rld::verbose () >= RLD_VERBOSE_INFO) - std::cout << " rtems: " << arch_bsp + std::cout << " rtems: " << arch_bsp () << ": CXXFLAGS=" << rld::cc::get_flags (rld::cc::ft_cxxflags) << std::endl; } if (pkg.get ("LDFLAGS", flags)) { - rld::cc::append_flags (flags, arch (arch_bsp), path, rld::cc::ft_ldflags); + rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_ldflags); if (rld::verbose () >= RLD_VERBOSE_INFO) - std::cout << " rtems: " << arch_bsp + std::cout << " rtems: " << arch_bsp () << ": LDFLAGS=" << rld::cc::get_flags (rld::cc::ft_ldflags) << std::endl; } - rld::cc::set_exec_prefix (arch (arch_bsp)); + rld::cc::set_exec_prefix (arch ()); + } + + void + set_version (const std::string& version_) + { + _version = version_; + } + + void + set_arch_bsp (const std::string& arch_bsp_) + { + _arch_bsp = arch_bsp_; + if (!_path.empty ()) + load_cc (); + } + + void + set_path (const std::string& path_) + { + _path = path_; + if (!_arch_bsp.empty ()) + load_cc (); + } + + const std::string + version () + { + return _version; + } + + const std::string + arch_bsp () + { + return _arch_bsp; + } + + const std::string + arch () + { + if (_arch_bsp.empty ()) + throw rld::error ("No arch/bsp name", "rtems: arch"); + std::string::size_type slash = _arch_bsp.find_first_of ('/'); + if (slash == std::string::npos) + throw rld::error ("Invalid BSP name", _arch_bsp); + return _arch_bsp.substr (0, slash); + std::string bsp = _arch_bsp.substr (slash + 1); } + + const std::string + bsp () + { + if (_arch_bsp.empty ()) + throw rld::error ("No arch/bsp name", "rtems: bsp"); + std::string::size_type slash = _arch_bsp.find_first_of ('/'); + if (slash == std::string::npos) + throw rld::error ("Invalid BSP name", _arch_bsp); + return _arch_bsp.substr (slash + 1); + } + + const std::string + path () + { + return _path; + } + + const std::string + rtems_arch_prefix () + { + return arch () + "-rtems" + version (); + } + + const std::string + rtems_arch_bsp () + { + return rtems_arch_prefix () + '-' + bsp (); + } + } } diff --git a/rld-rtems.h b/rld-rtems.h index 97dc67e..04305ce 100644 --- a/rld-rtems.h +++ b/rld-rtems.h @@ -32,50 +32,54 @@ namespace rld namespace rtems { /** - * The RTEMS default version. + * Set the RTEMS version. */ - extern std::string version; + void set_version (const std::string& version); /** - * The path to RTEMS. + * Set the arch/bsp string. */ - extern std::string path; + void set_arch_bsp (const std::string& arch_bsp); /** - * Is the RTEMS installed. + * Set the path to RTEMS. */ - extern bool installed; + void set_path (const std::string& path); /** - * The BSP name. + * Get the RTEMS version. */ - extern std::string arch_bsp; + const std::string version (); + + /** + * Return the arch/bsp string. + */ + const std::string arch_bsp (); /** * Return the architecture given an arch/bsp string. */ - const std::string arch (const std::string& ab); + const std::string arch (); /** * Return the bsp given an arch/bsp string. */ - const std::string bsp (const std::string& ab); + const std::string bsp (); /** - * Return the RTEMS bsp string given an arch/bsp string. + * Get the RTEMS path. */ - const std::string rtems_bsp (const std::string& ab); + const std::string path (); /** - * Load the configuration. Set the various values via the command or a - * configuration file then check the configuration. + * Return the RTEMS BSP prefix. */ - void load_cc (); + const std::string rtems_arch_prefix (); /** - * Process the BSP name updating the various CC flags. + * Return the arch/bsp as an RTEMS prefix and BSP string. */ - void set_cc (void); + const std::string rtems_arch_bsp (); } } diff --git a/rld.h b/rld.h index 0a6cd9c..6a42923 100644 --- a/rld.h +++ b/rld.h @@ -271,11 +271,6 @@ namespace rld */ const std::string version (); - /** - * The RTEMS version string. @todo move to rld-rtems. - */ - const std::string rtems_version (); - /** * Container of strings to hold the results of a split. */ diff --git a/rtems-ld.cpp b/rtems-ld.cpp index cf28937..dfa5c14 100644 --- a/rtems-ld.cpp +++ b/rtems-ld.cpp @@ -185,6 +185,8 @@ main (int argc, char* argv[]) rld::symbols::table base_symbols; rld::symbols::table symbols; rld::symbols::symtab undefined; + std::string rtems_path; + std::string rtems_arch_bsp; std::string entry = "rtems"; std::string exit; std::string output = "a.out"; @@ -195,7 +197,6 @@ main (int argc, char* argv[]) bool map = false; bool warnings = false; bool one_file = false; - bool arch_bsp_load = false; libpaths.push_back ("."); @@ -311,12 +312,11 @@ main (int argc, char* argv[]) break; case 'r': - rld::rtems::path = optarg; + rtems_path = optarg; break; case 'B': - rld::rtems::arch_bsp = optarg; - arch_bsp_load = true; + rtems_arch_bsp = optarg; break; case '?': @@ -353,8 +353,13 @@ main (int argc, char* argv[]) /* * Load the arch/bsp value if provided. */ - if (arch_bsp_load) - rld::rtems::load_cc (); + if (!rtems_arch_bsp.empty ()) + { + if (rtems_path.empty ()) + throw rld::error ("arch/bsp provide and no RTEMS path", "options"); + rld::rtems::set_path (rtems_path); + rld::rtems::set_arch_bsp (rtems_arch_bsp); + } /* * Load the remaining command line arguments into the cache as object diff --git a/rtems-tld.cpp b/rtems-tld.cpp index 41269da..c6d5c55 100644 --- a/rtems-tld.cpp +++ b/rtems-tld.cpp @@ -232,6 +232,12 @@ namespace rld void compile_wrapper (rld::process::tempfile& c, rld::process::tempfile& o); + /** + * Link the application. + */ + void link (rld::process::tempfile& o, + const std::string& ld_cmds); + /** * Dump the linker. */ @@ -751,6 +757,13 @@ namespace rld } } + void + linker::link (rld::process::tempfile& o, + const std::string& ld_cmds) + { + + } + void linker::dump (std::ostream& out) const { @@ -779,6 +792,7 @@ static struct option rld_opts[] = { { "verbose", no_argument, NULL, 'v' }, { "warn", no_argument, NULL, 'w' }, { "keep", no_argument, NULL, 'k' }, + { "linker", required_argument, NULL, 'l' }, { "exec-prefix", required_argument, NULL, 'E' }, { "cflags", required_argument, NULL, 'c' }, { "rtems", required_argument, NULL, 'r' }, @@ -799,11 +813,12 @@ usage (int exit_code) << " to increase verbosity (also --verbose)" << std::endl << " -w : generate warnings (also --warn)" << std::endl << " -k : keep temporary files (also --keep)" << std::endl + << " -l linker : target linker is not standard (also --linker)" << std::endl << " -E prefix : the RTEMS tool prefix (also --exec-prefix)" << std::endl << " -c cflags : C compiler flags (also --cflags)" << std::endl << " -r path : RTEMS path (also --rtems)" << std::endl << " -B bsp : RTEMS arch/bsp (also --rtems-bsp)" << std::endl - << " -W wrapper : Wrapper file name without ext (also --wrapper)" << std::endl + << " -W wrapper : wrapper file name without ext (also --wrapper)" << std::endl << " -C ini : user configuration INI file (also --config)" << std::endl; ::exit (exit_code); } @@ -852,15 +867,17 @@ main (int argc, char* argv[]) try { rld::trace::linker linker; + std::string ld; std::string ld_cmd; std::string configuration; std::string trace = "tracer"; std::string wrapper; - bool arch_bsp_load = false; + std::string rtems_path; + std::string rtems_arch_bsp; while (true) { - int opt = ::getopt_long (argc, argv, "hvwkVE:c:C:r:B:W:", rld_opts, NULL); + int opt = ::getopt_long (argc, argv, "hvwkVl:E:c:C:r:B:W:", rld_opts, NULL); if (opt < 0) break; @@ -886,6 +903,10 @@ main (int argc, char* argv[]) rld::process::set_keep_temporary_files (); break; + case 'l': + ld = optarg; + break; + case 'E': rld::cc::set_exec_prefix (optarg); break; @@ -895,12 +916,11 @@ main (int argc, char* argv[]) break; case 'r': - rld::rtems::path = optarg; + rtems_path = optarg; break; case 'B': - rld::rtems::arch_bsp = optarg; - arch_bsp_load = true; + rtems_arch_bsp = optarg; break; case 'C': @@ -930,18 +950,20 @@ main (int argc, char* argv[]) /* * Load the arch/bsp value if provided. */ - if (arch_bsp_load) - rld::rtems::load_cc (); + if (!rtems_arch_bsp.empty ()) + { + if (rtems_path.empty ()) + throw rld::error ("arch/bsp provide and no RTEMS path", "options"); + rld::rtems::set_path (rtems_path); + rld::rtems::set_arch_bsp (rtems_arch_bsp); + } /* * Load the remaining command line arguments into the linker command line. */ while (argc--) - { - if (ld_cmd.length () != 0) - ld_cmd += " "; - ld_cmd += *argv++; - } + ld_cmd += ' ' + *argv++; + ld_cmd = rld::trim (ld_cmd); /* * If there are no object files there is nothing to link. @@ -969,6 +991,7 @@ main (int argc, char* argv[]) linker.generate_wrapper (c); linker.compile_wrapper (c, o); + linker.link (o, ld_cmd); if (rld::verbose ()) linker.dump (std::cout); -- cgit v1.2.3