Blame sofort/tools/pkgconf.sh

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