From 83ba2950779acff186879f986e19c37b4848591f Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 5 May 2012 20:24:45 -0500 Subject: [PATCH] pkg: add support for compiling in more than one default pkg-config search path Some packages install to /usr/share/pkgconfig instead of /usr/lib/pkgconfig. --- Makefile | 2 +- pkg.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 753c3e4..54d1ed1 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ SRCS = main.c parse.c pkg.c bsdstubs.c getopt_long.c fragment.c argvsplit.c fil include buildsys.mk -CFLAGS += -DLIBDIR=\"${libdir}\" -DINCLUDEDIR=\"${includedir}\" -DPKG_DEFAULT_PATH=\"${libdir}/pkgconfig\" -Wall -Wextra -Wformat=2 -std=gnu99 -D_FORTIFY_SOURCE=2 +CFLAGS += -DLIBDIR=\"${libdir}\" -DINCLUDEDIR=\"${includedir}\" -DPKG_DEFAULT_PATH=\"${libdir}/pkgconfig:${datadir}/pkgconfig\" -Wall -Wextra -Wformat=2 -std=gnu99 -D_FORTIFY_SOURCE=2 install-extra: mkdir -p $(DESTDIR)/$(datarootdir)/aclocal diff --git a/pkg.c b/pkg.c index 345d263..bc29b7d 100644 --- a/pkg.c +++ b/pkg.c @@ -89,9 +89,20 @@ pkg_find(const char *name, unsigned int flags) if (!(flags & PKGF_ENV_ONLY)) { - snprintf(locbuf, sizeof locbuf, "%s/%s" PKG_CONFIG_EXT, PKG_DEFAULT_PATH, name); - if ((f = fopen(locbuf, "r")) != NULL) - return parse_file(locbuf, f); + count = path_split(PKG_DEFAULT_PATH, &path); + + while (iter < count) + { + snprintf(locbuf, sizeof locbuf, "%s/%s" PKG_CONFIG_EXT, path[iter], name); + free(path[iter]); + + if ((f = fopen(locbuf, "r")) != NULL) + return parse_file(locbuf, f); + + iter++; + } + + free(path); } return NULL;