]> git.tdb.fi Git - builder.git/blobdiff - source/package.cpp
Package configuration is cached
[builder.git] / source / package.cpp
index fcbe9f7a6208fe8c10f3bac150f78d5c6986138c..cb1940341722608c25e80f1e19794ba741e6ce66 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/strconv.h>
 #include <msp/strutils.h>
 #include "builder.h"
 #include "misc.h"
@@ -79,6 +80,18 @@ void Package::create_build_info()
        if(flags&LIB)
                export_binfo.libpath.push_back((Path::Path(config.get_option("prefix").value)/"lib").str());
 
+       string optimize=config.get_option("optimize").value;
+       if(strtol(optimize))
+       {
+               build_info.cflags.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))
+               build_info.cflags.push_back("-ggdb");
+
        build_info.unique();
        export_binfo.unique();
 
@@ -94,20 +107,29 @@ void Package::create_build_info()
 
 void Package::process_options(const RawOptionMap &opts)
 {
-       config.process(opts);
+       if(config.process(opts))
+               config.save(source/".options.cache");
 }
 
 Package *Package::create(Builder &b, const string &name)
 {
        list<string> argv;
        argv.push_back("pkg-config");
+       argv.push_back("--silence-errors");
        argv.push_back("--cflags");
        argv.push_back("--libs");
        argv.push_back(name);
        vector<string> info=split(run_command(argv));
        
        if(info.empty())
-               return 0;
+       {
+               if(name=="opengl")
+                       info.push_back("-lGL");
+               else if(name=="pthread")
+                       info.push_back("-lpthread");
+               else
+                       return 0;
+       }
        
        Package *pkg=new Package(b, name, info);
        return pkg;
@@ -117,9 +139,11 @@ void Package::init_buildable()
 {
        buildable=true;
 
-       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("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");
 
        const char *home=getenv("HOME");
        unsigned flags=get_install_flags();
@@ -133,6 +157,8 @@ void Package::init_buildable()
                config.add_option("includedir", "$prefix/lib",     "Library installation directory");
        if(flags&DATA)
                config.add_option("includedir", "$prefix/share",   "Data installation directory");*/
+
+       config.load(source/".options.cache");
 }
 
 unsigned Package::get_install_flags()
@@ -162,6 +188,7 @@ Package::Loader::Loader(Package &p):
        add("require",     &Loader::require);
        add("program",     &Loader::program);
        add("library",     &Loader::library);
+       add("headers",     &Loader::headers);
 }
 
 Package::Loader::~Loader()
@@ -174,16 +201,23 @@ void Package::Loader::require(const string &n)
        pkg.requires.push_back(PackageRef(pkg.builder, n));
 }
 
-void Package::Loader::program(const std::string &n)
+void Package::Loader::program(const string &n)
 {
        Component prog(pkg, Component::PROGRAM, n);
        load_sub(prog);
        pkg.components.push_back(prog);
 }
 
-void Package::Loader::library(const std::string &n)
+void Package::Loader::library(const string &n)
 {
        Component prog(pkg, Component::LIBRARY, n);
        load_sub(prog);
        pkg.components.push_back(prog);
 }
+
+void Package::Loader::headers(const string &n)
+{
+       Component prog(pkg, Component::HEADERS, n);
+       load_sub(prog);
+       pkg.components.push_back(prog);
+}