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>
10 #include "component.h"
11 #include "executable.h"
14 #include "objectfile.h"
16 #include "sharedlibrary.h"
17 #include "staticlibrary.h"
18 #include "systemlibrary.h"
23 Link::Link(Builder &b, const Executable &exe):
26 const Component &comp=exe.get_component();
28 //XXX Determine whether to use g++ or gcc
29 argv.push_back(builder.get_tool("LDXX", comp.get_package().get_arch()));
31 if(comp.get_type()==Component::LIBRARY || comp.get_type()==Component::MODULE)
32 argv.push_back("-shared");
33 else if(comp.get_package().get_library_mode()==ALL_STATIC)
34 argv.push_back("-static");
36 const BuildInfo &binfo=comp.get_build_info();
37 for(list<string>::const_iterator i=binfo.ldflags.begin(); i!=binfo.ldflags.end(); ++i)
39 for(list<string>::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
40 argv.push_back("-L"+*i);
43 argv.push_back(exe.get_name());
44 const TargetList &deps=exe.get_depends();
45 for(TargetList::const_iterator i=deps.begin(); i!=deps.end(); ++i)
48 if(dynamic_cast<Install *>(tgt))
49 tgt=tgt->get_depends().front();
51 if(dynamic_cast<ObjectFile *>(tgt))
52 argv.push_back((*i)->get_name());
53 else if(SharedLibrary *shlib=dynamic_cast<SharedLibrary *>(tgt))
54 argv.push_back("-l"+shlib->get_libname());
55 else if(dynamic_cast<StaticLibrary *>(tgt))
56 argv.push_back((*i)->get_name());
57 else if(SystemLibrary *syslib=dynamic_cast<SystemLibrary *>(tgt))
58 argv.push_back("-l"+syslib->get_libname());
61 Path::Path epath=exe.get_name();
62 if(!builder.get_dry_run())
63 Path::mkpath(epath.subpath(0, epath.size()-1), 0755);
65 announce(comp.get_package().get_name(), "LINK", relative(epath, comp.get_package().get_source()).str());