]> git.tdb.fi Git - builder.git/blobdiff - source/component.cpp
Properly handle default and install options for datafiles
[builder.git] / source / component.cpp
index cb81f8420429b78bd79b4d3f70c6021db04e4e81..e96ac220cf48ed2d2525a4d6f1a21183503394c6 100644 (file)
@@ -13,6 +13,7 @@ Distributed under the LGPL
 #include <msp/strings/lexicalcast.h>
 #include "builder.h"
 #include "component.h"
+#include "datafile.h"
 #include "executable.h"
 #include "file.h"
 #include "header.h"
@@ -89,7 +90,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 +104,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 +124,50 @@ void Component::create_targets() const
 
                return;
        }
+       else if(type==INSTALL)
+       {
+               inst_loc=name;
+               for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i)
+               {
+                       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 if(type==DATAFILE)
+       {
+               File *source;
+               if(Target *tgt=builder.get_target(files.front().str()))
+                       source=dynamic_cast<File *>(tgt);
+               else
+                       source=new File(builder, pkg, files.front());
+               ::DataFile *result=new ::DataFile(builder, *this, *source);
 
-       list<FileTarget *> inst_list;
-       for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i)
+               if(&pkg==builder.get_main_package() && deflt)
+                       def_tgt->add_depend(result);
+               else
+                       world->add_depend(result);
+               if(install)
+                       inst_list.push_back(result);
+       }
+       else
        {
-               string ext=FS::extpart(FS::basename(*i));
-               if(ext==".h")
+               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());
+                       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 +179,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 +207,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 +268,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 +278,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)