]> git.tdb.fi Git - builder.git/blob - source/compile.cpp
Better encapsulation of config inside Package
[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 "objectfile.h"
7 #include "package.h"
8
9 using namespace std;
10 using namespace Msp;
11
12 Compile::Compile(Builder &b, const ObjectFile &obj):
13         ExternalAction(b)
14 {
15         const Component &comp=obj.get_component();
16
17         const TargetList &deps=obj.get_depends();
18         Path::Path spath=deps.front()->get_name();
19
20         const string &prefix=b.get_arch_prefix(obj.get_package()->get_arch());
21
22         string ext=Path::splitext(spath.str()).ext;
23         const char *tool=0;
24         if(ext==".cpp" || ext==".cc")
25         {
26                 tool="CXX";
27                 argv.push_back(prefix+"g++");
28         }
29         else
30         {
31                 tool="CC";
32                 argv.push_back(prefix+"gcc");
33         }
34         argv.push_back("-c");
35         
36         const BuildInfo &binfo=comp.get_build_info();
37         for(list<string>::const_iterator i=binfo.cflags.begin(); i!=binfo.cflags.end(); ++i)
38                 argv.push_back(*i);
39         for(list<string>::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
40                 argv.push_back("-I"+*i);
41         for(list<string>::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
42                 argv.push_back("-D"+*i);
43         
44         Path::Path opath=obj.get_name();
45         argv.push_back("-o");
46         argv.push_back(opath.str());
47         argv.push_back(spath.str());
48
49         if(!builder.get_dry_run())
50                 Path::mkpath(opath.subpath(0, opath.size()-1), 0755);
51
52         announce(comp.get_package().get_name(), tool, relative(opath, comp.get_package().get_source()).str());
53
54         launch();
55 }