mirror of
https://github.com/tpoechtrager/osxcross.git
synced 2024-08-16 12:00:24 +03:00
Misc pkg-config adjustments (closes #69)
This commit is contained in:
parent
13240f3bd0
commit
e3e3cfb83e
21
README.PKG-CONFIG.md
Normal file
21
README.PKG-CONFIG.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
OSXCross' pkg-config ignores `PKG_CONFIG_*` environment variables by default and maps to `OSXCROSS_PKG_*` to `PKG_*` internally to prevent including wrong header files (`/usr/include`, etc.).
|
||||||
|
|
||||||
|
You can restore the default behavior by setting `OSXCROSS_PKG_CONFIG_USE_NATIVE_VARIABLES` (env) to 1.
|
||||||
|
|
||||||
|
Usage examples:
|
||||||
|
|
||||||
|
$ x86_64-apple-darwin15-pkg-config
|
||||||
|
osxcross: warning: x86_64-apple-darwin15-pkg-config is a no-op - please see README.PKG-CONFIG.md for more
|
||||||
|
## Explanation: No MacPorts packages installed and no OSXCROSS_PKG_* variables set = no-op. ##
|
||||||
|
|
||||||
|
$ x86_64-apple-darwin15-pkg-config --libs sdl2
|
||||||
|
-L[...]/target/bin/../macports/pkgs/opt/local/lib -lSDL2
|
||||||
|
|
||||||
|
$ OSXCROSS_PKG_CONFIG_NO_MP_INC=1 x86_64-apple-darwin15-pkg-config --libs sdl2
|
||||||
|
osxcross: warning: x86_64-apple-darwin15-pkg-config is a no-op - please see README.PKG-CONFIG.md for more
|
||||||
|
|
||||||
|
$ OSXCROSS_PKG_CONFIG_LIBDIR=<path> x86_64-apple-darwin15-pkg-config
|
||||||
|
## Explanation: OSXCROSS_PKG_CONFIG_LIBDIR gets mapped to PKG_CONFIG_LIBDIR internally. ##
|
||||||
|
|
||||||
|
$ OSXCROSS_PKG_CONFIG_USE_NATIVE_VARIABLES=1 PKG_CONFIG_LIBDIR=<path> x86_64-apple-darwin15-pkg-config
|
||||||
|
## Explanation: Restores the default behavior. PKG_CONFIG_LIBDIR is used and OSXCROSS_PKG_* variables will be ignored. ##
|
@ -48,50 +48,68 @@ int pkg_config(int argc, char **argv, Target &target) {
|
|||||||
std::vector<envvar> envvars;
|
std::vector<envvar> envvars;
|
||||||
std::vector<envvar> unset;
|
std::vector<envvar> unset;
|
||||||
envvar evar;
|
envvar evar;
|
||||||
|
bool usenativevariables = getenv("OSXCROSS_PKG_CONFIG_USE_NATIVE_VARIABLES");
|
||||||
|
|
||||||
if (!getenv("OSXCROSS_PKG_CONFIG_NO_MP_INC")) {
|
if (!getenv("OSXCROSS_PKG_CONFIG_NO_MP_INC")) {
|
||||||
std::string MacPortsSysRoot;
|
std::string MacPortsSysRoot;
|
||||||
|
|
||||||
if (target.getMacPortsSysRootDir(MacPortsSysRoot)) {
|
if (target.getMacPortsSysRootDir(MacPortsSysRoot)) {
|
||||||
concatEnvVariable("OSXCROSS_PKG_CONFIG_SYSROOT_DIR", MacPortsSysRoot);
|
concatEnvVariable(usenativevariables ? "PKG_CONFIG_SYSROOT_DIR"
|
||||||
|
: "OSXCROSS_PKG_CONFIG_SYSROOT_DIR",
|
||||||
|
MacPortsSysRoot);
|
||||||
|
|
||||||
std::string MacPortsPkgConfigPath;
|
std::string MacPortsPkgConfigPath;
|
||||||
|
|
||||||
if (target.getMacPortsPkgConfigDir(MacPortsPkgConfigPath))
|
if (target.getMacPortsPkgConfigDir(MacPortsPkgConfigPath))
|
||||||
concatEnvVariable("OSXCROSS_PKG_CONFIG_PATH", MacPortsPkgConfigPath);
|
concatEnvVariable(usenativevariables ? "PKG_CONFIG_PATH"
|
||||||
|
: "OSXCROSS_PKG_CONFIG_PATH",
|
||||||
|
MacPortsPkgConfigPath);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsetenv("OSXCROSS_PKG_CONFIG_NO_MP_INC");
|
unsetenv("OSXCROSS_PKG_CONFIG_NO_MP_INC");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map OSXCROSS_PKG_* to PKG_*.
|
if (!usenativevariables) {
|
||||||
for (char **env = environ; *env; ++env) {
|
// Map OSXCROSS_PKG_* to PKG_*.
|
||||||
char *p = *env;
|
for (char **env = environ; *env; ++env) {
|
||||||
|
char *p = *env;
|
||||||
|
|
||||||
if (!strncmp(p, "OSXCROSS_PKG_CONFIG", 19)) {
|
if (!strncmp(p, "OSXCROSS_PKG_CONFIG", 19)) {
|
||||||
p += 9; // skip OSXCROSS_
|
p += 9; // skip OSXCROSS_
|
||||||
envvars.push_back(var(p, evar));
|
envvars.push_back(var(p, evar));
|
||||||
} else if (!strncmp(p, "PKG_CONFIG", 10)) {
|
} else if (!strncmp(p, "PKG_CONFIG", 10)) {
|
||||||
// Unset native pkg-config vars.
|
// Unset native pkg-config vars.
|
||||||
unset.push_back(var(p, evar, true));
|
unset.push_back(var(p, evar, true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!envvars.empty()) {
|
if (usenativevariables || !envvars.empty()) {
|
||||||
for (const envvar &evar : unset)
|
if (!usenativevariables) {
|
||||||
unsetenv(evar.name.c_str());
|
for (const envvar &evar : unset) {
|
||||||
|
warn << argv[0] << ": ignoring environment variable '" << evar.name
|
||||||
|
<< "' - please see README.PKG-CONFIG.md for more" << warn.endl();
|
||||||
|
|
||||||
for (const envvar &evar : envvars)
|
unsetenv(evar.name.c_str());
|
||||||
setenv(evar.name.c_str(), evar.value.c_str(), 1);
|
}
|
||||||
|
|
||||||
|
for (const envvar &evar : envvars)
|
||||||
|
setenv(evar.name.c_str(), evar.value.c_str(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
// Prevent pkg-config from looking for *.pc files
|
// Prevent pkg-config from looking for *.pc files
|
||||||
// in pre-defined search paths, such as /usr.
|
// in pre-defined search paths, such as /usr.
|
||||||
if (!getenv("PKG_CONFIG_LIBDIR"))
|
if (!getenv("PKG_CONFIG_LIBDIR"))
|
||||||
setenv("PKG_CONFIG_LIBDIR", "", 1);
|
setenv("PKG_CONFIG_LIBDIR", "", 1);
|
||||||
|
|
||||||
if (execvp("pkg-config", argv))
|
execvp("pkg-config", argv);
|
||||||
err << "cannot find or execute pkg-config" << err.endl();
|
err << "cannot find or execute pkg-config" << err.endl();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
warn << argv[0] << " is a no-op - please see README.PKG-CONFIG.md for more"
|
||||||
|
<< warn.endl();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user