Blame sofort/tools/pkgconf.sh

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