3 This file is part of builder
4 Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/fs/dir.h>
9 #include <msp/fs/utils.h>
11 #include "component.h"
12 #include "executable.h"
15 #include "objectfile.h"
17 #include "sharedlibrary.h"
18 #include "staticlibrary.h"
19 #include "systemlibrary.h"
24 Link::Link(Builder &b, const Binary &bin):
27 const Component &comp = bin.get_component();
29 work_dir = comp.get_package().get_source();
31 //XXX Determine whether to use g++ or gcc
33 argv.push_back(builder.get_current_arch().get_tool(tool));
35 if(comp.get_type()==Component::LIBRARY || comp.get_type()==Component::MODULE)
36 argv.push_back("-shared");
37 else if(comp.get_package().get_library_mode()==ALL_STATIC)
38 argv.push_back("-static");
40 const BuildInfo &binfo = comp.get_build_info();
41 for(list<string>::const_iterator i=binfo.ldflags.begin(); i!=binfo.ldflags.end(); ++i)
43 for(list<string>::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
44 argv.push_back("-L"+*i);
47 argv.push_back(relative(bin.get_path(), work_dir).str());
48 const TargetList &deps = bin.get_depends();
49 for(TargetList::const_iterator i=deps.begin(); i!=deps.end(); ++i)
52 if(Install *inst = dynamic_cast<Install *>(tgt))
53 tgt = &inst->get_source();
55 if(ObjectFile *obj = dynamic_cast<ObjectFile *>(tgt))
56 argv.push_back(relative(obj->get_path(), work_dir).str());
57 else if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(tgt))
58 argv.push_back(stlib->get_path().str());
59 else if(Library *lib = dynamic_cast<Library *>(tgt))
60 argv.push_back("-l"+lib->get_libname());
63 FS::Path binpath = bin.get_path();
64 if(!builder.get_dry_run())
65 FS::mkpath(FS::dirname(binpath), 0755);
67 announce(comp.get_package().get_name(), tool, relative(binpath, work_dir).str().substr(2));