Adopt pkg-config for more reliable library detection.

[IMPROVED]  Using pkg-config we can more reliably find and use installed dependency libraries on the system.
This commit is contained in:
Maarten Billemont 2023-01-14 11:16:21 -05:00
parent 8d6d670197
commit 26c01a5eaa
2 changed files with 13 additions and 6 deletions

2
api

@ -1 +1 @@
Subproject commit 06243e2673ffa4b050c957276d6cb18b0feb981f Subproject commit 1d7c4a7986d35403dadb29d0d7d67a6c092ad42d

13
build
View file

@ -186,13 +186,20 @@ cc() (
### DEPENDENCIES ### DEPENDENCIES
use() { use() {
local option=$1 requisite=$2 lib=$3; shift 3 local option=$1 requisite=$2 lib=$3; shift 3
local enabled=${!option} local enabled=${!option} found=0 _cflags _ldflags
if (( enabled )); then if (( enabled )); then
if haslib "$lib"; then
for lib in "$lib" "$@"; do for lib in "$lib" "$@"; do
haslib "$lib" && ldflags+=( -l"$lib" ) if _cflags=$(pkg-config --cflags "$lib" 2>/dev/null) && _ldflags=$(pkg-config --libs "$lib" 2>/dev/null); then
cflags+=( $_cflags ) ldflags+=( $_ldflags ); found=1
elif _cflags=$(pkg-config --cflags "lib$lib" 2>/dev/null) && _ldflags=$(pkg-config --libs "lib$lib" 2>/dev/null); then
cflags+=( $_cflags ) ldflags+=( $_ldflags ); found=1
elif haslib "$lib"; then
ldflags+=( -l"$lib" ); found=1
fi
done done
if (( found )); then
echo "INFO: Enabled $option (lib$lib)." echo "INFO: Enabled $option (lib$lib)."
return 0 return 0