diff options
author | Michael Olbrich <m.olbrich@pengutronix.de> | 2018-09-03 10:40:49 +0200 |
---|---|---|
committer | Michael Olbrich <m.olbrich@pengutronix.de> | 2018-09-06 08:47:38 +0200 |
commit | 4c6e7fa28b66dee069d10b514d5e1317173da250 (patch) | |
tree | 9a8a85efbcfe36fe8842f5e0ad3e819b73ae3b61 | |
parent | a7d93ba352b42652f275a946bc4473f2f47bf908 (diff) | |
download | ptxdist-4c6e7fa28b66dee069d10b514d5e1317173da250.tar.gz ptxdist-4c6e7fa28b66dee069d10b514d5e1317173da250.tar.xz |
pkg-config: cleanup and improve path and dependency handling
- move all search path magic into the wrapper script
- use the wrapper script for host packages as well
- enforce the dependencies for host packages
- make it possible to overwrite the script in the BSP
- track host and target dependencies separately
Needed e.g. by barebox to build host tools
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rw-r--r-- | rules/cross-pkg-config-wrapper.make | 9 | ||||
-rw-r--r-- | rules/host-pkg-config.make | 16 | ||||
-rw-r--r-- | rules/pre/Rules.make | 8 | ||||
-rw-r--r-- | scripts/lib/ptxd_make_00-init.sh | 46 | ||||
-rw-r--r-- | scripts/lib/ptxd_make_world_common.sh | 21 | ||||
-rw-r--r-- | scripts/lib/ptxd_make_world_install.sh | 13 | ||||
-rwxr-xr-x | scripts/pkg-config-wrapper | 55 |
7 files changed, 84 insertions, 84 deletions
diff --git a/rules/cross-pkg-config-wrapper.make b/rules/cross-pkg-config-wrapper.make index e3ffbd4f8..6745a877e 100644 --- a/rules/cross-pkg-config-wrapper.make +++ b/rules/cross-pkg-config-wrapper.make @@ -18,10 +18,15 @@ CROSS_PKG_CONFIG_WRAPPER_LICENSE := ignore # Install # ---------------------------------------------------------------------------- +CROSS_PKG_CONFIG_WRAPPER_SCRIPT = \ + $(shell ptxd_get_alternative scripts pkg-config-wrapper && echo $$ptxd_reply) + $(STATEDIR)/cross-pkg-config-wrapper.install: @$(call targetinfo) - install -D -m755 $(SCRIPTSDIR)/pkg-config-wrapper $(PTXCONF_SYSROOT_CROSS)/bin/pkg-config - install -D -m755 $(SCRIPTSDIR)/pkg-config-wrapper $(PTXCONF_SYSROOT_CROSS)/bin/$(COMPILER_PREFIX)pkg-config + @ln -sv $(CROSS_PKG_CONFIG_WRAPPER_SCRIPT) \ + $(PTXCONF_SYSROOT_CROSS)/bin/$(COMPILER_PREFIX)pkg-config + @ln -sv $(CROSS_PKG_CONFIG_WRAPPER_SCRIPT) \ + $(PTXCONF_SYSROOT_CROSS)/bin/pkg-config @$(call touch) # vim: syntax=make diff --git a/rules/host-pkg-config.make b/rules/host-pkg-config.make index 45a323fd8..d4f72c11c 100644 --- a/rules/host-pkg-config.make +++ b/rules/host-pkg-config.make @@ -39,4 +39,20 @@ HOST_PKG_CONFIG_CONF_OPT := \ --disable-host-tool \ --with-internal-glib +# ---------------------------------------------------------------------------- +# Install +# ---------------------------------------------------------------------------- + +PKG_CONFIG_SCRIPT = \ + $(shell ptxd_get_alternative scripts pkg-config-wrapper && echo $$ptxd_reply) + +$(STATEDIR)/host-pkg-config.install: + @$(call targetinfo) + @$(call world/install, HOST_PKG_CONFIG) + @mv $(PTXDIST_SYSROOT_HOST)/bin/pkg-config \ + $(PTXDIST_SYSROOT_HOST)/bin/pkg-config.real + @ln -sv $(PKG_CONFIG_SCRIPT) \ + $(PTXDIST_SYSROOT_HOST)/bin/pkg-config + @$(call touch) + # vim: syntax=make diff --git a/rules/pre/Rules.make b/rules/pre/Rules.make index 1e5dad893..a5fd9adc4 100644 --- a/rules/pre/Rules.make +++ b/rules/pre/Rules.make @@ -64,6 +64,7 @@ CROSS_GNATMAKE := $(PTXCONF_COMPILER_PREFIX)gnatmake CROSS_GNATNAME := $(PTXCONF_COMPILER_PREFIX)gnatname CROSS_GNATPREP := $(PTXCONF_COMPILER_PREFIX)gnatprep CROSS_GNATXREF := $(PTXCONF_COMPILER_PREFIX)gnatxref +CROSS_PKG_CONFIG := $(PTXCONF_COMPILER_PREFIX)pkg-config CROSS_ENV_AR := AR=$(CROSS_AR) CROSS_ENV_AS := AS=$(CROSS_AS) @@ -93,6 +94,7 @@ CROSS_ENV_GNATXREF := GNATXREF=$(CROSS_GNATXREF) CROSS_ENV_CC_FOR_BUILD := CC_FOR_BUILD=$(HOSTCC) CROSS_ENV_CPP_FOR_BUILD := CPP_FOR_BUILD="$(HOSTCC) -E" CROSS_ENV_LINK_FOR_BUILD:= LINK_FOR_BUILD=$(HOSTCC) +CROSS_ENV_PKG_CONFIG := PKG_CONFIG=$(CROSS_PKG_CONFIG) @@ -131,7 +133,8 @@ CROSS_ENV_PROGS := \ $(CROSS_ENV_GNATXREF) \ $(CROSS_ENV_CC_FOR_BUILD) \ $(CROSS_ENV_CPP_FOR_BUILD) \ - $(CROSS_ENV_LINK_FOR_BUILD) + $(CROSS_ENV_LINK_FOR_BUILD) \ + $(CROSS_ENV_PKG_CONFIG) CROSS_LIB_DIR := $(shell ptxd_get_lib_dir) @@ -212,7 +215,6 @@ endif # CROSS_ENV := \ $(CROSS_ENV_PROGS) \ - $(CROSS_ENV_PKG_CONFIG) \ $(CROSS_ENV_AC) @@ -302,8 +304,6 @@ HOST_ENV_PROGS := \ $(HOST_ENV_CC) \ $(HOST_ENV_CXX) -HOST_ENV_PKG_CONFIG := $(PTXDIST_HOST_ENV_PKG_CONFIG) - HOST_ENV_PYTHONPATH := \ PYTHONPATH="$(shell python -c 'import distutils.sysconfig as sysconfig; \ print "%s" % sysconfig.get_python_lib(prefix="'"$(PTXDIST_SYSROOT_HOST)"'")')" diff --git a/scripts/lib/ptxd_make_00-init.sh b/scripts/lib/ptxd_make_00-init.sh index 4103d4f39..7e561a4e6 100644 --- a/scripts/lib/ptxd_make_00-init.sh +++ b/scripts/lib/ptxd_make_00-init.sh @@ -191,7 +191,6 @@ export -f ptxd_get_lib_dir # out: # PTXDIST_CROSS_CPPFLAGS CPPFLAGS for cross-compiled packages # PTXDIST_CROSS_LDFLAGS LDFLAGS for cross-compiled packages -# PTXDIST_CROSS_ENV_PKG_CONFIG PKG_CONFIG_* environemnt for cross pkg-config # ptxd_init_cross_env() { @@ -219,32 +218,6 @@ ptxd_init_cross_env() { export \ PTXDIST_CROSS_CPPFLAGS="${cppflags[*]}" \ PTXDIST_CROSS_LDFLAGS="${ldflags[*]}" - - - - ######## PKG_CONFIG_LIBDIR, PKG_CONFIG_PATH ######## - - # - # PKG_CONFIG_LIBDIR contains the default pkg-config search - # directories. Set it to the components of - # PTXDIST_PATH_SYSROOT_PREFIX. - # - - # add <DIR>/lib/pkgconfig and <DIR>/share/pkgconfig - local -a pkg_libdir pkg_lib_system_path pkg_system_incpath - pkg_libdir=( "${prefix[@]/%//${lib_dir}/pkgconfig}" "${prefix[@]/%//share/pkgconfig}" ) - pkg_system_libpath=( "${pkg_libdir[@]/%//../../lib}" "${pkg_libdir[@]/%//../lib}" "/usr/lib" "/lib" ) - pkg_system_incpath=( "${pkg_libdir[@]/%//../../include}" "${pkg_libdir[@]/%//../include}" "/usr/include" "/include" ) - - IFS=":" - local pc_path="PKG_CONFIG_PATH=''" - local pc_libdir="PKG_CONFIG_LIBDIR='${pkg_libdir[*]}'" - local pc_sys_lib_path="PKG_CONFIG_SYSTEM_LIBRARY_PATH='${pkg_system_libpath[*]}'" - local pc_syc_inc_path="PKG_CONFIG_SYSTEM_INCLUDE_PATH='${pkg_system_incpath[*]}'" - IFS="${orig_IFS}" - local pc="PKG_CONFIG='$(ptxd_get_ptxconf PTXCONF_SYSROOT_CROSS)/bin/$(ptxd_get_ptxconf PTXCONF_COMPILER_PREFIX)pkg-config'" - PTXDIST_CROSS_ENV_PKG_CONFIG="${pc_path} ${pc_libdir} ${pc_sys_lib_path} ${pc_syc_inc_path} ${pc}" - export PTXDIST_CROSS_ENV_PKG_CONFIG } # @@ -287,25 +260,6 @@ ptxd_init_host_env() { export \ PTXDIST_HOST_CPPFLAGS="${cppflags[*]}" \ PTXDIST_HOST_LDFLAGS="${ldflags[*]}" - - ######## PKG_CONFIG_LIBDIR, PKG_CONFIG_PATH ######## - - # - # PKG_CONFIG_LIBDIR contains the default pkg-config search - # directories. - # - - # add <DIR>/lib/pkgconfig and <DIR>/share/pkgconfig - local -a pkg_libdir - pkg_libdir=( "${prefix[@]/%//${lib_dir}/pkgconfig}" "${prefix[@]/%//share/pkgconfig}" ) - - IFS=":" - local pc_path="PKG_CONFIG_PATH=''" - local pc_libdir="PKG_CONFIG_LIBDIR='${pkg_libdir[*]}'" - IFS="${orig_IFS}" - local pc="PKG_CONFIG='$(ptxd_get_ptxconf PTXCONF_SYSROOT_HOST)/bin/pkg-config'" - PTXDIST_HOST_ENV_PKG_CONFIG="${pc_path} ${pc_libdir} ${pc}" - export PTXDIST_HOST_ENV_PKG_CONFIG } ptxd_init_devpkg() diff --git a/scripts/lib/ptxd_make_world_common.sh b/scripts/lib/ptxd_make_world_common.sh index f04d2ed05..86e73538f 100644 --- a/scripts/lib/ptxd_make_world_common.sh +++ b/scripts/lib/ptxd_make_world_common.sh @@ -340,12 +340,21 @@ ptxd_make_world_init() { ;; *) ;; esac - local pkgconfig_whitelist - pkgconfig_whitelist="$(echo $( - for dep in ${pkg_build_deps}; do - cat "${ptx_state_dir}/${dep}.pkgconfig" 2>/dev/null; - done))" - pkg_env="PKGCONFIG_WHITELIST='${pkgconfig_whitelist}' PKGCONFIG_WHITELIST_SRC='${pkg_label}' ${pkg_env}" + local -a deps_host deps_target + local whitelist_host whitelist_target + for dep in ${pkg_build_deps}; do + case "${dep}" in + host-*|cross-*) + deps_host[${#deps_host[@]}]="${ptx_state_dir}/${dep}.pkgconfig" + ;; + *) + deps_target[${#deps_target[@]}]="${ptx_state_dir}/${dep}.pkgconfig" + ;; + esac + done + whitelist_host="$(echo $(cat "${deps_host[@]}" /dev/null 2>/dev/null))" + whitelist_target="$(echo $(cat "${deps_target[@]}" /dev/null 2>/dev/null))" + pkg_env="PKGCONFIG_WHITELIST_HOST='${whitelist_host}' PKGCONFIG_WHITELIST_TARGET='${whitelist_target}' PKGCONFIG_WHITELIST_SRC='${pkg_label}' ${pkg_env}" # DESTDIR if [[ "${pkg_conf_tool}" =~ "python" ]]; then diff --git a/scripts/lib/ptxd_make_world_install.sh b/scripts/lib/ptxd_make_world_install.sh index bcc93539c..eaadfadf4 100644 --- a/scripts/lib/ptxd_make_world_install.sh +++ b/scripts/lib/ptxd_make_world_install.sh @@ -221,11 +221,20 @@ ptxd_make_world_install_post() { ptxd_make_world_init && ( if [ -n "${pkg_pkg_dir}" -a -d "${pkg_pkg_dir}" ]; then - find "${pkg_pkg_dir}"/usr/{lib,share}/pkgconfig -name *.pc \ + find "${pkg_pkg_dir}"{,/usr}/{lib,share}/pkgconfig -name *.pc \ -printf "%f\n" 2>/dev/null | sed 's/\.pc$//' fi for dep in ${pkg_build_deps}; do - cat "${ptx_state_dir}/${dep}.pkgconfig" 2>/dev/null; + case "${dep}" in + host-*|cross-*) + if [ "${pkg_type}" = "target" ]; then + continue + fi + ;& + *) + cat "${ptx_state_dir}/${dep}.pkgconfig" 2>/dev/null + ;; + esac done ) | sort -u > "${ptx_state_dir}/${pkg_label}.pkgconfig" # do nothing if pkg_pkg_dir does not exist 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 |