X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fpackage.cpp;h=949bd8e7755b6c7b0a0a348624b3b709b612c7c1;hb=7aeaa4ba965f596edad438c02e345a8843f7469a;hp=74dcbaa693a09e0e32969659b193bced835a95f2;hpb=b6dcf65b5e1b99f6c65454358c7610f3e9c8af2b;p=builder.git diff --git a/source/package.cpp b/source/package.cpp index 74dcbaa..949bd8e 100644 --- a/source/package.cpp +++ b/source/package.cpp @@ -1,3 +1,10 @@ +/* $Id$ + +This file is part of builder +Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + #include #include #include "builder.h" @@ -21,7 +28,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 "<resolve(); if(pkg) all_reqs.push_back(pkg); } + for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i) { i->resolve_refs(); @@ -97,6 +108,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 +140,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 +151,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 +186,13 @@ Package *Package::create(Builder &b, const string &name) argv.push_back("--libs"); argv.push_back(name); vector 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 +204,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 +236,14 @@ Package::Package(Builder &b, const string &n, const vector &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 "<::const_iterator i=info.begin(); i!=info.end(); ++i) + cout<<' '<<*i; + cout<<'\n'; + } } /** @@ -234,9 +272,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 +293,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 +331,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(config.get_option("with_"+i->name).value)) + build_info.cflags.push_back("-DWITH_"+toupper(i->name)); + build_info.unique(); for(list::iterator i=components.begin(); i!=components.end(); ++i) @@ -314,6 +362,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 +376,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);