]> git.tdb.fi Git - builder.git/blobdiff - source/component.cpp
Remove a useless path-to-string conversion
[builder.git] / source / component.cpp
index c440e4c90df9c07c30db084f75d5fc8678963d73..c12399f670f944e2a22f953862f3763ba05ff795 100644 (file)
@@ -1,12 +1,4 @@
-/* $Id$
-
-This file is part of builder
-Copyright © 2006-2010  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include <algorithm>
-#include <msp/core/except.h>
 #include <msp/fs/dir.h>
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
@@ -23,7 +15,6 @@ Distributed under the LGPL
 #include "sharedlibrary.h"
 #include "sourcepackage.h"
 #include "staticlibrary.h"
-#include "symlink.h"
 #include "tarball.h"
 #include "target.h"
 
@@ -35,11 +26,18 @@ Component::Component(SourcePackage &p, Type t, const string &n):
        type(t),
        name(n),
        install(false),
-       module_host(0),
-       modular(false),
        deflt(true)
 { }
 
+void Component::configure(const StringMap &opts, unsigned flag)
+{
+       for(StringList::iterator i=sources.begin(); i!=sources.end(); ++i)
+               *i = (pkg.get_source()/pkg.expand_string(*i)).str();
+
+       for(PackageList::const_iterator i=requires.begin(); i!=requires.end(); ++i)
+               (*i)->configure(opts, flag&2);
+}
+
 void Component::create_build_info()
 {
        const PackageList &pkg_reqs = pkg.get_requires();
@@ -92,18 +90,6 @@ void Component::create_build_info()
                build_info.cflags.push_back("-fPIC");
        }
 
-       if(modular)
-       {
-               build_info.ldflags.push_back("-rdynamic");
-               build_info.libs.push_back("dl");
-       }
-       else if(module_host)
-       {
-               const PathList &host_src = module_host->get_sources();
-               for(PathList::const_iterator i=host_src.begin(); i!=host_src.end(); ++i)
-                       build_info.incpath.push_back(i->str());
-       }
-
        build_info.unique();
 }
 
@@ -126,8 +112,8 @@ void Component::create_targets() const
 
                if(name=="@src")
                {
-                       const TargetMap &targets = builder.get_targets();
-                       for(TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
+                       const Builder::TargetMap &targets = builder.get_targets();
+                       for(Builder::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
                                if(i->second->get_package()==&pkg && !i->second->is_buildable())
                                        result->add_depend(i->second);
                        files.push_back(pkg.get_source()/"Build");
@@ -136,7 +122,7 @@ void Component::create_targets() const
                for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i)
                {
                        FileTarget *ft;
-                       if(Target *tgt = builder.get_target(i->str()))
+                       if(Target *tgt = builder.get_target_by_path(*i))
                                ft = dynamic_cast<FileTarget *>(tgt);
                        else
                                ft = new File(builder, *i);
@@ -154,7 +140,7 @@ void Component::create_targets() const
                for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i)
                {
                        FileTarget *ft;
-                       if(Target *tgt = builder.get_target(i->str()))
+                       if(Target *tgt = builder.get_target_by_path(*i))
                                ft = dynamic_cast<FileTarget *>(tgt);
                        else
                                ft = new File(builder, pkg, *i);
@@ -164,7 +150,7 @@ void Component::create_targets() const
        else if(type==DATAFILE)
        {
                File *source;
-               if(Target *tgt = builder.get_target(files.front().str()))
+               if(Target *tgt = builder.get_target_by_path(files.front()))
                        source = dynamic_cast<File *>(tgt);
                else
                        source = new File(builder, pkg, files.front());
@@ -184,7 +170,7 @@ void Component::create_targets() const
                        string ext = FS::extpart(FS::basename(*i));
                        if(ext==".h")
                        {
-                               FileTarget *hdr = dynamic_cast<FileTarget *>(builder.get_target(i->str()));
+                               FileTarget *hdr = builder.get_target_by_path(*i);
                                if(!hdr)
                                        hdr = new Header(builder, *this, i->str());
 
@@ -234,27 +220,23 @@ void Component::create_targets() const
        {
                Install *inst = new Install(builder, pkg, **i, inst_loc);
                inst_tgt->add_depend(inst);
-
-               if(type==LIBRARY)
-                       if(SharedLibrary *shlib = dynamic_cast<SharedLibrary *>(*i))
-                               if(!shlib->get_soname().empty())
-                                       inst_tgt->add_depend(new Symlink(builder, pkg, *inst, shlib->get_name()));
        }
 }
 
 PathList Component::collect_source_files() const
 {
        PathList files;
-       for(PathList::const_iterator i=sources.begin(); i!=sources.end(); ++i)
+       for(StringList::const_iterator i=sources.begin(); i!=sources.end(); ++i)
        {
-               if(FS::is_dir(*i))
+               FS::Path path(*i);
+               if(FS::is_dir(path))
                {
-                       list<string> sfiles = list_files(*i);
+                       list<string> sfiles = list_files(path);
                        for(list<string>::iterator j=sfiles.begin(); j!=sfiles.end(); ++j)
-                               files.push_back(*i / *j);
+                               files.push_back(path / *j);
                }
                else
-                       files.push_back(*i);
+                       files.push_back(path);
        }
 
        return files;
@@ -287,7 +269,7 @@ void Component::Loader::finish()
 
 void Component::Loader::source(const string &s)
 {
-       comp.sources.push_back(comp.pkg.get_source()/s);
+       comp.sources.push_back(s);
 }
 
 void Component::Loader::require(const string &n)
@@ -299,24 +281,14 @@ void Component::Loader::require(const string &n)
 
 void Component::Loader::modular()
 {
-       if(comp.type!=PROGRAM)
-               throw Exception("Only programs can be modular");
-       comp.modular = true;
+       IO::print("%s: Note: modular is deprecated\n", get_source());
+       comp.build_info.ldflags.push_back("-rdynamic");
+       comp.build_info.libs.push_back("dl");
 }
 
-void Component::Loader::host(const string &n)
+void Component::Loader::host(const string &)
 {
-       const ComponentList &comps = comp.pkg.get_components();
-       for(ComponentList::const_iterator i=comps.begin(); i!=comps.end(); ++i)
-               if(i->get_name()==n)
-               {
-                       if(i->get_type()!=PROGRAM || !i->is_modular())
-                               throw Exception("Module host must be a modular program");
-                       comp.module_host = &*i;
-                       return;
-               }
-
-       throw KeyError("Unknown component", n);
+       IO::print("%s: Note: host is deprecated\n", get_source());
 }
 
 void Component::Loader::install_headers(const string &p)