aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Danny van Dyk <dvandyk@exherbo.org> 2007-03-18 22:43:03 +0000
committerAvatar Danny van Dyk <dvandyk@exherbo.org> 2007-03-18 22:43:03 +0000
commit7ec28dfa33cc92754490ba1e2ffe5fa907b57710 (patch)
tree05661ec6700ab4007d6adc64c24c664cad2cad31
parentf02ee9142fe25e5aad29984d9ca26e9f90a4da8c (diff)
downloadpaludis-7ec28dfa33cc92754490ba1e2ffe5fa907b57710.tar.gz
paludis-7ec28dfa33cc92754490ba1e2ffe5fa907b57710.tar.xz
Forgot to add 2 files.
-rw-r--r--src/clients/contrarius/target_config.cc147
-rw-r--r--src/clients/contrarius/target_config.hh106
2 files changed, 253 insertions, 0 deletions
diff --git a/src/clients/contrarius/target_config.cc b/src/clients/contrarius/target_config.cc
new file mode 100644
index 0000000..3108f61
--- /dev/null
+++ b/src/clients/contrarius/target_config.cc
@@ -0,0 +1,147 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Danny van Dyk <kugelfang@gentoo.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <paludis/util/fs_entry.hh>
+#include <paludis/util/tokeniser.hh>
+#include <paludis/config_file.hh>
+#include <list>
+#include <string>
+#include <vector>
+
+#include "command_line.hh"
+#include "target_config.hh"
+
+using namespace paludis;
+
+void
+TargetConfig::_parse_defaults()
+{
+ Context c("While parsing default configuration:");
+
+ LineConfigFile defaults(FSEntry(DATADIR "/paludis/contrarius/default_config.txt"));
+ for (LineConfigFile::Iterator l(defaults.begin()), l_end(defaults.end()) ;
+ l != l_end ; ++l)
+ {
+ Context c("While parsing line '" + *l + "'");
+ std::vector<std::string> tokens;
+ WhitespaceTokeniser::get_instance()->tokenise(*l, std::back_inserter(tokens));
+ SpecEntryList * list(&_binutils_list);
+
+ if (("aux" == tokens[1]) && (2 == std::distance(tokens.begin(), tokens.end())))
+ tokens.push_back("");
+ else if (2 > std::distance(tokens.begin(), tokens.end()))
+ throw TargetConfigError("Illegal number of tokens encountered");
+
+ if ("binutils" == tokens[1])
+ list = &_binutils_list;
+ else if ("gcc" == tokens[1])
+ list = &_gcc_list;
+ else if ("headers" == tokens[1])
+ list = &_headers_list;
+ else if ("libc" == tokens[1])
+ list = &_libc_list;
+ else if ("aux" == tokens[1])
+ list = &_aux_list;
+ else
+ throw TargetConfigError("Invalid key '" + tokens[1] + "' encountered");
+
+ std::string entry(tokens[2]);
+ for (std::vector<std::string>::const_iterator t(tokens.begin() + 3), t_end(tokens.end()) ;
+ t != t_end ; ++t)
+ entry += " " + *t;
+
+ list->push_back(std::make_pair(tokens[0], entry));
+ }
+}
+
+std::string
+TargetConfig::_find_match(SpecEntryList & list)
+{
+ Tokeniser<delim_kind::AnyOfTag, delim_mode::DelimiterTag> tokeniser("-");
+ std::vector<std::string> tokens;
+
+ for (SpecEntryList::const_iterator i(list.begin()), i_end(list.end()) ;
+ i != i_end ; ++i)
+ {
+ tokens.clear();
+ tokeniser.tokenise(i->first, std::back_inserter(tokens));
+
+ for (unsigned index(0) ; index < 4 ; ++index)
+ {
+ std::string & token(tokens[index]);
+
+ std::string t;
+ if (0 == index)
+ t = stringify(_target.architecture);
+ else if (1 == index)
+ t = stringify(_target.manufacturer);
+ else if (2 == index)
+ t = stringify(_target.kernel);
+ else if (3 == index)
+ t = stringify(_target.userland);
+
+ if (t.length() < token.length())
+ break;
+
+ if (0 != token.compare(0, token.length() - 1, t, 0, token.length() - 1))
+ break;
+
+ if (('*' == token[token.length() - 1]) || (t[token.length() - 1] == token[token.length() - 1]))
+ {
+ if (3 == index)
+ return i->second;
+ else
+ continue;
+ }
+ else
+ break;
+ }
+ }
+
+ throw TargetConfigError("Unknown CTARGET '" + stringify(_target) + "'");
+}
+
+TargetConfig::TargetConfig() :
+ _target(CommandLine::get_instance()->a_target.argument())
+{
+ _parse_defaults();
+
+ _binutils = "cross-" + stringify(_target) + "/" + _find_match(_binutils_list);
+ Log::get_instance()->message(ll_debug, lc_no_context, "Using configuration:\n"
+ " binutils: " + _binutils + "\n");
+
+ _gcc = "cross-" + stringify(_target) + "/" + _find_match(_gcc_list);
+ Log::get_instance()->message(ll_debug, lc_no_context, "Using configuration:\n"
+ " gcc: " + _gcc + "\n");
+
+ _headers = _find_match(_headers_list);
+ if (! _headers.empty())
+ _headers = "cross-" + stringify(_target) + "/" + _find_match(_headers_list);
+ Log::get_instance()->message(ll_debug, lc_no_context, "Using configuration:\n"
+ " headers: " + (_headers.empty() ? "[none]" : _headers) + "\n");
+
+ _libc = "cross-" + stringify(_target) + "/" + _find_match(_libc_list);
+ Log::get_instance()->message(ll_debug, lc_no_context, "Using configuration:\n"
+ " libc: " + _libc + "\n");
+
+ _aux = _find_match(_aux_list);
+ Log::get_instance()->message(ll_debug, lc_no_context, "Using configuration:\n"
+ " aux: " + _aux + "\n");
+}
+
diff --git a/src/clients/contrarius/target_config.hh b/src/clients/contrarius/target_config.hh
new file mode 100644
index 0000000..b6731be
--- /dev/null
+++ b/src/clients/contrarius/target_config.hh
@@ -0,0 +1,106 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Danny van Dyk <kugelfang@gentoo.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_SRC_CLIENTS_CONTRARIUS_TARGET_CONFIG_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CONTRARIUS_TARGET_CONFIG_HH 1
+
+#include <paludis/util/exception.hh>
+#include <paludis/util/instantiation_policy.hh>
+#include <paludis/host_tuple_name.hh>
+#include <list>
+#include <utility>
+
+using namespace paludis;
+
+class TargetConfigError :
+ public Exception
+{
+ public:
+ TargetConfigError(const std::string & m) throw () :
+ Exception("Error in contrarius configuration: " + m)
+ {
+ }
+};
+
+class TargetConfig :
+ public InstantiationPolicy<TargetConfig, instantiation_method::SingletonTag>
+{
+ friend class InstantiationPolicy<TargetConfig, instantiation_method::SingletonTag>;
+
+ private:
+ typedef std::list<std::pair<std::string, std::string> > SpecEntryList;
+
+ typedef libwrapiter::ForwardIterator<TargetConfig, const std::string> Iterator;
+
+ SpecEntryList _binutils_list;
+
+ SpecEntryList _gcc_list;
+
+ SpecEntryList _headers_list;
+
+ SpecEntryList _libc_list;
+
+ SpecEntryList _aux_list;
+
+ HostTupleName _target;
+
+ std::string _binutils;
+
+ std::string _gcc;
+
+ std::string _headers;
+
+ std::string _libc;
+
+ std::string _aux;
+
+ TargetConfig();
+
+ void _parse_defaults();
+
+ std::string _find_match(SpecEntryList & list);
+
+ public:
+ std::string binutils() const
+ {
+ return _binutils;
+ }
+
+ std::string gcc() const
+ {
+ return _gcc;
+ }
+
+ std::string headers() const
+ {
+ return _headers;
+ }
+
+ std::string libc() const
+ {
+ return _libc;
+ }
+
+ std::string aux() const
+ {
+ return _aux;
+ }
+};
+
+#endif