+#include <algorithm>
#include <msp/io/print.h>
#include <msp/strings/utils.h>
#include "binarypackage.h"
#include "builder.h"
+#include "filetarget.h"
+#include "staticlibrary.h"
using namespace std;
using namespace Msp;
use_pkgconfig = false;
}
+BinaryPackage *BinaryPackage::from_flags(Builder &builder, const string &name, const Flags &flags, const Flags &static_flags)
+{
+ BinaryPackage *pkg = new BinaryPackage(builder, name);
+ pkg->use_pkgconfig = true;
+
+ process_flags(flags, pkg->export_binfo);
+
+ Flags exclusive_static_flags;
+ for(Flags::const_iterator i=static_flags.begin(); i!=static_flags.end(); ++i)
+ if(find(flags.begin(), flags.end(), *i)==flags.end())
+ exclusive_static_flags.push_back(*i);
+ process_flags(exclusive_static_flags, pkg->static_binfo);
+
+ return pkg;
+}
+
+void BinaryPackage::process_flags(const Flags &flags, BuildInfo &binfo)
+{
+ for(Flags::const_iterator i=flags.begin(); i!=flags.end(); ++i)
+ {
+ if(!i->compare(0, 2, "-I"))
+ binfo.incpath.push_back(i->substr(2));
+ else if(!i->compare(0, 2, "-D"))
+ {
+ string::size_type equals = i->find('=');
+ if(equals!=string::npos)
+ binfo.defines[i->substr(2, equals-2)] = i->substr(equals+1);
+ else
+ binfo.defines[i->substr(2)] = string();
+ }
+ else if(!i->compare(0, 2, "-L"))
+ binfo.libpath.push_back(i->substr(2));
+ else if(!i->compare(0, 2, "-l"))
+ binfo.libs.push_back(i->substr(2));
+ else if(*i=="-pthread")
+ binfo.threads = true;
+ }
+}
+
void BinaryPackage::do_prepare()
{
bool has_relative_paths = false;
for(BuildInfo::PathList::const_iterator i=export_binfo.libpath.begin(); (!has_relative_paths && i!=export_binfo.libpath.end()); ++i)
has_relative_paths = !i->is_absolute();
+ for(BuildInfo::PathList::const_iterator i=export_binfo.incpath.begin(); (!has_relative_paths && i!=export_binfo.incpath.end()); ++i)
+ has_relative_paths = !i->is_absolute();
list<FS::Path> bases;
/* If we have any relative paths that need resolving, or we have no paths at
all and are not using pkg-config, look for files in prefix */
- if(has_relative_paths || (!use_pkgconfig && export_binfo.libpath.empty()))
+ if(has_relative_paths || (!use_pkgconfig && export_binfo.libpath.empty() && export_binfo.incpath.empty()))
bases.push_back(builder.get_prefix());
// Always look in system locations
for(BuildInfo::WordList::const_iterator j=export_binfo.libs.begin(); j!=export_binfo.libs.end(); ++j)
all_found &= (builder.get_vfs().find_library(*j, libpath, export_binfo.libmode, system)!=0);
+ BuildInfo::PathList incpath = export_binfo.incpath;
+ if(!system && incpath.empty())
+ incpath.push_back("include");
+ for(BuildInfo::PathList::iterator j=incpath.begin(); j!=incpath.end(); ++j)
+ *j = prefix/ *j;
+
+ for(HeaderList::const_iterator j=headers.begin(); j!=headers.end(); ++j)
+ all_found &= (builder.get_vfs().find_header(*j, 0, incpath, system)!=0);
+
if(all_found)
{
base_path = prefix;
if(base_path.empty())
{
- builder.problem(name, "Cannot locate files");
+ // TODO report which files were not found
+ builder.get_logger().log("problems", format("Cannot locate files for %s", name));
+ problems.push_back("Cannot locate files");
return;
}
if(!system && export_binfo.libpath.empty())
export_binfo.libpath.push_back(base_path/"lib");
- for(BuildInfo::PathList::iterator i=export_binfo.incpath.begin(); i!=export_binfo.incpath.end(); ++i)
- *i = base_path/ *i;
- for(BuildInfo::PathList::iterator i=export_binfo.libpath.begin(); i!=export_binfo.libpath.end(); ++i)
- *i = base_path/ *i;
-}
-
-BinaryPackage *BinaryPackage::from_flags(Builder &builder, const string &name, const vector<string> &flags)
-{
- BinaryPackage *pkg = new BinaryPackage(builder, name);
- pkg->use_pkgconfig = true;
- BuildInfo &binfo = pkg->export_binfo;
-
- for(vector<string>::const_iterator i=flags.begin(); i!=flags.end(); ++i)
+ if(has_relative_paths)
{
- if(!i->compare(0, 2, "-I"))
- binfo.incpath.push_back(i->substr(2));
- else if(!i->compare(0, 2, "-D"))
- {
- string::size_type equals = i->find('=');
- if(equals!=string::npos)
- binfo.defines[i->substr(2, equals-2)] = i->substr(equals+1);
- else
- binfo.defines[i->substr(2)] = string();
- }
- else if(!i->compare(0, 2, "-L"))
- binfo.libpath.push_back(i->substr(2));
- else if(!i->compare(0, 2, "-l"))
- binfo.libs.push_back(i->substr(2));
- else if(*i=="-pthread")
- binfo.threads = true;
+ for(BuildInfo::PathList::iterator i=export_binfo.incpath.begin(); i!=export_binfo.incpath.end(); ++i)
+ *i = base_path/ *i;
+ for(BuildInfo::PathList::iterator i=export_binfo.libpath.begin(); i!=export_binfo.libpath.end(); ++i)
+ *i = base_path/ *i;
}
- return pkg;
+ if(!static_binfo.libs.empty())
+ {
+ BuildInfo::PathList combined_libpath = static_binfo.libpath;
+ combined_libpath.insert(combined_libpath.end(), export_binfo.libpath.begin(), export_binfo.libpath.end());
+
+ for(BuildInfo::WordList::const_iterator i=export_binfo.libs.begin(); i!=export_binfo.libs.end(); ++i)
+ if(Target *lib = builder.get_vfs().find_library(*i, export_binfo.libpath, BuildInfo::FORCE_STATIC, system))
+ if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(lib))
+ {
+ for(BuildInfo::WordList::const_iterator j=static_binfo.libs.begin(); j!=static_binfo.libs.end(); ++j)
+ stlib->add_required_library(*j);
+ for(BuildInfo::PathList::const_iterator j=combined_libpath.begin(); j!=combined_libpath.end(); ++j)
+ stlib->add_library_path(*j);
+ }
+ }
}
BinaryPackage::Loader::Loader(BinaryPackage &p):
- DataFile::DerivedObjectLoader<BinaryPackage, Package>(p)
+ DataFile::DerivedObjectLoader<BinaryPackage, Package::Loader>(p)
{
add("build_info", &Loader::build_info);
+ add("header", &Loader::header);
}
void BinaryPackage::Loader::build_info()
{
load_sub(obj.export_binfo);
}
+
+void BinaryPackage::Loader::header(const string &h)
+{
+ obj.headers.push_back(h);
+}