]> git.tdb.fi Git - builder.git/blob - source/compile.cpp
Improve file target naming
[builder.git] / source / compile.cpp
1 #include <msp/fs/dir.h>
2 #include <msp/fs/utils.h>
3 #include "builder.h"
4 #include "buildinfo.h"
5 #include "compile.h"
6 #include "component.h"
7 #include "objectfile.h"
8 #include "sourcefile.h"
9 #include "sourcepackage.h"
10
11 using namespace std;
12 using namespace Msp;
13
14 Compile::Compile(Builder &b, const ObjectFile &obj):
15         ExternalAction(b)
16 {
17         const Component &comp = obj.get_component();
18
19         work_dir = comp.get_package().get_source();
20
21         FS::Path spath = obj.get_source().get_path();
22
23         string ext = FS::extpart(spath.str());
24         const char *tool = 0;
25         if(ext==".cpp" || ext==".cc")
26                 tool = "CXX";
27         else
28                 tool = "CC";
29
30         argv.push_back(builder.get_current_arch().get_tool(tool));
31         argv.push_back("-c");
32
33         const BuildInfo &binfo = comp.get_build_info();
34         for(list<string>::const_iterator i=binfo.warnings.begin(); i!=binfo.warnings.end(); ++i)
35                 argv.push_back("-W"+*i);
36         for(list<string>::const_iterator i=binfo.cflags.begin(); i!=binfo.cflags.end(); ++i)
37                 argv.push_back(*i);
38         for(list<string>::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
39                 argv.push_back("-I"+*i);
40         for(list<string>::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
41                 argv.push_back("-D"+*i);
42
43         FS::Path opath = obj.get_path();
44         argv.push_back("-o");
45         argv.push_back(relative(opath, work_dir).str());
46         argv.push_back(relative(spath, work_dir).str());
47
48         if(!builder.get_dry_run())
49                 FS::mkpath(FS::dirname(opath), 0755);
50
51         announce(comp.get_package().get_name(), tool, basename(opath));
52
53         launch();
54 }