Blame sofort/tools/pkgconf.sh

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