Blame sofort/tools/pkgconf.sh

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