1 #include <msp/path/utils.h>
4 #include "executable.h"
7 #include "objectfile.h"
9 #include "sharedlibrary.h"
10 #include "staticlibrary.h"
11 #include "systemlibrary.h"
16 Link::Link(Builder &b, const Executable &exe):
19 const Component &comp=exe.get_component();
21 //XXX Determine whether to use g++ or gcc
22 argv.push_back("g++");
24 if(comp.get_type()==Component::LIBRARY)
25 argv.push_back("-shared");
26 else if(comp.get_package().get_config().get_option("staticlibs").value=="all")
27 argv.push_back("-static");
29 const BuildInfo &binfo=comp.get_build_info();
30 for(list<string>::const_iterator i=binfo.ldflags.begin(); i!=binfo.ldflags.end(); ++i)
32 for(list<string>::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
33 argv.push_back("-L"+*i);
36 argv.push_back(exe.get_name());
37 const TargetList &deps=exe.get_depends();
38 for(TargetList::const_iterator i=deps.begin(); i!=deps.end(); ++i)
41 if(dynamic_cast<Install *>(tgt))
42 tgt=tgt->get_depends().front();
44 if(dynamic_cast<ObjectFile *>(tgt))
45 argv.push_back((*i)->get_name());
46 else if(SharedLibrary *shlib=dynamic_cast<SharedLibrary *>(tgt))
47 argv.push_back("-l"+shlib->get_libname());
48 else if(dynamic_cast<StaticLibrary *>(tgt))
49 argv.push_back((*i)->get_name());
50 else if(SystemLibrary *syslib=dynamic_cast<SystemLibrary *>(tgt))
51 argv.push_back("-l"+syslib->get_libname());
54 Path::Path epath=exe.get_name();
55 if(!builder.get_dry_run())
56 Path::mkpath(epath.subpath(0, epath.size()-1), 0755);
58 announce(comp.get_package().get_name(), "LINK", relative(epath, comp.get_package().get_source()).str());