Blame sofort/tools/pkgconf.sh

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