diff options
Diffstat (limited to 'scripts/pkg-config-wrapper')
-rwxr-xr-x | scripts/pkg-config-wrapper | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/scripts/pkg-config-wrapper b/scripts/pkg-config-wrapper index 80656ddd4..11e586a20 100755 --- a/scripts/pkg-config-wrapper +++ b/scripts/pkg-config-wrapper @@ -1,8 +1,33 @@ #!/usr/bin/env bash -declare -a PKG_CONFIG_ARRAY -PKG_CONFIG_ARRAY=( $(type -a -P pkg-config) ) -PKG_CONFIG="${PKG_CONFIG_ARRAY[1]}" +basedir="$(basename "$(dirname "$(dirname "$0")")")" + +declare -a prefix +if [ "${basedir}" = "sysroot-cross" ]; then + prefix="$(dirname "$(dirname "$(dirname "$0")")")/sysroot-target/usr" + whitelist="${PKGCONFIG_WHITELIST_TARGET}" +elif [ "${basedir}" = "sysroot-host" ]; then + prefix="$(dirname "$(dirname "$0")")" + whitelist="${PKGCONFIG_WHITELIST_HOST}" +else + echo "$(basename ${0}): failed to determine prefix" >&2 + exit 1 +fi + +declare -a libdir system_path system_incpath +libdir=( "${prefix/%//lib/pkgconfig}" "${prefix/%//share/pkgconfig}" ) +system_libpath=( "${libdir[@]/%//../../lib}" "${libdir[@]/%//../lib}" "/usr/lib" "/lib" ) +system_incpath=( "${libdir[@]/%//../../include}" "${libdir[@]/%//../include}" "/usr/include" "/include" ) + +orig_IFS="${IFS}" +IFS=":" +# default pkg-config searchs +export PKG_CONFIG_LIBDIR="${libdir[*]}" +# default search path that will be dropped from --cflags +export PKG_CONFIG_SYSTEM_LIBRARY_PATH="${system_libpath[*]}" +# default search path that will be dropped from --libs +export PKG_CONFIG_SYSTEM_INCLUDE_PATH="${system_incpath[*]}" +IFS="${orig_IFS}" for ((i = 1; i <= ${#}; i++)); do case "${!i}" in @@ -34,24 +59,6 @@ if [ -n "${PTXDIST_PKG_CONFIG_VAR_NO_SYSROOT}" -a \ # args[${#args[@]}]="-e" args[${#args[@]}]="s~^${SYSROOT}/~/~" -else - declare -a sysroot_prefix - # - # this shell/sed magic removes "-I$SYSROOT/include" from - # pkg-config's output - # - - # - # transform from PATH to array: /foo:/bar -> /foo /bar - # - sysroot_prefix=( ${PTXDIST_PATH_SYSROOT_PREFIX//:/ } ) - - # - # make sed expression: -e s~-I/foo/include\(\s\|$\)~~ - # remove whitespace - # - sysroot_prefix=( ${sysroot_prefix[@]/%//include\\(\\s\\|$\\)~~} ) - args=( ${args[@]} ${sysroot_prefix[@]/#/-e s~-I} -e "s~\s\+~ ~g" -e "s~^\s\+$~~") fi check_pipe_status() { @@ -63,13 +70,13 @@ check_pipe_status() { } if [ -n "${PKGCONFIG_WHITELIST_SRC}" ]; then - pkgs="$("${PKG_CONFIG}" --print-provides "${@}" 2>/dev/null | awk '{print $1}' && check_pipe_status)" && + pkgs="$(pkg-config.real --print-provides "${@}" 2>/dev/null | awk '{print $1}' && check_pipe_status)" && for pkg in ${pkgs}; do - if [[ ! " ${PKGCONFIG_WHITELIST} " =~ " ${pkg} " && ! "${pkg}" =~ '-uninstalled' ]]; then + if [[ ! " ${whitelist} " =~ " ${pkg} " && ! "${pkg}" =~ '-uninstalled' ]]; then echo "$(basename ${0}): warning: blocking '${pkg}': not selected by '${PKGCONFIG_WHITELIST_SRC}'" >&2 exit 1 fi done fi -"${PKG_CONFIG}" "${@}" | sed "${args[@]}" +pkg-config.real "${@}" | sed "${args[@]}" check_pipe_status |