Blame sofort/tools/pkgconf.sh

43d630
#!/bin/sh
43d630
dd8932
set -eu
dd8932
43d630
# prefix, exec_prefix
43d630
if [ "$PKGCONF_PREFIX" = "$PKGCONF_EXEC_PREFIX" ]; then
dc5a50
	pkgconf_prefix="${PKGCONF_PREFIX}"
dc5a50
	pkgconf_exec_prefix='${prefix}'
43d630
else
dc5a50
	pkgconf_prefix="${PKGCONF_PREFIX}"
dc5a50
	pkgconf_exec_prefix="${PKGCONF_EXEC_PREFIX}"
43d630
fi
43d630
43d630
43d630
# (relative) includedir
dc5a50
if [ -z "$PKGCONF_INCLUDEDIR" ]; then
dc5a50
	pkgconf_includedir=
dc5a50
	pkgconf_cflags=
43d630
else
dc5a50
	prefix=$(dirname "$PKGCONF_INCLUDEDIR")
dc5a50
	base=$(basename "$PKGCONF_INCLUDEDIR")
dc5a50
181a86
	if [ "$prefix" = '/' ]; then
181a86
		prefix=
181a86
	fi
181a86
dc5a50
	if [ "$prefix/$base" = "$PKGCONF_PREFIX/$base" ]; then
dc5a50
		pkgconf_includedir='${prefix}/'"${base}"
dc5a50
		pkgconf_cflags='-I${includedir}'
dc5a50
	else
dc5a50
		pkgconf_includedir="${PKGCONF_INCLUDEDIR}"
dc5a50
		pkgconf_cflags='-I${includedir}'
dc5a50
	fi
43d630
fi
43d630
43d630
dc5a50
# (relative) libdir (blank unless needed)
dc5a50
if [ -z "$PKGCONF_LIBDIR" ]; then
dc5a50
	pkgconf_libdir=
43d630
else
dc5a50
	prefix=$(dirname "$PKGCONF_LIBDIR")
dc5a50
	base=$(basename "$PKGCONF_LIBDIR")
dc5a50
181a86
	if [ "$prefix" = '/' ]; then
181a86
		prefix=
181a86
	fi
181a86
dc5a50
	if [ "$prefix/$base" = "$PKGCONF_EXEC_PREFIX/$base" ]; then
dc5a50
		pkgconf_libdir='${exec_prefix}/'"${base}"
dc5a50
	else
dc5a50
		pkgconf_libdir='${prefix}/'"${PKGCONF_LIBDIR}"
dc5a50
	fi
43d630
fi
43d630
dc5a50
dc5a50
# ldflags (--libs)
dc5a50
if [ -n "$pkgconf_libdir" ] &&  [ -n "${PKGCONF_NAME}" ]; then
9d1795
	pkgconf_ldflags='-L${libdir}'" -l${PKGCONF_NAME}"
dc5a50
elif [ -n "${PKGCONF_NAME}" ]; then
dc5a50
	pkgconf_ldflags="-l${PKGCONF_NAME}"
43d630
else
9d1795
	pkgconf_ldflags='-L${libdir}'
43d630
fi
43d630
43d630
dc5a50
# cflags
dc5a50
if [ -n "$pkgconf_cflags" ] || [ -n "${PKGCONF_DEFS}" ]; then
829d49
	pkgconf_cflags="$pkgconf_cflags ${PKGCONF_DEFS}"
dc5a50
	pkgconf_cflags=$(printf '%s' "$pkgconf_cflags" | sed -e 's/^[ \t]*//g')
dc5a50
fi
43d630
43d630
43d630
# repo (optional)
dc5a50
if [ -z "${PKGCONF_REPO}" ]; then
dc5a50
	pkgconf_repo='#'
dc5a50
else
dc5a50
	pkgconf_repo="Repo:        ${PKGCONF_REPO}"
43d630
fi
43d630
43d630
# patches (optional)
dc5a50
if [ -z "${PKGCONF_PSRC}" ]; then
dc5a50
	pkgconf_psrc='#'
dc5a50
else
dc5a50
	pkgconf_psrc="Patches:     ${PKGCONF_PSRC}"
43d630
fi
43d630
dc5a50
# distro (optional)
dc5a50
if [ -z "${PKGCONF_DURL}" ]; then
dc5a50
	pkgconf_durl='#'
43d630
else
dc5a50
	pkgconf_durl="Distro:      ${PKGCONF_DURL}"
43d630
fi
43d630
43d630
dc5a50
# output (without trailing spaces)
dc5a50
cat << _EOF | grep -v '^#' | sed 's/[ \t]*$//'
dc5a50
###
dc5a50
prefix=$pkgconf_prefix
dc5a50
exec_prefix=$pkgconf_exec_prefix
dc5a50
includedir=$pkgconf_includedir
dc5a50
libdir=$pkgconf_libdir
dc5a50
dc5a50
Name:        ${PKGCONF_NAME}
dc5a50
Description: ${PKGCONF_DESC}
dc5a50
URL:         ${PKGCONF_USRC}
dc5a50
Version:     ${PKGCONF_VERSION}
dc5a50
$pkgconf_repo
dc5a50
$pkgconf_psrc
dc5a50
$pkgconf_durl
dc5a50
dc5a50
Cflags:      $pkgconf_cflags
dc5a50
Libs:        $pkgconf_ldflags
dc5a50
###
dc5a50
_EOF
dc5a50
dc5a50
# all done
dc5a50
exit 0