Blame sofort/tools/pkgconf.sh

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