#include <vector>
#include <msp/fs/dir.h>
#include <msp/fs/utils.h>
+#include <msp/strings/format.h>
#include "builder.h"
#include "component.h"
#include "executable.h"
{
input_suffixes.push_back(".o");
input_suffixes.push_back(".a");
+
+ const Architecture &arch = builder.get_current_arch();
+ if(arch.is_native())
+ {
+ system_path.push_back("/lib");
+ system_path.push_back("/usr/lib");
+ if(arch.match_name("pc-32-linux"))
+ system_path.push_back("/usr/lib/i386-linux-gnu");
+ else if(arch.match_name("pc-64-linux"))
+ system_path.push_back("/usr/lib/x86_64-linux-gnu");
+ }
+ else
+ system_path.push_back("/usr/"+arch.get_cross_prefix()+"/lib");
}
Target *GnuLinker::create_target(const list<Target *> &sources, const std::string &arg) const
Task *GnuLinker::run(const Target &target) const
{
const Binary &bin = dynamic_cast<const Binary &>(target);
- const SharedLibrary *shlib = dynamic_cast<const SharedLibrary *>(&bin);
string command = "gcc";
if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
{
const Tool *tool = obj->get_tool();
- if(dynamic_cast<const GnuCxxCompiler *>(tool))
+ if(tool->get_tag()=="CXX")
command = "g++";
}
vector<string> argv;
argv.push_back(command);
- const Component &comp = bin.get_component();
+ const Component &comp = *bin.get_component();
- if(shlib)
+ if(const SharedLibrary *shlib = dynamic_cast<const SharedLibrary *>(&bin))
{
argv.push_back("-shared");
+ argv.push_back("-fPIC");
if(!shlib->get_soname().empty())
argv.push_back("-Wl,-soname,"+shlib->get_soname());
}
argv.push_back("-static");
const BuildInfo &binfo = comp.get_build_info();
- for(list<string>::const_iterator i=binfo.ldflags.begin(); i!=binfo.ldflags.end(); ++i)
- argv.push_back(*i);
- for(list<string>::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
- argv.push_back("-L"+*i);
+ for(BuildInfo::PathList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
+ argv.push_back("-L"+i->str());
+ if(binfo.strip)
+ argv.push_back("-s");
+ if(binfo.threads)
+ argv.push_back("-pthread");
+
+ const Architecture &arch = builder.get_current_arch();
+ const Architecture &native_arch = builder.get_native_arch();
+ if(arch.get_bits()!=native_arch.get_bits())
+ argv.push_back(format("-m%d", arch.get_bits()));
FS::Path work_dir = comp.get_package().get_source();
argv.push_back(relative(obj->get_path(), work_dir).str());
else if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(tgt))
argv.push_back(stlib->get_path().str());
- else if(Library *lib = dynamic_cast<Library *>(tgt))
- argv.push_back("-l"+lib->get_libname());
+ else if(SharedLibrary *shlib = dynamic_cast<SharedLibrary *>(tgt))
+ argv.push_back("-l"+shlib->get_libname());
}
if(!builder.get_dry_run())