]> git.tdb.fi Git - builder.git/commitdiff
Let PackageManager take care of PKG_CONFIG_PATH
authorMikko Rasa <tdb@tdb.fi>
Mon, 16 Jul 2012 20:46:26 +0000 (23:46 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 16 Jul 2012 23:30:03 +0000 (02:30 +0300)
source/builder.cpp
source/packagemanager.cpp
source/packagemanager.h

index 122e1b901e011d6abafd8ea86789b86e66bb628e..ff2f95257b22b98404b2061bb5aab01b7b6aadff 100644 (file)
@@ -1,5 +1,4 @@
 #include <set>
-#include <cstdlib>
 #include <msp/core/getopt.h>
 #include <msp/datafile/parser.h>
 #include <msp/fs/dir.h>
@@ -230,25 +229,6 @@ Builder::~Builder()
 
 int Builder::main()
 {
-       if(prefix.str()!="/usr")
-       {
-               FS::Path pcdir = prefix/"lib"/"pkgconfig";
-               if(const char *pcp = getenv("PKG_CONFIG_PATH"))
-               {
-                       vector<string> path = split(pcp, ':');
-                       bool found = false;
-                       for(vector<string>::const_iterator i=path.begin(); (!found && i!=path.end()); ++i)
-                               found = (*i==pcdir.str());
-                       if(!found)
-                       {
-                               path.push_back(pcdir.str());
-                               setenv("PKG_CONFIG_PATH", join(path.begin(), path.end(), ":").c_str(), true);
-                       }
-               }
-               else
-                       setenv("PKG_CONFIG_PATH", pcdir.str().c_str(), true);
-       }
-
        if(load_build_file(cwd/build_file))
        {
                if(help)
index 01c9e09c1959de54b6408fcd71e46cbce173c7fa..730f02271e32a5261c95829b89b51604c1296bef 100644 (file)
@@ -1,3 +1,4 @@
+#include <cstdlib>
 #include <msp/fs/dir.h>
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
@@ -17,7 +18,8 @@ using namespace Msp;
 
 PackageManager::PackageManager(Builder &b):
        builder(b),
-       no_externals(false)
+       no_externals(false),
+       env_set(false)
 {
        pkg_path.push_back(builder.get_cwd()/".");
        pkg_path.push_back(builder.get_cwd()/"..");
@@ -87,6 +89,29 @@ Package *PackageManager::find_package(const string &name)
 
 string PackageManager::run_pkgconfig(const string &pkg, const string &what)
 {
+       if(!env_set)
+       {
+               const FS::Path &prefix = builder.get_prefix();
+               if(prefix.str()!="/usr")
+               {
+                       FS::Path pcdir = prefix/"lib/pkgconfig";
+                       if(const char *pcp = getenv("PKG_CONFIG_PATH"))
+                       {
+                               vector<string> path = split(pcp, ':');
+                               bool found = false;
+                               for(vector<string>::const_iterator i=path.begin(); (!found && i!=path.end()); ++i)
+                                       found = (*i==pcdir.str());
+                               if(!found)
+                               {
+                                       path.push_back(pcdir.str());
+                                       setenv("PKG_CONFIG_PATH", join(path.begin(), path.end(), ":").c_str(), true);
+                               }
+                       }
+                       else
+                               setenv("PKG_CONFIG_PATH", pcdir.str().c_str(), true);
+               }
+       }
+
        ExternalTask::Arguments argv;
        argv.push_back("pkg-config");
        if(what=="cflags" || what=="libs")
index 3484687e6191bf6a3c93bc72221f2ccac9b4c113..4017065d83299de2d0c880f5d6a61b8139343f6a 100644 (file)
@@ -26,6 +26,7 @@ private:
        SearchPath pkg_dirs;
        bool no_externals;
        PackageMap packages;
+       bool env_set;
 
 public:
        PackageManager(Builder &);