]> git.tdb.fi Git - builder.git/blobdiff - source/pkgconfigaction.cpp
Use mspio for all I/O operations
[builder.git] / source / pkgconfigaction.cpp
index b1bebace667a337c22a3372e0473cd6ef3717f52..991bd3516a704abbe10a948a9cdfa1be7f1b493c 100644 (file)
@@ -1,65 +1,61 @@
 /* $Id$
 
 This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-200 Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
-#include <fstream>
-#include <iostream>
-#include <msp/path/utils.h>
+#include <msp/fs/utils.h>
+#include <msp/io/file.h>
+#include <msp/io/print.h>
 #include "package.h"
 #include "pkgconfig.h"
 #include "pkgconfigaction.h"
 
 using namespace std;
+using namespace Msp;
 
 PkgConfigAction::PkgConfigAction(Builder &b, const PkgConfig &p):
        Action(b)
 {
-       const Package &pkg=*p.get_package();
-       
-       announce(pkg.get_name(), "PC", relative(p.get_name(), pkg.get_source()).str());
-       
-       ofstream out(p.get_name().c_str());
-       if(out)
-       {
-               // Prefix is already included in the various paths
-               //out<<"prefix="<<pkg.get_prefix()<<"\n\n";
-               out<<"source="<<pkg.get_source()<<"\n\n";
-               
-               out<<"Name: "<<pkg.get_name()<<'\n';
-               out<<"Description: "<<pkg.get_description()<<'\n';
-               out<<"Version: "<<pkg.get_version()<<'\n';
-               
-               out<<"Requires:";
-               const PkgRefList &reqs=pkg.get_requires();
-               for(PkgRefList::const_iterator i=reqs.begin(); i!=reqs.end(); ++i)
-                       if(i->get_package()->get_use_pkgconfig())
-                               out<<' '<<i->get_name();
-               out<<'\n';
+       const SourcePackage &spkg=*static_cast<const SourcePackage *>(p.get_package());
 
-               const BuildInfo &binfo=pkg.get_exported_binfo();
-               out<<"Libs:";
-               for(StringList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
-                       out<<" -L"<<*i;
-               for(StringList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
-                       out<<" -l"<<*i;
-               for(StringList::const_iterator i=binfo.ldflags.begin(); i!=binfo.ldflags.end(); ++i)
-                       out<<' '<<*i;
-               out<<'\n';
+       announce(spkg.get_name(), "PC", relative(p.get_path(), spkg.get_source()).str());
 
-               out<<"Cflags:";
-               for(StringList::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
-                       out<<" -I"<<*i;
-               for(StringList::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
-                       out<<" -D"<<*i;
-               for(StringList::const_iterator i=binfo.cflags.begin(); i!=binfo.cflags.end(); ++i)
-                       out<<' '<<*i;
-               out<<'\n';
-       }
-       else
-               cerr<<"Can't open "<<p.get_name()<<" for writing\n";
+       IO::BufferedFile out(p.get_path().str(), IO::M_WRITE);
+       // Prefix is already included in the various paths
+       //IO::print(out, "prefix=%s\n", pkg.get_prefix());
+       IO::print(out, "source=%s\n\n", spkg.get_source());
+
+       IO::print(out, "Name: %s\n", spkg.get_name());
+       IO::print(out, "Description: %s\n", spkg.get_description());
+       IO::print(out, "Version: %s\n", spkg.get_version());
+
+       IO::print(out, "Requires:");
+       const PackageList &reqs=spkg.get_requires();
+       for(PackageList::const_iterator i=reqs.begin(); i!=reqs.end(); ++i)
+               if((*i)->get_use_pkgconfig())
+                       IO::print(out, " %s", (*i)->get_name());
+       out.put('\n');
+
+       const BuildInfo &binfo=spkg.get_exported_binfo();
+       IO::print(out, "Libs:");
+       for(StringList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
+               IO::print(out, " -L%s", *i);
+       for(StringList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
+               IO::print(out, " -l%s", *i);
+       for(StringList::const_iterator i=binfo.ldflags.begin(); i!=binfo.ldflags.end(); ++i)
+               IO::print(out, " %s", *i);
+       out.put('\n');
+
+       IO::print(out, "Cflags:");
+       for(StringList::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
+               IO::print(out, " -I%s", *i);
+       for(StringList::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
+               IO::print(out, " -D%s", *i);
+       for(StringList::const_iterator i=binfo.cflags.begin(); i!=binfo.cflags.end(); ++i)
+               IO::print(out, " %s", *i);
+       out.put('\n');
 }
 
 int PkgConfigAction::check()