]> git.tdb.fi Git - builder.git/blobdiff - source/buildinfo.h
Add a list of symbols to keep in the binary to BuildInfo
[builder.git] / source / buildinfo.h
index fbd186c617d1af03a239a30e262175dbf79625fa..1bba8195bc536014270ba8eff7664d31e63e7069 100644 (file)
@@ -1,17 +1,10 @@
-/* $Id$
-
-This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #ifndef BUILDINFO_H_
 #define BUILDINFO_H_
 
 #include <list>
 #include <string>
-#include <msp/parser/loader.h>
-#include "misc.h"
+#include <msp/datafile/objectloader.h>
+#include <msp/fs/path.h>
 
 /**
 Stores information about compiler command line parameters in a more abstract
@@ -20,32 +13,98 @@ form.  Allows combining with other BuildInfos to support package dependencies.
 class BuildInfo
 {
 public:
-       class Loader: public Msp::Parser::Loader
+       enum LibraryMode
+       {
+               FORCE_STATIC,  //< Only accept static libraries
+               STATIC,        //< Prefer static libraries but accept dynamic as well
+               DYNAMIC,       //< Prefer dynamic libraries but accept static as well
+               FORCE_DYNAMIC  //< Only accept dynamic libraries
+       };
+
+       class Loader: public Msp::DataFile::ObjectLoader<BuildInfo>
        {
        public:
                Loader(BuildInfo &);
        private:
-               BuildInfo &binfo;
-               
-               void cflag(const std::string &s)   { binfo.cflags.push_back(s); }
-               void incpath(const std::string &s) { binfo.incpath.push_back(s); }
-               void define(const std::string &s)  { binfo.defines.push_back(s); }
-               void ldflag(const std::string &s)  { binfo.ldflags.push_back(s); }
-               void libpath(const std::string &s) { binfo.libpath.push_back(s); }
-               void library(const std::string &s) { binfo.libs.push_back(s); }
+               void incpath(const std::string &);
+               void define(const std::string &, const std::string &);
+               void keep_symbol(const std::string &);
+               void libmode_for_lib(const std::string &, LibraryMode);
+               void libpath(const std::string &);
+               void library(const std::string &);
+               void local_incpath(const std::string &);
+               void standard(Msp::DataFile::Symbol, const std::string &);
+               void sysroot(const std::string &);
        };
        
-       StringList cflags;
-       StringList defines;
-       StringList incpath;
-       StringList ldflags;
-       StringList libpath;
-       StringList libs;
-
-       void add(const BuildInfo &);
-       void unique();
-private:
-       void unique(StringList &);
+       enum UpdateLevel
+       {
+               LOCAL,       //< Include all information
+               DEPENDENCY,  //< Include all but code generation options
+               CHAINED      //< Include only compilation options
+       };
+
+       /**
+       A wrapper which tracks the set status of the wrapped variable.  A default
+       value may be provided in initialization without causing it to be treated as
+       set.  Assigning from a raw value flags the Tracked object as set.  Assigning
+       from another Tracked object will only change the value of the target if the
+       source is set.  
+       */
+       template<typename T>
+       class Tracked
+       {
+       public:
+               typedef T LoadType;
+
+       private:
+               T value;
+               bool set;
+
+       public:
+               Tracked(): value(T()), set(false) { }
+               Tracked(T v): value(v), set(false) { }
+               Tracked &operator=(const Tracked &v) { if(v.set) { value = v.value; set = true; } return *this; }
+
+               Tracked &operator=(T v) { value = v; set = true; return *this; }
+               operator T() const { return value; }
+       };
+
+       typedef std::map<std::string, std::string> DefineMap;
+       typedef std::list<Msp::FS::Path> PathList;
+       typedef std::list<std::string> WordList;
+       typedef std::map<std::string, LibraryMode> LibModeMap;
+       typedef std::map<std::string, std::string> StandardMap;
+
+       Tracked<Msp::FS::Path> sysroot;
+       DefineMap defines;
+       PathList incpath;
+       PathList local_incpath;
+       PathList libpath;
+       WordList libs;
+       Tracked<LibraryMode> libmode;
+       LibModeMap libmodes;
+       WordList keep_symbols;
+       StandardMap standards;
+       Tracked<bool> threads;
+       Tracked<bool> debug;
+       Tracked<int> optimize;
+       Tracked<bool> strip;
+       Tracked<unsigned> warning_level;
+       Tracked<bool> fatal_warnings;
+
+       BuildInfo();
+
+       /** Returns the library mode for linking a particular library.  If no mode
+       has been specified for that library, the the global library mode is
+       returned. */
+       LibraryMode get_libmode_for(const std::string &) const;
+
+       /** Updates the BuildInfo from another one.  Lists are concatenated, with
+       the first occurrence of each item preserved.  Scalars are overwritten.
+       
+       The update level determines what information is updated. */
+       void update_from(const BuildInfo &, UpdateLevel = LOCAL);
 };
 
 #endif