]> git.tdb.fi Git - builder.git/commitdiff
Add basic support for tools (not configurable yet)
authorMikko Rasa <tdb@tdb.fi>
Tue, 27 Mar 2007 16:53:31 +0000 (16:53 +0000)
committerMikko Rasa <tdb@tdb.fi>
Tue, 27 Mar 2007 16:53:31 +0000 (16:53 +0000)
Fix several uninitialized variables

source/archive.cpp
source/builder.cpp
source/builder.h
source/compile.cpp
source/link.cpp
source/package.cpp

index 7da7250f1d47c0beba22051221d93ffc9d1744cb..cd25de1e2d90f4ef0516edf29f4efb4c1a9980eb 100644 (file)
@@ -14,9 +14,7 @@ Archive::Archive(Builder &b, const StaticLibrary &lib):
 {
        const Component &comp=lib.get_component();
 
-       const string &prefix=b.get_arch_prefix(lib.get_package()->get_arch());
-
-       argv.push_back(prefix+"ar");
+       argv.push_back(builder.get_tool("AR", lib.get_package()->get_arch()));
        argv.push_back("rc");
 
        argv.push_back(lib.get_name());
index f23e85af8c06d17c1056734a0bb2ce3995d82425..31cdd1806aa62b5e921ed531d73631920a8baf3a 100644 (file)
@@ -29,10 +29,15 @@ using namespace Msp;
 Builder::Builder(int argc, char **argv):
        analyzer(0),
        do_build(false),
+       dry_run(false),
+       help(false),
        verbose(1),
        chrome(false),
        build_file("Build"),
-       jobs(1)
+       jobs(1),
+       conf_all(false),
+       conf_only(false),
+       build_all(false)
 {
        string   analyze_mode;
        string   work_dir;
@@ -100,6 +105,13 @@ Builder::Builder(int argc, char **argv):
        archs.insert(StringMap::value_type("native", ""));
        archs.insert(StringMap::value_type("arm", "arm-linux-gnu-"));
        archs.insert(StringMap::value_type("win32", "i586-mingw32msvc-"));
+
+       StringMap &native_tools=tools.insert(ToolMap::value_type("native", StringMap())).first->second;
+       native_tools.insert(StringMap::value_type("CC",   "gcc"));
+       native_tools.insert(StringMap::value_type("CXX",  "g++"));
+       native_tools.insert(StringMap::value_type("LD",   "gcc"));
+       native_tools.insert(StringMap::value_type("LDXX", "g++"));
+       native_tools.insert(StringMap::value_type("AR",   "ar"));
 }
 
 /**
@@ -249,6 +261,25 @@ const string &Builder::get_arch_prefix(const string &arch) const
        return i->second;
 }
 
+string Builder::get_tool(const std::string &tool, const std::string &arch)
+{
+       ToolMap::iterator i=tools.find(arch);
+       if(i!=tools.end())
+       {
+               StringMap::iterator j=i->second.find(tool);
+               if(j!=i->second.end())
+                       return j->second;
+       }
+
+       // Either the arch, or the tool within the arch was not found
+       i=tools.find("native");
+       StringMap::iterator j=i->second.find(tool);
+       if(j==i->second.end())
+               throw InvalidParameterValue("Unknown tool");
+
+       return get_arch_prefix(arch)+j->second;
+}
+
 int Builder::main()
 {
        if(load_build_file(cwd/build_file))
index 98e541da348ba5264ef5cac7d861ed7bf0d4def7..3e3388dbc4b41043ee0cb0278da362b227bc01d2 100644 (file)
@@ -30,6 +30,7 @@ public:
        Target   *get_library(const std::string &, const StringList &, LibMode);
        const Msp::Path::Path &get_cwd() const { return cwd; }
        const std::string &get_arch_prefix(const std::string &) const;
+       std::string get_tool(const std::string &, const std::string &);
        int      main();
        ~Builder();
 
@@ -49,7 +50,7 @@ private:
        typedef std::list<Package *>               PackageList;
        typedef std::map<std::string, Package *>   PackageMap;
        typedef std::map<std::string, Target *>    TargetMap;
-       typedef std::map<std::string, std::string> ToolMap;
+       typedef std::map<std::string, StringMap>   ToolMap;
        
        StringList   cmdline_targets;
        RawOptionMap cmdline_options;
@@ -65,7 +66,7 @@ private:
        TargetMap    libraries;
 
        ToolMap      tools;    /// Not used yet
-       StringMap    archs;    /// arch -> prefix
+       StringMap    archs;    //< arch -> prefix
        
        Analyzer        *analyzer;
        bool            do_build;
index 02ae493ea1892a4002c320a88d4ab9997ade1634..5162da67f6b683104141bbb891d68ad55bc18653 100644 (file)
@@ -17,20 +17,14 @@ Compile::Compile(Builder &b, const ObjectFile &obj):
        const TargetList &deps=obj.get_depends();
        Path::Path spath=deps.front()->get_name();
 
-       const string &prefix=b.get_arch_prefix(obj.get_package()->get_arch());
-
        string ext=Path::splitext(spath.str()).ext;
        const char *tool=0;
        if(ext==".cpp" || ext==".cc")
-       {
                tool="CXX";
-               argv.push_back(prefix+"g++");
-       }
        else
-       {
                tool="CC";
-               argv.push_back(prefix+"gcc");
-       }
+
+       argv.push_back(builder.get_tool(tool, obj.get_package()->get_arch()));
        argv.push_back("-c");
        
        const BuildInfo &binfo=comp.get_build_info();
index 4a96ff2e4da59b2bde1f1173584d863890f5b09a..2f688be4cbd73fb1788348a717de1df52bcdeb3c 100644 (file)
@@ -18,10 +18,8 @@ Link::Link(Builder &b, const Executable &exe):
 {
        const Component &comp=exe.get_component();
 
-       const string &prefix=b.get_arch_prefix(exe.get_package()->get_arch());
-
        //XXX Determine whether to use g++ or gcc
-       argv.push_back(prefix+"g++");
+       argv.push_back(builder.get_tool("LDXX", exe.get_package()->get_arch()));
        
        if(comp.get_type()==Component::LIBRARY || comp.get_type()==Component::MODULE)
                argv.push_back("-shared");
index 031ceb5f95c3a0bac333ed5c50df60137c71e834..2e7932c1c57a93dbed709797eb14a05b5a9572ea 100644 (file)
@@ -188,7 +188,8 @@ Package *Package::create(Builder &b, const string &name)
 Package::Package(Builder &b, const string &n, const vector<string> &info):
        builder(b),
        name(n),
-       buildable(false)
+       buildable(false),
+       conf_done(false)
 {
        for(vector<string>::const_iterator i=info.begin(); i!=info.end(); ++i)
        {
@@ -273,6 +274,7 @@ void Package::create_build_info()
                if(lexical_cast<unsigned>(optimize))
                {
                        build_info.cflags.push_back("-O"+optimize);
+                       build_info.ldflags.push_back("-O"+optimize);
                        string cpu=config.get_option("cpu").value;
                        if(cpu!="auto")
                                build_info.cflags.push_back("-march="+cpu);