#include <set>
-#include <cstdlib>
#include <msp/core/getopt.h>
#include <msp/datafile/parser.h>
#include <msp/fs/dir.h>
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)
+#include <cstdlib>
#include <msp/fs/dir.h>
#include <msp/fs/stat.h>
#include <msp/fs/utils.h>
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()/"..");
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")