Add a helper to lookup libraries

This commit is contained in:
Pierre Pronchery 2017-11-10 03:27:01 +01:00
parent e2b8bc4a3f
commit b3c260c4b9

View File

@ -28,10 +28,25 @@
CONFIGSH="${0%/platform.sh}/config.sh" CONFIGSH="${0%/platform.sh}/config.sh"
PREFIX="/usr/local" PREFIX="/usr/local"
PROGNAME="platform.sh" PROGNAME="platform.sh"
SOEXT=".so"
[ -f "$CONFIGSH" ] && . "$CONFIGSH" [ -f "$CONFIGSH" ] && . "$CONFIGSH"
#functions #functions
#platform_library
_platform_library()
{
library="$1"
libdir=$(_platform_variable "LIBDIR")
if [ -f "/lib/lib$library$SOEXT" \
-o -f "/usr/lib/lib$library$SOEXT" \
-o -f "$libdir/lib$library$SOEXT" ]; then
echo "-l$library"
fi
}
#platform_variable #platform_variable
_platform_variable() _platform_variable()
{ {
@ -74,7 +89,7 @@ _platform_variable()
#usage #usage
_usage() _usage()
{ {
echo "Usage: $PROGNAME -V variable" 1>&2 echo "Usage: $PROGNAME -l library -V variable" 1>&2
return 1 return 1
} }
@ -82,7 +97,7 @@ _usage()
#main #main
type= type=
variable= variable=
while getopts "O:V:" name; do while getopts "l:O:V:" name; do
case "$name" in case "$name" in
O) O)
export "${OPTARG%%=*}"="${OPTARG#*=}" export "${OPTARG%%=*}"="${OPTARG#*=}"
@ -91,6 +106,10 @@ while getopts "O:V:" name; do
type="variable" type="variable"
variable="$OPTARG" variable="$OPTARG"
;; ;;
l)
type="library"
library="$OPTARG"
;;
?) ?)
_usage _usage
exit $? exit $?
@ -104,6 +123,9 @@ if [ $# -ne 0 ]; then
fi fi
case "$type" in case "$type" in
library)
"_platform_$type" "$library"
;;
variable) variable)
"_platform_$type" "$variable" "_platform_$type" "$variable"
;; ;;