X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fpackage.cpp;h=74dcbaa693a09e0e32969659b193bced835a95f2;hb=b6dcf65b5e1b99f6c65454358c7610f3e9c8af2b;hp=587ce80da4f3b172ca839cb53be9d6673c7c2fb5;hpb=4f78d9f016482ce1ac7d726852e33e07c090df1b;p=builder.git diff --git a/source/package.cpp b/source/package.cpp index 587ce80..74dcbaa 100644 --- a/source/package.cpp +++ b/source/package.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include "builder.h" #include "misc.h" #include "package.h" @@ -17,7 +17,9 @@ Package::Package(Builder &b, const string &n, const Path::Path &s): name(n), buildable(true), source(s), + config(*this), conf_done(false), + use_pkgconfig(true), need_path(false) { } @@ -30,6 +32,53 @@ void Package::set_path(const Msp::Path::Path &p) path=builder.get_cwd()/p; } +Msp::Path::Path Package::get_temp_dir() const +{ + return source/config.get_option("tempdir").value/config.get_option("profile").value; +} + +Msp::Path::Path Package::get_out_dir() const +{ + return source/config.get_option("outdir").value; +} + +/** +Checks which kinds of things the components of this package install. + +@return A bitmask of installed things +*/ +unsigned Package::get_install_flags() +{ + unsigned flags=0; + for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i) + { + if(i->get_install()) + { + if(i->get_type()==Component::PROGRAM) + flags|=BIN; + else if(i->get_type()==Component::LIBRARY || i->get_type()==Component::MODULE) + flags|=LIB; + } + if(!i->get_install_headers().empty()) + flags|=INCLUDE; + } + + return flags; +} + +LibMode Package::get_library_mode() const +{ + const string &mode=config.get_option("staticlibs").value; + if(mode=="all") + return ALL_STATIC; + else if(mode=="local") + return LOCAL_STATIC; + else if(mode=="none") + return DYNAMIC; + else + throw Exception("Unknown library mode"); +} + /** Tries to resolve all references to dependency packages. */ @@ -54,30 +103,42 @@ void Package::resolve_refs() Processes configuration options that were most likely obtained from the command line. */ -void Package::configure(const RawOptionMap &opts, unsigned flag) +void Package::configure(const StringMap &opts, unsigned flag) { - if(conf_done || !buildable) + if(conf_done) return; - + if(builder.get_verbose()>=3) cout<<"Configuring "<=2) - cout<<"Configuration of "<configure(opts, flag&2); - if((*i)->get_need_path()) - (*i)->set_path(config.get_option((*i)->get_name()+"_path").value); + init_config(); + + StringMap::const_iterator prof=opts.find("profile"); + if(prof!=opts.end() && flag) + config.select_profile(prof->second); + else + config.select_last_profile(); + + if(flag && config.update(opts)) + { + if(builder.get_verbose()>=2) + cout<<"Configuration of "<get_need_path()) + (*i)->set_path(config.get_option((*i)->get_name()+"_path").value); + (*i)->configure(opts, flag&2); + } } - + create_build_info(); conf_done=true; @@ -99,8 +160,11 @@ Package *Package::create(Builder &b, const string &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"); @@ -110,12 +174,15 @@ Package *Package::create(Builder &b, const string &name) info.push_back("-lgmpxx"); else if(name=="fmod4") need_path=true; + else if(name=="devil") + info.push_back("-lIL"); else return 0; } Package *pkg=new Package(b, name, info); pkg->need_path=need_path; + pkg->use_pkgconfig=use_pkgconfig; return pkg; } @@ -124,7 +191,9 @@ Package *Package::create(Builder &b, const string &name) Package::Package(Builder &b, const string &n, const vector &info): builder(b), name(n), - buildable(false) + buildable(false), + config(*this), + conf_done(false) { for(vector::const_iterator i=info.begin(); i!=info.end(); ++i) { @@ -144,17 +213,18 @@ Initializes configuration options and loads cached values. */ void Package::init_config() { - config.add_option("tempdir", "temp", "Directory for storing temporary files"); - config.add_option("optimize", "0", "Apply compiler optimizations"); - config.add_option("debug", "0", "Produce debugging symbols"); - config.add_option("cpu", "auto", "CPU type to optimize for"); - config.add_option("arch", "native", "Architecture for cross-compiling"); - config.add_option("staticlibs", "local", "Use static libraries"); - - const char *home=getenv("HOME"); + config.add_option("profile", "default", "Configuration profile"); + config.add_option("tempdir", "temp", "Directory for storing temporary files"); + config.add_option("outdir", ".", "Directory to put build results in"); + config.add_option("optimize", "0", "Apply compiler optimizations"); + config.add_option("debug", "0", "Produce debugging symbols"); + config.add_option("cpu", "auto", "CPU type to optimize for"); + config.add_option("arch", "native", "Architecture for cross-compiling"); + config.add_option("staticlibs", "local", "Use static libraries"); + unsigned flags=get_install_flags(); if(flags) - config.add_option("prefix", string(home)+"/local"/*"/usr"*/, "Installation prefix"); + config.add_option("prefix", "$HOME/local", "Installation prefix"); /*if(flags&INCLUDE) config.add_option("includedir", "$prefix/include", "Header installation directory"); if(flags&BIN) @@ -167,8 +237,6 @@ void Package::init_config() 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()); - - config.load(source/".options.cache"); } /** @@ -204,15 +272,16 @@ void Package::create_build_info() export_binfo.libpath.push_back((Path::Path(config.get_option("prefix").value)/"lib").str()); string optimize=config.get_option("optimize").value; - if(strtol(optimize)) + if(lexical_cast(optimize)) { build_info.cflags.push_back("-O"+optimize); + build_info.ldflags.push_back("-O"+optimize); string cpu=config.get_option("cpu").value; if(cpu!="auto") build_info.cflags.push_back("-march="+cpu); } - if(strtobool(config.get_option("debug").value)) + if(lexical_cast(config.get_option("debug").value)) { build_info.cflags.push_back("-ggdb"); build_info.defines.push_back("DEBUG"); @@ -239,30 +308,6 @@ void Package::create_build_info() export_binfo.unique(); } -/** -Checks which kinds of things the components of this package install. - -@return A bitmask of installed things -*/ -unsigned Package::get_install_flags() -{ - unsigned flags=0; - for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i) - { - if(i->get_install()) - { - if(i->get_type()==Component::PROGRAM) - flags|=BIN; - else if(i->get_type()==Component::LIBRARY || i->get_type()==Component::MODULE) - flags|=LIB; - } - if(!i->get_install_headers().empty()) - flags|=INCLUDE; - } - - return flags; -} - Package::Loader::Loader(Package &p): pkg(p) { @@ -271,6 +316,7 @@ Package::Loader::Loader(Package &p): add("require", &Loader::require); add("program", &Loader::program); add("library", &Loader::library); + add("module", &Loader::module); add("headers", &Loader::headers); add("build_info", &Loader::build_info); } @@ -294,6 +340,13 @@ void Package::Loader::library(const string &n) pkg.components.push_back(prog); } +void Package::Loader::module(const string &n) +{ + Component prog(pkg, Component::MODULE, n); + load_sub(prog); + pkg.components.push_back(prog); +} + void Package::Loader::headers(const string &n) { Component prog(pkg, Component::HEADERS, n);