Blame sofort/tools/pkgconf.sh

6153b3
#!/bin/sh
6153b3
b9b0a7
set -eu
b9b0a7
6153b3
# prefix, exec_prefix
6153b3
if [ "$PKGCONF_PREFIX" = "$PKGCONF_EXEC_PREFIX" ]; then
d72a00
	pkgconf_prefix="${PKGCONF_PREFIX}"
d72a00
	pkgconf_exec_prefix='${prefix}'
6153b3
else
d72a00
	pkgconf_prefix="${PKGCONF_PREFIX}"
d72a00
	pkgconf_exec_prefix="${PKGCONF_EXEC_PREFIX}"
6153b3
fi
6153b3
6153b3
6153b3
# (relative) includedir
d72a00
if [ -z "$PKGCONF_INCLUDEDIR" ]; then
d72a00
	pkgconf_includedir=
d72a00
	pkgconf_cflags=
6153b3
else
d72a00
	prefix=$(dirname "$PKGCONF_INCLUDEDIR")
d72a00
	base=$(basename "$PKGCONF_INCLUDEDIR")
d72a00
d72a00
	if [ "$prefix/$base" = "$PKGCONF_PREFIX/$base" ]; then
d72a00
		pkgconf_includedir='${prefix}/'"${base}"
d72a00
		pkgconf_cflags='-I${includedir}'
d72a00
	else
d72a00
		pkgconf_includedir="${PKGCONF_INCLUDEDIR}"
d72a00
		pkgconf_cflags='-I${includedir}'
d72a00
	fi
6153b3
fi
6153b3
6153b3
d72a00
# (relative) libdir (blank unless needed)
d72a00
if [ -z "$PKGCONF_LIBDIR" ]; then
d72a00
	pkgconf_libdir=
6153b3
else
d72a00
	prefix=$(dirname "$PKGCONF_LIBDIR")
d72a00
	base=$(basename "$PKGCONF_LIBDIR")
d72a00
d72a00
	if [ "$prefix/$base" = "$PKGCONF_EXEC_PREFIX/$base" ]; then
d72a00
		pkgconf_libdir='${exec_prefix}/'"${base}"
d72a00
	else
d72a00
		pkgconf_libdir='${prefix}/'"${PKGCONF_LIBDIR}"
d72a00
	fi
6153b3
fi
6153b3
d72a00
d72a00
# ldflags (--libs)
d72a00
if [ -n "$pkgconf_libdir" ] &&  [ -n "${PKGCONF_NAME}" ]; then
d72a00
	pkgconf_ldflags="$pkgconf_libdir -l${PKGCONF_NAME}"
d72a00
elif [ -n "${PKGCONF_NAME}" ]; then
d72a00
	pkgconf_ldflags="-l${PKGCONF_NAME}"
6153b3
else
d72a00
	pkgconf_ldflags="$pkgconf_libdir"
6153b3
fi
6153b3
6153b3
d72a00
# cflags
d72a00
if [ -n "$pkgconf_cflags" ] || [ -n "${PKGCONF_DEFS}" ]; then
e8a663
	pkgconf_cflags="$pkgconf_cflags ${PKGCONF_DEFS}"
d72a00
	pkgconf_cflags=$(printf '%s' "$pkgconf_cflags" | sed -e 's/^[ \t]*//g')
d72a00
fi
6153b3
6153b3
6153b3
# repo (optional)
d72a00
if [ -z "${PKGCONF_REPO}" ]; then
d72a00
	pkgconf_repo='#'
d72a00
else
d72a00
	pkgconf_repo="Repo:        ${PKGCONF_REPO}"
6153b3
fi
6153b3
6153b3
# patches (optional)
d72a00
if [ -z "${PKGCONF_PSRC}" ]; then
d72a00
	pkgconf_psrc='#'
d72a00
else
d72a00
	pkgconf_psrc="Patches:     ${PKGCONF_PSRC}"
6153b3
fi
6153b3
d72a00
# distro (optional)
d72a00
if [ -z "${PKGCONF_DURL}" ]; then
d72a00
	pkgconf_durl='#'
6153b3
else
d72a00
	pkgconf_durl="Distro:      ${PKGCONF_DURL}"
6153b3
fi
6153b3
6153b3
d72a00
# output (without trailing spaces)
d72a00
cat << _EOF | grep -v '^#' | sed 's/[ \t]*$//'
d72a00
###
d72a00
prefix=$pkgconf_prefix
d72a00
exec_prefix=$pkgconf_exec_prefix
d72a00
includedir=$pkgconf_includedir
d72a00
libdir=$pkgconf_libdir
d72a00
d72a00
Name:        ${PKGCONF_NAME}
d72a00
Description: ${PKGCONF_DESC}
d72a00
URL:         ${PKGCONF_USRC}
d72a00
Version:     ${PKGCONF_VERSION}
d72a00
$pkgconf_repo
d72a00
$pkgconf_psrc
d72a00
$pkgconf_durl
d72a00
d72a00
Cflags:      $pkgconf_cflags
d72a00
Libs:        $pkgconf_ldflags
d72a00
###
d72a00
_EOF
d72a00
d72a00
# all done
d72a00
exit 0