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