2014-09-27 19:45:49 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* OSXCross Compiler Wrapper *
|
|
|
|
* Copyright (C) 2014 by Thomas Poechtrager *
|
|
|
|
* t.poechtrager@gmail.com *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software *
|
|
|
|
* Foundation, Inc., *
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
#include "proginc.h"
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern char **environ;
|
|
|
|
|
|
|
|
namespace program {
|
|
|
|
namespace osxcross {
|
|
|
|
|
2014-09-27 22:42:53 +02:00
|
|
|
struct envvar {
|
|
|
|
std::string name;
|
|
|
|
std::string value;
|
|
|
|
envvar(std::string name, std::string value) : name(name), value(value) {}
|
|
|
|
};
|
|
|
|
|
2014-09-27 19:45:49 +02:00
|
|
|
int pkg_config(int argc, char **argv) {
|
|
|
|
(void)argc;
|
|
|
|
|
2014-09-27 22:42:53 +02:00
|
|
|
std::vector<envvar> envvars;
|
2014-09-27 19:45:49 +02:00
|
|
|
|
|
|
|
// Map OSXCROSS_PKG_* to PKG_*
|
|
|
|
for (char **env = environ; *env; ++env) {
|
|
|
|
char *p = *env;
|
|
|
|
|
|
|
|
if (!strncmp(p, "OSXCROSS_PKG", 12)) {
|
|
|
|
p += 9; // skip OSXCROSS_
|
2014-09-27 22:42:53 +02:00
|
|
|
const char *val = strchr(p, '=') + 1; // find value offset
|
|
|
|
envvars.push_back(envvar(std::string(p, val - p - 1), val));
|
2014-09-27 19:45:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-27 22:42:53 +02:00
|
|
|
for (const envvar &evar : envvars)
|
|
|
|
setenv(evar.name.c_str(), evar.value.c_str(), 1);
|
|
|
|
|
|
|
|
if (!envvars.empty() && execvp("pkg-config", argv))
|
2014-09-27 19:45:49 +02:00
|
|
|
std::cerr << "cannot find or execute pkg-config" << std::endl;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace osxcross
|
|
|
|
} // namespace program
|