Blame sofort/tools/pkgconf.sh

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