Blame sofort/tools/pkgconf.sh

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