From d630a05f40fa67600be81eb1dab77bef8903c03d Mon Sep 17 00:00:00 2001 From: Doug Ambrisko Date: Fri, 2 Dec 2005 00:50:30 +0000 Subject: [PATCH] Add support to easily build FreeBSD unpacked in a chroot of another FreeBSD machine. To do this add the man 1 uname changes to __xuname.c so we can override the settings it reports. Add OSVERSION override to getosreldate. Finally which Makefile.inc1 to use uname -m instead of sysctl -n hw.machine_arch to get the arch. type. With these change you can put a complete FreeBSD OS image into a chroot set: UNAME_s=FreeBSD UNAME_r=4.7-RELEASE UNAME_v="FreeBSD $UNAME_r #1: Fri Jul 22 20:32:52 PDT 2005 fake@fake:/usr/obj/usr/src/sys/FAKE" UNAME_m=i386 UNAME_p=i386 OSVERSION=470000 on an amd64 or i386 and it just work including building ports and using pkg_add -r etc. The caveat for this example is that these patches have to be applied to FreeBSD 4.7 and the uname(1) changes need to be merged. This also addresses issue with libtool. This is usefull for when a build machine has been trashed for an old release and we want to do a build on a new machine that FreeBSD 4.7 won't run on ... --- Makefile.inc1 | 2 +- lib/libc/gen/__xuname.c | 8 ++++++++ lib/libc/gen/getosreldate.c | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Makefile.inc1 b/Makefile.inc1 index 8f140a6ff6d..6a93be9aa8f 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -122,7 +122,7 @@ _CPUTYPE!= MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} \ .error CPUTYPE global should be set with ?=. .endif .if make(buildworld) -BUILD_ARCH!= sysctl -n hw.machine_arch +BUILD_ARCH!= uname -m .if ${MACHINE_ARCH} != ${BUILD_ARCH} .error To cross-build, set TARGET_ARCH. .endif diff --git a/lib/libc/gen/__xuname.c b/lib/libc/gen/__xuname.c index 4d1be8c04f1..c7965743675 100644 --- a/lib/libc/gen/__xuname.c +++ b/lib/libc/gen/__xuname.c @@ -71,6 +71,8 @@ __xuname(int namesize, void *namebuf) rval = -1; } name->sysname[sizeof(name->sysname) - 1] = '\0'; + if ((p = getenv("UNAME_s"))) + strncpy(name->sysname, p, sizeof(name->sysname)); mib[0] = CTL_KERN; mib[1] = KERN_HOSTNAME; @@ -95,6 +97,8 @@ __xuname(int namesize, void *namebuf) rval = -1; } name->release[sizeof(name->release) - 1] = '\0'; + if ((p = getenv("UNAME_r"))) + strncpy(name->release, p, sizeof(name->release)); /* The version may have newlines in it, turn them into spaces. */ mib[0] = CTL_KERN; @@ -116,6 +120,8 @@ __xuname(int namesize, void *namebuf) *p = '\0'; } } + if ((p = getenv("UNAME_v"))) + strncpy(name->version, p, sizeof(name->version)); mib[0] = CTL_HW; mib[1] = HW_MACHINE; @@ -128,5 +134,7 @@ __xuname(int namesize, void *namebuf) rval = -1; } name->machine[sizeof(name->machine) - 1] = '\0'; + if ((p = getenv("UNAME_m"))) + strncpy(name->machine, p, sizeof(name->machine)); return (rval); } diff --git a/lib/libc/gen/getosreldate.c b/lib/libc/gen/getosreldate.c index 22c400d1c73..03a00c1b6a8 100644 --- a/lib/libc/gen/getosreldate.c +++ b/lib/libc/gen/getosreldate.c @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include @@ -49,10 +50,14 @@ getosreldate(void) size_t size; int value; + char *temp; + mib[0] = CTL_KERN; mib[1] = KERN_OSRELDATE; size = sizeof value; if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) return (-1); + if ((temp = getenv("OSVERSION"))) + value = atoi(temp); return (value); }