Blame sofort/tools/pkgconf.sh

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