Skip to content

Commit

Permalink
Don't print system paths by default
Browse files Browse the repository at this point in the history
mainly for compatibility with pkgconf. also the `--keep-system-libs`
flag seems to be used in practice [0] so seems to be worth it to support
it.

[0]: https://github.com/gentoo/gentoo/blob/b743fa0be223a9a220cae24820048d53b7ee0b31/dev-lang/python/python-3.10.9.ebuild#L234
  • Loading branch information
N-R-K authored and skeeto committed Jan 22, 2023
1 parent b7fafa6 commit c069c94
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ summary:

* Omits most `.pc` debugging features (`--print-…`)
* No special handling of "uninstalled" packages, and no attendant knobs
* No removal of standard system paths (e.g. `/usr/include`)
* Skips checks unimplemented by pkg-config (i.e. `Conflicts:`)
* Omits clunky redundant features (`--exists`, `--errors-to-stdout`, etc.)
* Less strict `.pc` syntax
Expand Down
16 changes: 16 additions & 0 deletions generic_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
# endif
#endif

#ifndef PKG_CONFIG_SYSTEM_INCLUDE_PATH
# define PKG_CONFIG_SYSTEM_INCLUDE_PATH "/usr/include"
#endif

#ifndef PKG_CONFIG_SYSTEM_LIBRARY_PATH
# define PKG_CONFIG_SYSTEM_LIBRARY_PATH "/lib" PATHDELIM "/usr/lib"
#endif

#ifndef PKG_CONFIG_PREFIX
# define PKG_CONFIG_PREFIX "/usr"
#endif
Expand Down Expand Up @@ -85,6 +93,14 @@ int main(int argc, char **argv)
if (!conf.fixedpath.s) {
conf.fixedpath = S(pkg_config_path);
}
conf.sys_incpath = fromcstr_(getenv("PKG_CONFIG_SYSTEM_INCLUDE_PATH"));
if (!conf.sys_incpath.s) {
conf.sys_incpath = S(PKG_CONFIG_SYSTEM_INCLUDE_PATH);
}
conf.sys_libpath = fromcstr_(getenv("PKG_CONFIG_SYSTEM_LIBRARY_PATH"));
if (!conf.sys_libpath.s) {
conf.sys_libpath = S(PKG_CONFIG_SYSTEM_LIBRARY_PATH);
}
conf.top_builddir = fromcstr_(getenv("PKG_CONFIG_TOP_BUILD_DIR"));

appmain(conf);
Expand Down
45 changes: 43 additions & 2 deletions u-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ typedef struct {
Str envpath; // $PKG_CONFIG_PATH or empty
Str fixedpath; // $PKG_CONFIG_LIBDIR or default
Str top_builddir; // $PKG_CONFIG_TOP_BUILD_DIR or default
Str sys_incpath; // $PKG_CONFIG_SYSTEM_INCLUDE_PATH or default
Str sys_libpath; // $PKG_CONFIG_SYSTEM_LIBRARY_PATH or default
Bool define_prefix;
Byte delim;
} Config;
Expand Down Expand Up @@ -805,6 +807,7 @@ static void usage(Out *out)
" --cflags, --cflags-only-I, --cflags-only-other\n"
" --define-prefix, --dont-define-prefix\n"
" --define-variable=NAME=VALUE, --variable=NAME\n"
" --keep-system-cflags, --keep-system-libs\n"
" --libs, --libs-only-L, --libs-only-l, --libs-only-other\n"
" --modversion\n"
" --newlines\n"
Expand Down Expand Up @@ -1539,6 +1542,32 @@ static OutConfig newoutconf(Arena *a, Out *out, Out *err)
return r;
}

static void insertsyspath(OutConfig *conf, Str path, Byte delim, Byte flag)
{
Byte flagbuf[] = {'-', flag};
Str prefix = {flagbuf, SIZEOF(flagbuf)};
while (path.len) {
Arena snapshot = *conf->arena;
Cut c = cut(path, delim);
Str dir = c.head;
path = c.tail;
if (!dir.len) {
continue;
}
Str syspath = newstr(&snapshot, prefix.len+dir.len);
copy(copy(syspath, prefix), dir);
// NOTE(NRK): Technically, the path doesn't need to follow the flag
// immediately (e.g `-I /usr/include`). But I have not seen a single
// pc file that does this.
//
// In fact, `pkgconf` also fails to recognize `-I /usr/include` as
// a system include path! So this should be fine in practice.
if (insertstr(&snapshot, conf->seen, syspath)) {
*conf->arena = snapshot;
}
}
}

// Process the field while writing it to the output.
static void fieldout(OutConfig *conf, Pkg *p, Str field)
{
Expand Down Expand Up @@ -1589,6 +1618,8 @@ static void appmain(Config conf)
Bool silent = 0;
Bool static_ = 0;
Bool modversion = 0;
Bool print_sysinc = 0;
Bool print_syslib = 0;
Str variable = {0, 0};

proc.define_prefix = conf.define_prefix;
Expand All @@ -1597,6 +1628,8 @@ static void appmain(Config conf)
}

*insert(a, &global, S("pc_path")) = conf.fixedpath;
*insert(a, &global, S("pc_system_includedirs")) = conf.sys_incpath;
*insert(a, &global, S("pc_system_libdirs")) = conf.sys_libpath;
*insert(a, &global, S("pc_sysrootdir")) = S("/");
*insert(a, &global, S("pc_top_builddir")) = conf.top_builddir;

Expand Down Expand Up @@ -1707,10 +1740,10 @@ static void appmain(Config conf)
// Ignore

} else if (equals(r.arg, S("-keep-system-cflags"))) {
// Ignore: already the default behavior
print_sysinc = 1;

} else if (equals(r.arg, S("-keep-system-libs"))) {
// Ignore: already the default behavior
print_syslib = 1;

} else if (equals(r.arg, S("-validate"))) {
silent = 1;
Expand All @@ -1730,6 +1763,14 @@ static void appmain(Config conf)
err = newnullout();
}

if (!print_sysinc) {
insertsyspath(&outconf, conf.sys_incpath, conf.delim, 'I');
}

if (!print_syslib) {
insertsyspath(&outconf, conf.sys_libpath, conf.delim, 'L');
}

for (Size i = 0; i < nargs; i++) {
process(a, &proc, args[i]);
}
Expand Down

0 comments on commit c069c94

Please sign in to comment.