]> git.tdb.fi Git - builder.git/blobdiff - source/sourcepackage.cpp
Further changes for library compatibility
[builder.git] / source / sourcepackage.cpp
index 3b107372c78935616ef98da15e2de2085c8ea765..7160013b4267bf19cbebbb7cc521efcb104def67 100644 (file)
@@ -5,6 +5,7 @@ Copyright © 2007-2010  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
+#include <cstdlib>
 #include <msp/io/print.h>
 #include <msp/strings/lexicalcast.h>
 #include <msp/strings/utils.h>
@@ -75,7 +76,51 @@ LibMode SourcePackage::get_library_mode() const
        else if(mode=="none")
                return DYNAMIC;
        else
-               throw Exception("Unknown library mode");
+               throw runtime_error("unknown library mode");
+}
+
+string SourcePackage::expand_string(const string &str) const
+{
+       string result = str;
+       string::size_type dollar = 0;
+       unsigned n = 0;
+       while((dollar = result.find('$'))!=string::npos)
+       {
+               if(n>1000)
+                       throw bad_expansion("nested too deep");
+
+               string::size_type end;
+               string var;
+               if(dollar+1<result.size() && result[dollar+1]=='{')
+               {
+                       end = result.find('}', dollar+2);
+                       if(end==string::npos)
+                               throw bad_expansion("unterminated variable reference");
+                       var = result.substr(dollar+2, end-dollar-2);
+                       ++end;
+               }
+               else
+               {
+                       for(end=dollar+1; (isalnum(result[end]) || result[end]=='_'); ++end) ;
+                       var = result.substr(dollar+1, end-dollar-1);
+               }
+
+               string value;
+               if(config.is_option(var))
+                       value = config.get_option(var).value;
+               else if(var=="arch")
+                       value = builder.get_current_arch().get_name();
+               else if(var=="system")
+                       value = builder.get_current_arch().get_system();
+               else if(const char *ptr = getenv(var.c_str()))
+                       value = ptr;
+
+               result.replace(dollar, end-dollar, value);
+
+               ++n;
+       }
+
+       return result;
 }
 
 void SourcePackage::do_configure(const StringMap &opts, unsigned flag)
@@ -107,14 +152,6 @@ void SourcePackage::do_configure(const StringMap &opts, unsigned flag)
                                        requires.push_back(pkg);
                }
 
-       base_reqs = requires;
-
-       for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i)
-       {
-               const PackageList &reqs = i->get_requires();
-               requires.insert(requires.end(), reqs.begin(), reqs.end());
-       }
-
        for(PackageList::iterator i=requires.begin(); i!=requires.end(); ++i)
        {
                BinaryPackage *bpkg = dynamic_cast<BinaryPackage *>(*i);
@@ -123,6 +160,9 @@ void SourcePackage::do_configure(const StringMap &opts, unsigned flag)
        }
 
        deps_cache.load();
+
+       for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i)
+               i->configure(opts, flag);
 }
 
 void SourcePackage::init_config()
@@ -150,16 +190,6 @@ void SourcePackage::create_build_info()
 {
        build_info.add(builder.get_current_arch().get_build_info());
 
-       for(PackageList::iterator i=base_reqs.begin(); i!=base_reqs.end(); ++i)
-       {
-               const BuildInfo &ebi = (*i)->get_exported_binfo();
-               build_info.add(ebi);
-
-               export_binfo.cflags.insert(export_binfo.cflags.end(), ebi.cflags.begin(), ebi.cflags.end());
-               export_binfo.incpath.insert(export_binfo.incpath.end(), ebi.incpath.begin(), ebi.incpath.end());
-               export_binfo.defines.insert(export_binfo.defines.end(), ebi.defines.begin(), ebi.defines.end());
-       }
-
        // XXX Currently, a package-specific settings will override cmdline.  This might or might not be desirable.
        const StringList &warnings = builder.get_warnings();
        build_info.warnings.insert(build_info.warnings.begin(), warnings.begin(), warnings.end());
@@ -175,7 +205,7 @@ void SourcePackage::create_build_info()
                export_binfo.libpath.push_back((builder.get_prefix()/"lib").str());
 
        string optimize = config.get_option("optimize").value;
-       if(lexical_cast<unsigned>(optimize))
+       if(!optimize.empty() && optimize!="0")
        {
                build_info.cflags.push_back("-O"+optimize);
                build_info.ldflags.push_back("-O"+optimize);
@@ -285,5 +315,5 @@ void SourcePackage::Loader::tar_file(const string &f)
        SourcePackage &spkg = static_cast<SourcePackage &>(pkg);
        for(ComponentList::iterator i=spkg.components.begin(); i!=spkg.components.end(); ++i)
                if(i->get_type()==Component::TARBALL && i->get_name()=="@src")
-                       const_cast<PathList &>(i->get_sources()).push_back(spkg.source/f);
+                       const_cast<StringList &>(i->get_sources()).push_back((spkg.source/f).str());
 }