]> git.tdb.fi Git - builder.git/blobdiff - source/architecture.h
More flexible way to manage filename patterns
[builder.git] / source / architecture.h
index af586192f9ef44b4dafa9103c68ca2b797000e43..360f3dd9f6321919df742d4fa7992ffbce0f9e27 100644 (file)
@@ -1,47 +1,89 @@
-/* $Id$
-
-This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #ifndef ARCHITECTURE_H_
 #define ARCHITECTURE_H_
 
+#include <typeinfo>
 #include <msp/datafile/loader.h>
-#include "misc.h"
+#include "buildinfo.h"
+#include "pattern.h"
 
 class Builder;
 
-// XXX Add lib/exe prefix/suffix fields.  Some archs may need multiple alternatives, how to handle this?
+/**
+Stores information about an architecture.  This includes CPU type, model and
+bitness and operating system.
+*/
 class Architecture
 {
 public:
-       class Loader: public Msp::DataFile::Loader
+       class Loader: public Msp::DataFile::ObjectLoader<Architecture>
        {
        public:
                Loader(Architecture &);
-               Architecture &get_object() { return arch; }
-       private:
-               Architecture &arch;
-
-               void tool(const std::string &t, const std::string &p);
        };
 
-       Architecture(Builder &b, const std::string &n, bool a=false);
-       void set_tool(const std::string &t, const std::string &p);
-       std::string get_tool(const std::string &t) const;
+       typedef std::list<Pattern> PatternList;
+
+private:
+       Builder &builder;
+       std::string type;
+       std::string cpu;
+       std::string fpu;
+       std::string system;
+       unsigned bits;
+       std::string toolchain;
+       std::string name;
+       bool native;
+       std::string cross_prefix;
+       std::map<std::string, PatternList> filename_patterns;
+
+public:
+       Architecture(Builder &b, const std::string &spec);
+
+       const std::string &get_type() const { return type; }
        const std::string &get_name() const { return name; }
+       const std::string &get_system() const { return system; }
+       unsigned get_bits() const { return bits; }
+       const std::string &get_cpu() const { return cpu; }
+       const std::string &get_fpu() const { return fpu; }
+       const std::string &get_toolchain() const { return toolchain; }
+       bool match_name(const std::string &) const;
+       std::string best_match(const std::vector<std::string> &) const;
        bool is_native() const { return native; }
-       const std::string &get_prefix() const { return prefix; }
+       bool is_cross() const { return !cross_prefix.empty(); }
+
+       const std::string &get_cross_prefix() const { return cross_prefix; }
+
+       template<typename T>
+       const PatternList &get_patterns() const;
+
+       template<typename T>
+       std::string create_filename(const std::string &) const;
+
 private:
-       Builder     &builder;
-       std::string name;
-       bool        native;
-       std::string prefix;
-       StringMap   tools;
+       template<typename T>
+       void add_pattern(const std::string &);
+
+private:
+       static void resolve_aliases(std::vector<std::string> &);
+       void parse_specification(const std::string &);
 };
 
-typedef std::map<std::string, Architecture> ArchMap;
+template<typename T>
+inline const Architecture::PatternList &Architecture::get_patterns() const
+{
+       std::map<std::string, PatternList>::const_iterator i = filename_patterns.find(typeid(T).name());
+       if(i!=filename_patterns.end())
+               return i->second;
+
+       static PatternList empty;
+       return empty;
+}
+
+template<typename T>
+inline std::string Architecture::create_filename(const std::string &base) const
+{
+       const PatternList &patterns = get_patterns<T>();
+       return patterns.empty() ? base : patterns.front().apply(base);
+}
 
 #endif