Blame sofort/tools/pkgconf.sh

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