]> git.tdb.fi Git - builder.git/blobdiff - source/component.cpp
Add install component type
[builder.git] / source / component.cpp
index cb81f8420429b78bd79b4d3f70c6021db04e4e81..de42d922404f995a186e80a6e62c5819faa59746 100644 (file)
@@ -89,7 +89,9 @@ void Component::create_targets() const
        Target *def_tgt=builder.get_target("default");
 
        PathList files=collect_source_files();
+       list<FileTarget *> inst_list;
 
+       string inst_loc;
        if(type==TARBALL)
        {
                string tarname=name;
@@ -101,7 +103,7 @@ void Component::create_targets() const
                {
                        const TargetMap &targets=builder.get_targets();
                        for(TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
-                               if(i->second->get_package()==&pkg && !i->second->get_buildable())
+                               if(i->second->get_package()==&pkg && !i->second->is_buildable())
                                        result->add_depend(i->second);
                        files.push_back(pkg.get_source()/"Build");
                }
@@ -121,20 +123,34 @@ void Component::create_targets() const
 
                return;
        }
-
-       list<FileTarget *> inst_list;
-       for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i)
+       else if(type==INSTALL)
        {
-               string ext=FS::extpart(FS::basename(*i));
-               if(ext==".h")
+               inst_loc=name;
+               for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i)
                {
-                       FileTarget *hdr=dynamic_cast<FileTarget *>(builder.get_target(i->str()));
-                       if(!hdr)
-                               hdr=new Header(builder, this, i->str());
+                       FileTarget *ft;
+                       if(Target *tgt=builder.get_target(i->str()))
+                               ft=dynamic_cast<FileTarget *>(tgt);
+                       else
+                               ft=new File(builder, pkg, *i);
+                       inst_list.push_back(ft);
+               }
+       }
+       else
+       {
+               for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i)
+               {
+                       string ext=FS::extpart(FS::basename(*i));
+                       if(ext==".h")
+                       {
+                               FileTarget *hdr=dynamic_cast<FileTarget *>(builder.get_target(i->str()));
+                               if(!hdr)
+                                       hdr=new Header(builder, *this, i->str());
 
-                       // Install headers if requested
-                       if(type==HEADERS && install)
-                               inst_list.push_back(hdr);
+                               // Install headers if requested
+                               if(type==HEADERS && install)
+                                       inst_list.push_back(hdr);
+                       }
                }
        }
 
@@ -146,7 +162,7 @@ void Component::create_targets() const
                        string ext=FS::extpart(FS::basename(*i));
                        if((ext==".cpp" || ext==".cc" || ext==".c"))
                        {
-                               SourceFile *src=new SourceFile(builder, this, i->str());
+                               SourceFile *src=new SourceFile(builder, *this, i->str());
                                ObjectFile *obj=new ObjectFile(builder, *this, *src);
                                objs.push_back(obj);
                        }
@@ -174,7 +190,7 @@ void Component::create_targets() const
 
        Target *inst_tgt=builder.get_target("install");
        for(list<FileTarget *>::const_iterator i=inst_list.begin(); i!=inst_list.end(); ++i)
-               inst_tgt->add_depend(new Install(builder, pkg, **i));
+               inst_tgt->add_depend(new Install(builder, pkg, **i, inst_loc));
 }
 
 PathList Component::collect_source_files() const
@@ -235,7 +251,7 @@ void Component::Loader::require(const string &n)
 void Component::Loader::modular()
 {
        if(comp.type!=PROGRAM)
-               throw Msp::Exception("Only programs can be modular");
+               throw Exception("Only programs can be modular");
        comp.modular=true;
 }
 
@@ -245,13 +261,13 @@ void Component::Loader::host(const string &n)
        for(ComponentList::const_iterator i=comps.begin(); i!=comps.end(); ++i)
                if(i->get_name()==n)
                {
-                       if(i->get_type()!=PROGRAM || !i->get_modular())
-                               throw Msp::Exception("Module host must be a modular program");
+                       if(i->get_type()!=PROGRAM || !i->is_modular())
+                               throw Exception("Module host must be a modular program");
                        comp.module_host=&*i;
                        return;
                }
 
-       throw Msp::Exception("Unknown component");
+       throw KeyError("Unknown component", n);
 }
 
 void Component::Loader::install_headers(const string &p)