]> git.tdb.fi Git - builder.git/blob - source/compile.cpp
Make warnings configurable through build_info and command line
[builder.git] / source / compile.cpp
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include <msp/path/utils.h>
9 #include "builder.h"
10 #include "buildinfo.h"
11 #include "compile.h"
12 #include "component.h"
13 #include "objectfile.h"
14 #include "sourcepackage.h"
15
16 using namespace std;
17 using namespace Msp;
18
19 Compile::Compile(Builder &b, const ObjectFile &obj):
20         ExternalAction(b)
21 {
22         const Component &comp=obj.get_component();
23
24         work_dir=comp.get_package().get_source();
25
26         const TargetList &deps=obj.get_depends();
27         Path spath=deps.front()->get_name();
28
29         string ext=splitext(spath.str()).ext;
30         const char *tool=0;
31         if(ext==".cpp" || ext==".cc")
32                 tool="CXX";
33         else
34                 tool="CC";
35
36         argv.push_back(builder.get_current_arch().get_tool(tool));
37         argv.push_back("-c");
38
39         const BuildInfo &binfo=comp.get_build_info();
40         for(list<string>::const_iterator i=binfo.warnings.begin(); i!=binfo.warnings.end(); ++i)
41                 argv.push_back("-W"+*i);
42         for(list<string>::const_iterator i=binfo.cflags.begin(); i!=binfo.cflags.end(); ++i)
43                 argv.push_back(*i);
44         for(list<string>::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
45                 argv.push_back("-I"+*i);
46         for(list<string>::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
47                 argv.push_back("-D"+*i);
48
49         Path opath=obj.get_name();
50         argv.push_back("-o");
51         argv.push_back(relative(opath, work_dir).str());
52         argv.push_back(relative(spath, work_dir).str());
53
54         if(!builder.get_dry_run())
55                 mkpath(opath.subpath(0, opath.size()-1), 0755);
56
57         announce(comp.get_package().get_name(), tool, relative(opath, work_dir).str());
58
59         launch();
60 }