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