cmd: honor package library roots in both stages

This commit is contained in:
2026-08-12 15:18:46 +09:00
parent bb71b31f81
commit 5a2e4ba28d
2 changed files with 94 additions and 41 deletions

View File

@@ -33,11 +33,18 @@ static const char *usage =
static char *self_dir;
static const char *
envpath(const char *name)
{
const char *p = getenv(name);
return p && p[0] ? p : NULL;
}
static const char *
toolpath(const char *envvar, const char *name)
{
const char *p = getenv(envvar);
if (p && p[0]) return p;
const char *p = envpath(envvar);
if (p) return p;
static char buf[1024];
snprintf(buf, sizeof buf, "%s/%s", self_dir, name);
return strdup(buf);
@@ -1681,15 +1688,15 @@ build_one_sep_impl(const char *src, int entry_is_dir,
const char *c6 = toolpath("WW_W6C", "w6c");
const char *a6 = toolpath("WW_W6A", "w6a");
const char *l6 = toolpath("WW_W6L", "w6l");
const char *libdir = getenv("WW_LIB");
if (libdir == NULL || libdir[0] == 0) {
const char *libdir = envpath("WW_LIB");
if (libdir == NULL) {
static char libbuf[1024];
snprintf(libbuf, sizeof libbuf, "%s/../lib", self_dir);
libdir = libbuf;
}
const char *srcdir = getenv("WW_SRCLIB");
const char *srcdir = envpath("WW_SRCLIB");
static char srcbuf[1024];
if (srcdir == NULL || srcdir[0] == 0) {
if (srcdir == NULL) {
snprintf(srcbuf, sizeof srcbuf, "%s/../../lib", self_dir);
if (access(srcbuf, 0) == 0) srcdir = srcbuf;
else if (access("lib", 0) == 0) srcdir = "lib";
@@ -2267,17 +2274,17 @@ do_version(void)
return 0;
}
/* Compose the standard module search path: cwd : <extra-includes> : $WW_LIB
* source dir. The `extra` string is colon-separated -I dirs from argv. */
/* Compose the standard module search path: cwd : <extra-includes> : selected
* source library. The `extra` string is colon-separated -I dirs from argv. */
static const char *
search_path(const char *extra, char *buf, size_t bufsz)
{
const char *libdir = getenv("WW_SRCLIB");
const char *libdir = envpath("WW_SRCLIB");
static char libbuf[1024];
if (libdir == NULL || libdir[0] == 0) {
libdir = getenv("WW_LIB");
if (libdir == NULL) {
libdir = envpath("WW_LIB");
}
if (libdir == NULL || libdir[0] == 0) {
if (libdir == NULL) {
snprintf(libbuf, sizeof libbuf, "%s/../../lib", self_dir);
if (access(libbuf, 0) == 0) libdir = libbuf;
else if (access("lib", 0) == 0) libdir = "lib";