3 This file is part of builder
4 Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/path/utils.h>
11 #include "component.h"
13 #include "objectfile.h"
14 #include "sourcefile.h"
15 #include "sourcepackage.h"
20 ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &src):
21 Target(b, &c.get_package(), generate_target_name(c, src.get_name())),
29 Processes as many new dependences as possible. Some may be left unprocessed
30 if their own dependencies are not ready, requiring another call to this
31 function. Use the get_deps_ready() function to determine whether this is the
34 void ObjectFile::find_depends()
36 for(TargetList::iterator i=new_deps.begin(); i!=new_deps.end();)
39 if(tgt->get_depends_ready())
48 deps_ready=new_deps.empty();
53 Recursively looks for header targets and adds them as dependencies.
55 void ObjectFile::find_depends(Target *tgt)
57 const string &tname=tgt->get_name();
58 string path=tname.substr(0, tname.rfind('/'));
60 SourceFile *src=dynamic_cast<SourceFile *>(tgt);
63 Install *inst=dynamic_cast<Install *>(tgt);
65 src=dynamic_cast<SourceFile *>(inst->get_depends().front());
70 const StringList &incpath=comp.get_build_info().incpath;
72 const list<string> &includes=src->get_includes();
73 for(list<string>::const_iterator i=includes.begin(); i!=includes.end(); ++i)
75 Target *hdr2=builder.get_header(*i, path, incpath);
76 if(hdr2 && find(depends.begin(), depends.end(), hdr2)==depends.end())
82 Adds a target to the dependency list as well as the new dependencies list.
84 void ObjectFile::add_depend(Target *tgt)
86 Target::add_depend(tgt);
87 new_deps.push_back(tgt);
90 Action *ObjectFile::create_action()
92 return new Compile(builder, *this);
95 string ObjectFile::generate_target_name(const Component &comp, const string &src)
97 const SourcePackage &pkg=comp.get_package();
98 return (pkg.get_temp_dir()/comp.get_name()/(splitext(basename(src)).base+".o")).str();