]> git.tdb.fi Git - builder.git/blob - source/compile.cpp
15aaee9e800477f30ebf475ca96ff4ce64928ff9
[builder.git] / source / compile.cpp
1 #include <msp/path/utils.h>
2 #include "buildinfo.h"
3 #include "compile.h"
4 #include "component.h"
5 #include "package.h"
6
7 using namespace std;
8 using namespace Msp;
9
10 Compile::Compile(Builder &b, const Path::Path &s, const Path::Path &o, const Component &c):
11         ExternalAction(b),
12         source(s),
13         object(o),
14         comp(c)
15 {
16         string ext=Path::splitext(source.str()).ext;
17         const char *tool=0;
18         if(ext==".cpp" || ext==".cc")
19         {
20                 tool="CXX";
21                 argv.push_back("g++");
22         }
23         else
24         {
25                 tool="CC";
26                 argv.push_back("gcc");
27         }
28         argv.push_back("-c");
29         
30         const BuildInfo &binfo=comp.get_build_info();
31         for(list<string>::const_iterator i=binfo.cflags.begin(); i!=binfo.cflags.end(); ++i)
32                 argv.push_back(*i);
33         for(list<string>::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
34                 argv.push_back("-I"+*i);
35         for(list<string>::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
36                 argv.push_back("-D"+*i);
37         
38         argv.push_back("-o");
39         argv.push_back(object.str());
40         argv.push_back(source.str());
41
42         Path::mkpath(object.subpath(0, object.size()-1), 0755);
43
44         announce(comp.get_package().get_name(), tool, relative(object.str(), comp.get_package().get_source()).str());
45
46         launch();
47 }