Blame sofort/tools/pkgconf.sh

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