#!/usr/bin/env bash declare -a PKG_CONFIG_ARRAY PKG_CONFIG_ARRAY=( $(type -a -P pkg-config) ) PKG_CONFIG="${PKG_CONFIG_ARRAY[1]}" for ((i = 1; i <= ${#}; i++)); do case "${!i}" in --variable*) found_var=true break ;; *) ;; esac done # # this sed will sanitize pkg-config's output. it will remove: # # "/usr/lib/pkgconfig/../../.." # "/lib/pkgconfig/../.." # declare -a args args=( \ "-e" "s~/usr/lib/pkgconfig/\.\./\.\./\.\.~~g" \ "-e" "s~/lib/pkgconfig/\.\./\.\.~~g" \ ) if [ -n "${PTXDIST_PKG_CONFIG_VAR_NO_SYSROOT}" -a \ -n "${found_var}" ]; then # # remove sysroot for variables that return a path # 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 "${PKG_CONFIG}" "${@}" | sed "${args[@]}" for _pipe_status in "${PIPESTATUS[@]}"; do if [ ${_pipe_status} -ne 0 ]; then exit ${_pipe_status} fi done