--- /dev/null
+#include <algorithm>
+#include "builder.h"
+#include "file.h"
+#include "sourcepackage.h"
+#include "tarballcomponent.h"
+#include "tool.h"
+
+using namespace std;
+
+TarballComponent::TarballComponent(SourcePackage &p, const string &n):
+ Component(p, n)
+{ }
+
+void TarballComponent::create_targets() const
+{
+ Builder &builder = package.get_builder();
+
+ list<Target *> files;
+ SourceList source_filenames = collect_source_files();
+ for(SourceList::const_iterator i=source_filenames.begin(); i!=source_filenames.end(); ++i)
+ {
+ FileTarget *file = builder.get_vfs().get_target(*i);
+ if(!file)
+ file = new File(builder, package, *i);
+ files.push_back(file);
+ }
+
+ BuildGraph &build_graph = builder.get_build_graph();
+
+ string tarname = name;
+ if(name=="@src")
+ {
+ tarname = package.get_name()+"-"+package.get_version();
+ files.insert(files.begin(), &package.get_build_file());
+
+ const BuildGraph::TargetMap &targets = build_graph.get_targets();
+ for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
+ if(i->second->get_package()==&package && !i->second->is_buildable())
+ if(find(files.begin(), files.end(), i->second)==files.end())
+ files.push_back(i->second);
+ }
+
+ const Toolchain &toolchain = builder.get_toolchain();
+ Target *result = toolchain.get_tool("TAR").create_target(files, tarname);
+ build_graph.get_target("tarballs")->add_dependency(*result);
+}