]> git.tdb.fi Git - builder.git/blobdiff - source/compile.cpp
Change arch and prefix to global options
[builder.git] / source / compile.cpp
index 15aaee9e800477f30ebf475ca96ff4ce64928ff9..53802639dae7786675aff8e9ff994582bed2334b 100644 (file)
@@ -1,32 +1,39 @@
+/* $Id$
+
+This file is part of builder
+Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
 #include <msp/path/utils.h>
+#include "builder.h"
 #include "buildinfo.h"
 #include "compile.h"
 #include "component.h"
-#include "package.h"
+#include "objectfile.h"
+#include "sourcepackage.h"
 
 using namespace std;
 using namespace Msp;
 
-Compile::Compile(Builder &b, const Path::Path &s, const Path::Path &o, const Component &c):
-       ExternalAction(b),
-       source(s),
-       object(o),
-       comp(c)
+Compile::Compile(Builder &b, const ObjectFile &obj):
+       ExternalAction(b)
 {
-       string ext=Path::splitext(source.str()).ext;
+       const Component &comp=obj.get_component();
+
+       const TargetList &deps=obj.get_depends();
+       Path spath=deps.front()->get_name();
+
+       string ext=splitext(spath.str()).ext;
        const char *tool=0;
        if(ext==".cpp" || ext==".cc")
-       {
                tool="CXX";
-               argv.push_back("g++");
-       }
        else
-       {
                tool="CC";
-               argv.push_back("gcc");
-       }
+
+       argv.push_back(builder.get_current_arch().get_tool(tool));
        argv.push_back("-c");
-       
+
        const BuildInfo &binfo=comp.get_build_info();
        for(list<string>::const_iterator i=binfo.cflags.begin(); i!=binfo.cflags.end(); ++i)
                argv.push_back(*i);
@@ -34,14 +41,16 @@ Compile::Compile(Builder &b, const Path::Path &s, const Path::Path &o, const Com
                argv.push_back("-I"+*i);
        for(list<string>::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
                argv.push_back("-D"+*i);
-       
+
+       Path opath=obj.get_name();
        argv.push_back("-o");
-       argv.push_back(object.str());
-       argv.push_back(source.str());
+       argv.push_back(opath.str());
+       argv.push_back(spath.str());
 
-       Path::mkpath(object.subpath(0, object.size()-1), 0755);
+       if(!builder.get_dry_run())
+               mkpath(opath.subpath(0, opath.size()-1), 0755);
 
-       announce(comp.get_package().get_name(), tool, relative(object.str(), comp.get_package().get_source()).str());
+       announce(comp.get_package().get_name(), tool, relative(opath, comp.get_package().get_source()).str());
 
        launch();
 }