]> git.tdb.fi Git - builder.git/blobdiff - source/package.cpp
Adjust requires to library changes
[builder.git] / source / package.cpp
index 74dcbaa693a09e0e32969659b193bced835a95f2..49866a71d2442f8aff3fd902c12d52c31aa98554 100644 (file)
@@ -21,7 +21,10 @@ Package::Package(Builder &b, const string &n, const Path::Path &s):
        conf_done(false),
        use_pkgconfig(true),
        need_path(false)
-{ }
+{
+       if(builder.get_verbose()>=4)
+               cout<<"Created buildable package "<<n<<" at "<<s<<'\n';
+}
 
 /**
 Sets the path where the package files were installed.  This is only useful for
@@ -89,6 +92,7 @@ void Package::resolve_refs()
                Package *pkg=i->resolve();
                if(pkg) all_reqs.push_back(pkg);
        }
+
        for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i)
        {
                i->resolve_refs();
@@ -97,6 +101,15 @@ void Package::resolve_refs()
                        if(j->get_package())
                                all_reqs.push_back(j->get_package());
        }
+
+       for(ConditionList::iterator i=conditions.begin(); i!=conditions.end(); ++i)
+       {
+               i->resolve_refs();
+               const PkgRefList &creqs=i->get_requires();
+               for(PkgRefList::const_iterator j=creqs.begin(); j!=creqs.end(); ++j)
+                       if(j->get_package())
+                               all_reqs.push_back(j->get_package());
+       }
 }
 
 /**
@@ -120,7 +133,7 @@ void Package::configure(const StringMap &opts, unsigned flag)
                        config.select_profile(prof->second);
                else
                        config.select_last_profile();
-                       
+
                if(flag && config.update(opts))
                {
                        if(builder.get_verbose()>=2)
@@ -131,6 +144,14 @@ void Package::configure(const StringMap &opts, unsigned flag)
 
                config.finish();
 
+               for(ConditionList::iterator i=conditions.begin(); i!=conditions.end(); ++i)
+                       if(i->eval())
+                       {
+                               const PkgRefList &reqs=i->get_requires();
+                               requires.insert(requires.end(), reqs.begin(), reqs.end());
+                               build_info.add(i->get_build_info());
+                       }
+
                for(PackageList::iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i)
                {
                        if((*i)->get_need_path())
@@ -158,13 +179,13 @@ Package *Package::create(Builder &b, const string &name)
        argv.push_back("--libs");
        argv.push_back(name);
        vector<string> info=split(run_command(argv));
-       
+
        bool need_path=false;
        bool use_pkgconfig=true;
        if(info.empty())
        {
                use_pkgconfig=false;
-               
+
                //XXX Put these in an external file
                if(name=="opengl")
                        info.push_back("-lGL");
@@ -176,10 +197,12 @@ Package *Package::create(Builder &b, const string &name)
                        need_path=true;
                else if(name=="devil")
                        info.push_back("-lIL");
+               else if(name=="Xlib")
+                       info.push_back("-lX11");
                else
                        return 0;
        }
-       
+
        Package *pkg=new Package(b, name, info);
        pkg->need_path=need_path;
        pkg->use_pkgconfig=use_pkgconfig;
@@ -206,6 +229,14 @@ Package::Package(Builder &b, const string &n, const vector<string> &info):
                else if(!i->compare(0, 2, "-l"))
                        export_binfo.libs.push_back(i->substr(2));
        }
+
+       if(builder.get_verbose()>=4)
+       {
+               cout<<"Created non-buildable package "<<name<<" with";
+               for(vector<string>::const_iterator i=info.begin(); i!=info.end(); ++i)
+                       cout<<' '<<*i;
+               cout<<'\n';
+       }
 }
 
 /**
@@ -234,9 +265,12 @@ void Package::init_config()
        if(flags&DATA)
                config.add_option("includedir", "$prefix/share",   "Data installation directory");*/
 
-       for(PkgRefList::iterator i=requires.begin(); i!=requires.end(); ++i)
-               if(i->get_package() && i->get_package()->get_need_path())
-                       config.add_option(i->get_name()+"_path", "", "Path for "+i->get_name());
+       for(FeatureList::iterator i=features.begin(); i!=features.end(); ++i)
+               config.add_option("with_"+i->name, "0", i->descr);
+
+       for(PackageList::const_iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i)
+               if((*i)->get_need_path())
+                       config.add_option((*i)->get_name()+"_path", "", "Path for "+(*i)->get_name());
 }
 
 /**
@@ -252,11 +286,14 @@ void Package::create_build_info()
                        Package *pkg=i->get_package();
                        if(!pkg)
                                continue;
-                       build_info.add(pkg->get_exported_binfo());
-                       //XXX We probably really only want to pass cflags and defines through
-                       export_binfo.add(pkg->get_exported_binfo());
+                       const BuildInfo &ebi=pkg->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());
                }
-       
+
                build_info.cflags.push_back("-Wall");
                build_info.cflags.push_back("-Wshadow");
                build_info.cflags.push_back("-Wextra");
@@ -287,6 +324,10 @@ void Package::create_build_info()
                        build_info.defines.push_back("DEBUG");
                }
 
+               for(FeatureList::iterator i=features.begin(); i!=features.end(); ++i)
+                       if(lexical_cast<bool>(config.get_option("with_"+i->name).value))
+                               build_info.cflags.push_back("-DWITH_"+toupper(i->name));
+
                build_info.unique();
 
                for(list<Component>::iterator i=components.begin(); i!=components.end(); ++i)
@@ -314,6 +355,8 @@ Package::Loader::Loader(Package &p):
        add("version",     &Package::version);
        add("description", &Package::description);
        add("require",     &Loader::require);
+       add("feature",     &Loader::feature);
+       add("if",          &Loader::condition);
        add("program",     &Loader::program);
        add("library",     &Loader::library);
        add("module",      &Loader::module);
@@ -326,6 +369,18 @@ void Package::Loader::require(const string &n)
        pkg.requires.push_back(PackageRef(pkg.builder, n));
 }
 
+void Package::Loader::feature(const string &n, const string &d)
+{
+       pkg.features.push_back(Feature(n, d));
+}
+
+void Package::Loader::condition(const string &c)
+{
+       Condition cond(pkg, c);
+       load_sub(cond);
+       pkg.conditions.push_back(cond);
+}
+
 void Package::Loader::program(const string &n)
 {
        Component prog(pkg, Component::PROGRAM, n);