xbps_init: autodetect musl libc variant at compile time.

This way we don't need to set the 'architecture' xbps.d
setting when the binaries are compiled for musl.

Close #195
This commit is contained in:
Juan RP
2019-12-27 16:14:07 +01:00
parent 66b07bb795
commit 7f75fd840a
3 changed files with 19 additions and 4 deletions

View File

@@ -107,10 +107,20 @@ xbps_init(struct xbps_handle *xhp)
if ((native_arch = getenv("XBPS_ARCH")) != NULL) {
xbps_strlcpy(xhp->native_arch, native_arch, sizeof (xhp->native_arch));
} else {
char *s = NULL;
struct utsname un;
if (uname(&un) == -1)
return ENOTSUP;
#if defined(__linux__) && !defined(__GLIBC__)
/* musl libc on linux */
s = xbps_xasprintf("%s-musl", un.machine);
assert(s);
xbps_strlcpy(xhp->native_arch, s, sizeof(xhp->native_arch));
free(s);
#else
/* glibc or any other os */
xbps_strlcpy(xhp->native_arch, un.machine, sizeof (xhp->native_arch));
#endif
}
assert(xhp->native_arch);