2 #include <msp/fs/utils.h>
3 #include <msp/strings/format.h>
4 #include "architecture.h"
7 #include "exportdefinitions.h"
8 #include "externaltask.h"
9 #include "importlibrary.h"
10 #include "installedfile.h"
11 #include "mingwdlltool.h"
12 #include "sharedlibrary.h"
13 #include "sourcepackage.h"
18 MingwDllTool::MingwDllTool(Builder &b, const Architecture &a):
21 string command = "dlltool";
22 if(architecture->is_cross())
23 command = format("%s-%s", architecture->get_cross_prefix(), command);
24 executable = builder.get_vfs().find_binary(command);
27 Target *MingwDllTool::create_target(const list<Target *> &sources, const string &) const
30 throw invalid_argument("MingwDllTool::create_target");
31 ExportDefinitions &def = dynamic_cast<ExportDefinitions &>(*sources.front());
32 ImportLibrary *imp = new ImportLibrary(builder, *def.get_component(), def);
37 Target *MingwDllTool::create_install(Target &target) const
39 if(ImportLibrary *imp = dynamic_cast<ImportLibrary *>(&target))
41 const Tool © = builder.get_toolchain().get_tool("CP");
42 InstalledFile *inst_tgt = dynamic_cast<InstalledFile *>(copy.create_target(target));
43 string link_name = format("lib%s.dll.a", imp->get_shared_library()->get_libname());
44 if(link_name!=FS::basename(inst_tgt->get_path()))
45 inst_tgt->set_symlink(link_name);
52 Task *MingwDllTool::run(const Target &target) const
54 const ImportLibrary &imp = dynamic_cast<const ImportLibrary &>(target);
55 const ExportDefinitions &exp = dynamic_cast<const ExportDefinitions &>(*imp.get_dependencies().front());
56 const SharedLibrary &shlib = exp.get_library();
59 argv.push_back(executable->get_path().str());
61 /* dlltool is stupid and puts temporary files in the working directory by
63 argv.push_back("--temp-prefix");
65 for(unsigned i=0; i<8; ++i)
66 random[i] = 'a'+(rand()%26);
67 argv.push_back(string("/tmp/")+string(random, 8));
69 const Component &comp = *imp.get_component();
70 FS::Path work_dir = comp.get_package().get_source_directory();
73 argv.push_back(relative(exp.get_path(), work_dir).str());
76 if(shlib.get_install_filename().empty())
77 argv.push_back(FS::basename(shlib.get_path()));
79 argv.push_back(shlib.get_install_filename());
82 argv.push_back(relative(imp.get_path(), work_dir).str());
84 return new ExternalTask(argv, work_dir);