From 3b13563d75a8fd711a9cf87cae62960f90a5bc39 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 16 Jul 2012 23:46:26 +0300 Subject: [PATCH] Let PackageManager take care of PKG_CONFIG_PATH --- source/builder.cpp | 20 -------------------- source/packagemanager.cpp | 27 ++++++++++++++++++++++++++- source/packagemanager.h | 1 + 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/source/builder.cpp b/source/builder.cpp index 122e1b9..ff2f952 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -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 path = split(pcp, ':'); - bool found = false; - for(vector::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) diff --git a/source/packagemanager.cpp b/source/packagemanager.cpp index 01c9e09..730f022 100644 --- a/source/packagemanager.cpp +++ b/source/packagemanager.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -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 path = split(pcp, ':'); + bool found = false; + for(vector::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") diff --git a/source/packagemanager.h b/source/packagemanager.h index 3484687..4017065 100644 --- a/source/packagemanager.h +++ b/source/packagemanager.h @@ -26,6 +26,7 @@ private: SearchPath pkg_dirs; bool no_externals; PackageMap packages; + bool env_set; public: PackageManager(Builder &); -- 2.45.2