Blame sofort/tools/pkgconf.sh

1b64c0
#!/bin/sh
1b64c0
1b64c0
# pkgconf.sh: generate a pkgconf manifest file.
1b64c0
# this file is covered by COPYING.SOFORT.
1b64c0
1b64c0
set -eu
1b64c0
1b64c0
# prefix, exec_prefix
1b64c0
if [ "$PKGCONF_PREFIX" = "$PKGCONF_EXEC_PREFIX" ]; then
1b64c0
	pkgconf_prefix="${PKGCONF_PREFIX}"
1b64c0
	pkgconf_exec_prefix='${prefix}'
1b64c0
else
1b64c0
	pkgconf_prefix="${PKGCONF_PREFIX}"
1b64c0
	pkgconf_exec_prefix="${PKGCONF_EXEC_PREFIX}"
1b64c0
fi
1b64c0
1b64c0
1b64c0
# (relative) includedir
1b64c0
if [ -z "$PKGCONF_INCLUDEDIR" ]; then
1b64c0
	pkgconf_includedir=
1b64c0
	pkgconf_cflags=
1b64c0
else
1b64c0
	prefix=$(dirname "$PKGCONF_INCLUDEDIR")
1b64c0
	base=$(basename "$PKGCONF_INCLUDEDIR")
1b64c0
1b64c0
	if [ "$prefix" = '/' ]; then
1b64c0
		prefix=
1b64c0
	fi
1b64c0
1b64c0
	if [ "$prefix/$base" = "$PKGCONF_PREFIX/$base" ]; then
1b64c0
		pkgconf_includedir='${prefix}/'"${base}"
1b64c0
		pkgconf_cflags='-I${includedir}'
1b64c0
	else
1b64c0
		pkgconf_includedir="${PKGCONF_INCLUDEDIR}"
1b64c0
		pkgconf_cflags='-I${includedir}'
1b64c0
	fi
1b64c0
fi
1b64c0
1b64c0
1b64c0
# (relative) libdir (blank unless needed)
1b64c0
if [ -z "$PKGCONF_LIBDIR" ]; then
1b64c0
	pkgconf_libdir=
1b64c0
else
1b64c0
	prefix=$(dirname "$PKGCONF_LIBDIR")
1b64c0
	base=$(basename "$PKGCONF_LIBDIR")
1b64c0
1b64c0
	if [ "$prefix" = '/' ]; then
1b64c0
		prefix=
1b64c0
	fi
1b64c0
1b64c0
	if [ "$prefix/$base" = "$PKGCONF_EXEC_PREFIX/$base" ]; then
1b64c0
		pkgconf_libdir='${exec_prefix}/'"${base}"
1b64c0
	else
1b64c0
		pkgconf_libdir='${prefix}/'"${PKGCONF_LIBDIR}"
1b64c0
	fi
1b64c0
fi
1b64c0
1b64c0
1b64c0
# ldflags (--libs)
1b64c0
if [ -n "$pkgconf_libdir" ] &&  [ -n "${PKGCONF_NAME}" ]; then
1b64c0
	pkgconf_ldflags='-L${libdir}'" -l${PKGCONF_NAME}"
1b64c0
elif [ -n "${PKGCONF_NAME}" ]; then
1b64c0
	pkgconf_ldflags="-l${PKGCONF_NAME}"
1b64c0
else
1b64c0
	pkgconf_ldflags='-L${libdir}'
1b64c0
fi
1b64c0
1b64c0
1b64c0
# cflags
1b64c0
if [ -n "$pkgconf_cflags" ] || [ -n "${PKGCONF_DEFS}" ]; then
1b64c0
	pkgconf_cflags="$pkgconf_cflags ${PKGCONF_DEFS}"
1b64c0
	pkgconf_cflags=$(printf '%s' "$pkgconf_cflags" | sed -e 's/^[ \t]*//g')
1b64c0
fi
1b64c0
1b64c0
1b64c0
# repo (optional)
1b64c0
if [ -z "${PKGCONF_REPO}" ]; then
1b64c0
	pkgconf_repo='#'
1b64c0
else
1b64c0
	pkgconf_repo="Repo:        ${PKGCONF_REPO}"
1b64c0
fi
1b64c0
1b64c0
# patches (optional)
1b64c0
if [ -z "${PKGCONF_PSRC}" ]; then
1b64c0
	pkgconf_psrc='#'
1b64c0
else
1b64c0
	pkgconf_psrc="Patches:     ${PKGCONF_PSRC}"
1b64c0
fi
1b64c0
1b64c0
# distro (optional)
1b64c0
if [ -z "${PKGCONF_DURL}" ]; then
1b64c0
	pkgconf_durl='#'
1b64c0
else
1b64c0
	pkgconf_durl="Distro:      ${PKGCONF_DURL}"
1b64c0
fi
1b64c0
1b64c0
# bug reports (optional)
1b64c0
if [ -z "${PKGCONF_BUGS}" ]; then
1b64c0
	pkgconf_bugs='#'
1b64c0
else
1b64c0
	pkgconf_bugs="Bug reports: ${PKGCONF_BUGS}"
1b64c0
fi
1b64c0
1b64c0
# project home page (optional)
1b64c0
if [ -z "${PKGCONF_HOME}" ]; then
1b64c0
	pkgconf_home='#'
1b64c0
else
1b64c0
	pkgconf_home="Home page:   ${PKGCONF_HOME}"
1b64c0
fi
1b64c0
1b64c0
1b64c0
# output (without trailing spaces)
1b64c0
cat << _EOF | grep -v '^#' | sed 's/[ \t]*$//'
1b64c0
###
1b64c0
prefix=$pkgconf_prefix
1b64c0
exec_prefix=$pkgconf_exec_prefix
1b64c0
includedir=$pkgconf_includedir
1b64c0
libdir=$pkgconf_libdir
1b64c0
1b64c0
Name:        ${PKGCONF_NAME}
1b64c0
Description: ${PKGCONF_DESC}
1b64c0
URL:         ${PKGCONF_USRC}
1b64c0
Version:     ${PKGCONF_VERSION}
1b64c0
$pkgconf_repo
1b64c0
$pkgconf_psrc
1b64c0
$pkgconf_durl
1b64c0
$pkgconf_bugs
1b64c0
$pkgconf_home
1b64c0
1b64c0
Cflags:      $pkgconf_cflags
1b64c0
Libs:        $pkgconf_ldflags
1b64c0
###
1b64c0
_EOF
1b64c0
1b64c0
# all done
1b64c0
exit 0