Blame sofort/tools/pkgconf.sh

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