Blame sofort/tools/pkgconf.sh

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