Blame sofort/tools/pkgconf.sh

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