Blame sofort/tools/pkgconf.sh

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