Blame sofort/tools/pkgconf.sh

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