The branch main has been updated by khorben:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=c146f5ae308ee47f2832fb3df1e14f864be70015

commit c146f5ae308ee47f2832fb3df1e14f864be70015
Author:     Pierre Pronchery <[email protected]>
AuthorDate: 2026-05-26 13:48:49 +0000
Commit:     Pierre Pronchery <[email protected]>
CommitDate: 2026-07-02 00:57:45 +0000

    pkgconf: determine the default paths dynamically
    
    This automatically computes the correct PKG_CONFIG_PATH with LOCALBASE
    from the environment (when set) or from the "user.localbase" sysctl, in
    this order.
    
    Reviewed by:    des
    Approved by:    des
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D57246
---
 contrib/pkgconf/libpkgconf/personality.c | 61 ++++++++++++++++++++++++++++++++
 lib/libpkgconf/Makefile                  |  2 --
 2 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/contrib/pkgconf/libpkgconf/personality.c 
b/contrib/pkgconf/libpkgconf/personality.c
index 191c222fe3b7..076337695893 100644
--- a/contrib/pkgconf/libpkgconf/personality.c
+++ b/contrib/pkgconf/libpkgconf/personality.c
@@ -19,6 +19,12 @@
 #include <libpkgconf/stdinc.h>
 #include <libpkgconf/libpkgconf.h>
 
+#ifdef __FreeBSD__
+# include <sys/param.h>
+# include <sys/sysctl.h>
+# include <err.h>
+#endif
+
 /*
  * !doc
  *
@@ -89,6 +95,34 @@ build_default_search_path(pkgconf_list_t* dirlist)
                free(paths);
                paths = NULL;
        }
+#elif defined(__FreeBSD__)
+       pkgconf_buffer_t path1 = PKGCONF_BUFFER_INITIALIZER;
+       pkgconf_buffer_t path2 = PKGCONF_BUFFER_INITIALIZER;
+       char const *localbase;
+       char buf[MAXPATHLEN];
+       size_t len;
+
+       localbase = getenv("LOCALBASE");
+
+       if (localbase == NULL) {
+               len = sizeof(buf);
+               if (sysctlbyname("user.localbase", &buf, &len, NULL, 0) < 0)
+                       err(1, "sysctl(user.localbase)");
+
+               localbase = buf;
+       }
+
+       if (!pkgconf_buffer_append(&path1, localbase) ||
+                       !pkgconf_buffer_append(&path1, "/libdata/pkgconfig"))
+               err(1, NULL);
+       pkgconf_path_add(pkgconf_buffer_str(&path1), dirlist, false);
+
+       pkgconf_path_add("/usr/libdata/pkgconfig", dirlist, false);
+
+       if (!pkgconf_buffer_append(&path2, localbase) ||
+                       !pkgconf_buffer_append(&path2, "/share/pkgconfig"))
+               err(1, NULL);
+       pkgconf_path_add(pkgconf_buffer_str(&path2), dirlist, false);
 #else
        pkgconf_path_split(PKG_DEFAULT_PATH, dirlist, false);
 #endif
@@ -324,6 +358,12 @@ pkgconf_cross_personality_find(const char *triplet)
 #if ! defined(_WIN32) && ! defined(__HAIKU__)
        const char *envvar;
 #endif
+#if defined(__FreeBSD__)
+       pkgconf_buffer_t path = PKGCONF_BUFFER_INITIALIZER;
+       char const *localbase;
+       char buf[MAXPATHLEN];
+       size_t len;
+#endif
 
        out = load_personality_with_path(triplet, NULL, false);
        if (out != NULL)
@@ -362,7 +402,28 @@ pkgconf_cross_personality_find(const char *triplet)
        pkgconf_path_free(&plist);
 #endif
 
+#ifdef __FreeBSD__
+       localbase = getenv("LOCALBASE");
+
+       if (localbase == NULL) {
+               len = sizeof(buf);
+               if (sysctlbyname("user.localbase", &buf, &len, NULL, 0) < 0)
+                       err(1, "sysctl(user.localbase)");
+
+               localbase = buf;
+       }
+
+       pkgconf_path_add("/usr/share/pkgconfig/personality.d", &plist, true);
+       pkgconf_path_add("/etc/pkgconfig/personality.d", &plist, true);
+
+       if (!pkgconf_buffer_append(&path, localbase) ||
+                       !pkgconf_buffer_append(&path,
+                               "/etc/pkgconfig/personality.d"))
+               err(1, NULL);
+       pkgconf_path_add(pkgconf_buffer_str(&path), &plist, true);
+#else
        pkgconf_path_split(PERSONALITY_PATH, &plist, true);
+#endif
 
        PKGCONF_FOREACH_LIST_ENTRY(plist.head, n)
        {
diff --git a/lib/libpkgconf/Makefile b/lib/libpkgconf/Makefile
index 7f742dcc4858..eb838405966b 100644
--- a/lib/libpkgconf/Makefile
+++ b/lib/libpkgconf/Makefile
@@ -39,8 +39,6 @@ INCS+=                libpkgconf-api.h
 
 WARNS?=                3
 
-CFLAGS+=       
-DPERSONALITY_PATH=\"/usr/share/pkgconfig/personality.d:/etc/pkgconfig/personality.d:${LOCALBASE:U/usr/local}/etc/pkgconfig/personality.d\"
-CFLAGS+=       
-DPKG_DEFAULT_PATH=\"${LOCALBASE:U/usr/local}/libdata/pkgconfig:/usr/libdata/pkgconfig:${LOCALBASE:U/usr/local}/share/pkgconfig\"
 CFLAGS+=       -DSYSTEM_INCLUDEDIR=\"/usr/include\"
 CFLAGS+=       -DSYSTEM_LIBDIR=\"/usr/lib\"
 CFLAGS+=       -I${SRCTOP}/lib/libpkgconf -I${PKGCONFDIR}

Reply via email to