From e2ea661939e207855b22208faef828fd71134afc Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 7 Nov 2006 06:57:02 +0000 Subject: [PATCH] Major kernel build infrastructure changes, part 2/2 (user). These changes are primarily designed to create a 2-layer machine and cpu build hierarchy in order to support virtual kernel builds in the near term and future porting efforts in the long term. * The make program now pulls MACHINE, MACHINE_ARCH, and MACHINE_CPU from the kernel hw.machine, hw.machine_arch, and hw.machine_cpu sysctl variables, unless overridden by environment variables. * The config program now generates additional softlinks in the kernel build directory: machine points to the platform architecture header files machine_base points to the baes of the platform architecture directory. cpu points to the cpu architecture header files cpu_base points to the base of the cpu architecture directory Additionally, the config program generates forwarding header files as includes/machine/*.h. Any cpu architecture header files that are not overridden by the platform architecture are generated in this directory. The kernel build's Makefile adjusts the -I paths to effectively merge machine/ and includes/machine/, presenting a uniform include file architecture to the kernel build. The kernel build's Makefile now automatically exports MACHINE and MACHINE_ARCH as environment variables. The kernel build's Makefile now makes opt_*, use_*, and IF header files directly available to the module build subsystem so the module build subsystem does not have to generate them in each module subdirectory. * Kernel configuration files now require both a 'machine' and a 'machine_arch' directive. Typically: machine pc32 (subject to change) machine_arch i386 * /usr/include/cpu has been added to augment /usr/include/machine. The buildworld infrastructure also automatically merges any header files that were not overridden by the header files into /usr/include/machine. Note that direct access to /usr/include/cpu is not recommended. * A number of weird cases that generate extranious 'machine' softlinks (for header access) have been removed. * The MACHINE_ARCH default to i386 has been removed. If the make program does not define the MACHINE_ environment and sys.mk is included, sys.mk will now fail with an error. * cpdup has been added to the bootstrap tools. --- Makefile.inc1 | 11 ++- etc/mtree/BSD.include.dist | 4 +- include/Makefile | 40 +++++++--- share/mk/sys.mk | 23 ++++-- test/sysperf/syscall1.c | 7 +- usr.bin/doscmd/register.h | 4 +- usr.bin/make/main.c | 62 +++++++++------ usr.sbin/config/config.h | 6 +- usr.sbin/config/config.y | 16 ++-- usr.sbin/config/configvers.h | 4 +- usr.sbin/config/lang.l | 6 +- usr.sbin/config/main.c | 146 +++++++++++++++++++++++++++-------- usr.sbin/config/mkmakefile.c | 14 ++-- usr.sbin/config/mkoptions.c | 10 ++- 14 files changed, 243 insertions(+), 110 deletions(-) diff --git a/Makefile.inc1 b/Makefile.inc1 index 13f510f142..b6d01453d5 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -1,6 +1,6 @@ # # $FreeBSD: src/Makefile.inc1,v 1.141.2.62 2003/04/06 19:54:00 dwmalone Exp $ -# $DragonFly: src/Makefile.inc1,v 1.90 2006/10/22 16:26:44 dillon Exp $ +# $DragonFly: src/Makefile.inc1,v 1.91 2006/11/07 06:56:59 dillon Exp $ # # Build-time options are documented in make.conf(5). # @@ -155,8 +155,11 @@ BUILD_ARCH!= sysctl -n hw.machine_arch # WORLD (Cross built) Our ultimate buildworld, using only BTOOLS and # CTOOLS. # -# MACHINE_ARCH Architecture we are building on -# TARGET_ARCH Architecture we are building for +# MACHINE Platform Architecture we are buliding on +# MACHINE_ARCH Cpu Architecture we are building on +# +# TARGET Platform Architecture we are building for +# TARGET_ARCH Cpu Architecture we are building for # BTOOLSDEST= ${DESTDIRBASE}/btools_${MACHINE_ARCH} CTOOLSDEST= ${DESTDIRBASE}/ctools_${MACHINE_ARCH}_${TARGET_ARCH} @@ -761,7 +764,7 @@ bootstrap-tools: ${LN} -fs /bin/date ${BTOOLSDEST}/bin/date .for _tool in ${_strfile} \ usr.bin/patch \ - bin/chmod bin/cp bin/dd bin/mkdir bin/rm bin/echo bin/test \ + bin/chmod bin/cp bin/cpdup bin/dd bin/mkdir bin/rm bin/echo bin/test \ bin/cat bin/ln bin/mv bin/csh bin/expr bin/sh \ bin/hostname bin/kill \ usr.bin/yacc usr.bin/colldef usr.bin/uudecode usr.bin/xinstall \ diff --git a/etc/mtree/BSD.include.dist b/etc/mtree/BSD.include.dist index 52604f219a..8bceaea098 100644 --- a/etc/mtree/BSD.include.dist +++ b/etc/mtree/BSD.include.dist @@ -1,5 +1,5 @@ # $FreeBSD: src/etc/mtree/BSD.include.dist,v 1.32.2.14 2003/01/24 09:47:07 roam Exp $ -# $DragonFly: src/etc/mtree/BSD.include.dist,v 1.21 2006/09/27 12:10:33 corecode Exp $ +# $DragonFly: src/etc/mtree/BSD.include.dist,v 1.22 2006/11/07 06:57:02 dillon Exp $ # # Please see the file src/etc/mtree/README before making changes to this file. # @@ -136,6 +136,8 @@ .. .. .. + cpu + .. isc .. libmilter diff --git a/include/Makefile b/include/Makefile index bc1a00286e..d3ecb2e008 100644 --- a/include/Makefile +++ b/include/Makefile @@ -1,6 +1,6 @@ # @(#)Makefile 8.2 (Berkeley) 1/4/94 # $FreeBSD: src/include/Makefile,v 1.109.2.27 2003/01/24 05:12:29 sam Exp $ -# $DragonFly: src/include/Makefile,v 1.30 2006/10/22 16:12:50 dillon Exp $ +# $DragonFly: src/include/Makefile,v 1.31 2006/11/07 06:57:02 dillon Exp $ # # Doing a make install builds /usr/include # @@ -137,12 +137,19 @@ INCSLINKS+= netproto/ncp ${INCLUDEDIR}/netncp INCSLINKS+= netproto/ns ${INCLUDEDIR}/netns INCSLINKS+= netproto/smb ${INCLUDEDIR}/netsmb INCSLINKS+= bus/pccard ${INCLUDEDIR}/pccard -# warning, we cannot softlink through ${INCLUDEDIR}/machine/... because -# machine itself is a softlink into the source tree in buildworld's -# temporary include hierarchy. + +# NOTE! +# +# machine/ header files come from the platform architecture and +# cpu/ header files come from the cpu architecture. All code outside +# of the machine header files ALWAYS #include's . So +# if the platform architecture is missing a header file we have to +# copy it in from the cpu architecture. This way we do not have to +# create dozens of pure forwarding headers for files that platform +# architecture does not need to enhance. mtree_setup: -.for i in ${LDIRS} ${LSYMSUBDIRS} ${LSYMSUBDIRS3} machine crypto +.for i in ${LDIRS} ${LSYMSUBDIRS} ${LSYMSUBDIRS3} machine cpu crypto if [ -h ${DESTDIR}/usr/include/$i ]; then \ rm -f ${DESTDIR}/usr/include/$i; \ fi @@ -159,12 +166,20 @@ copies: mtree_setup cd ${.CURDIR}/../sys; \ ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 opencrypto/*.h \ ${DESTDIR}/usr/include/crypto -.if exists(${.CURDIR}/../sys/arch/${MACHINE_ARCH}/include) - cd ${.CURDIR}/../sys/arch/${MACHINE_ARCH}/include; \ +.if exists(${.CURDIR}/../sys/cpu/${MACHINE_ARCH}/include) + cd ${.CURDIR}/../sys/cpu/${MACHINE_ARCH}/include; \ + ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 *.h \ + ${DESTDIR}/usr/include/cpu + # XXX this will cause quickworld to rebuild more junk + # then it needs to. + cpdup -o ${DESTDIR}/usr/include/cpu ${DESTDIR}/usr/include/machine +.endif +.if exists(${.CURDIR}/../sys/machine/${MACHINE}/include) + cd ${.CURDIR}/../sys/machine/${MACHINE}/include; \ ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 *.h \ ${DESTDIR}/usr/include/machine -.if exists(${.CURDIR}/../sys/arch/${MACHINE_ARCH}/include/pc) - cd ${.CURDIR}/../sys/arch/${MACHINE_ARCH}/include/pc; \ +.if exists(${.CURDIR}/../sys/machine/${MACHINE}/include/pc) + cd ${.CURDIR}/../sys/machine/${MACHINE}/include/pc; \ ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 *.h \ ${DESTDIR}/usr/include/machine/pc .endif @@ -197,8 +212,13 @@ symlinks: mtree_setup rm -rf ${DESTDIR}/usr/include/$i ${LN} -s ../../../../sys/$i ${DESTDIR}/usr/include/$i .endfor + rm -rf ${DESTDIR}/usr/include/cpu + ${LN} -s ../../sys/cpu/${MACHINE_ARCH}/include ${DESTDIR}/usr/include/cpu rm -rf ${DESTDIR}/usr/include/machine - ${LN} -s ../../sys/arch/${MACHINE_ARCH}/include ${DESTDIR}/usr/include/machine + cpdup ${.CURDIR}/../sys/cpu/${MACHINE_ARCH}/include \ + ${DESTDIR}/usr/include/machine + cpdup -o ${.CURDIR}/../sys/machine/${MACHINE}/include \ + ${DESTDIR}/usr/include/machine rm -rf ${DESTDIR}/usr/include/i4b_machine ${LN} -s ../../sys/net/i4b/include/${MACHINE_ARCH} ${DESTDIR}/usr/include/i4b_machine diff --git a/share/mk/sys.mk b/share/mk/sys.mk index e852b2fe94..aea350919b 100644 --- a/share/mk/sys.mk +++ b/share/mk/sys.mk @@ -1,6 +1,6 @@ # from: @(#)sys.mk 8.2 (Berkeley) 3/21/94 # $FreeBSD: src/share/mk/sys.mk,v 1.45.2.6 2002/12/23 16:33:37 ru Exp $ -# $DragonFly: src/share/mk/sys.mk,v 1.15 2006/01/26 17:48:35 corecode Exp $ +# $DragonFly: src/share/mk/sys.mk,v 1.16 2006/11/07 06:57:02 dillon Exp $ unix ?= We run FreeBSD, not UNIX. @@ -112,12 +112,21 @@ YFLAGS ?= YFLAGS ?= -d .endif -# FreeBSD/i386 has traditionally been built with a version of make -# which knows MACHINE, but not MACHINE_ARCH. When building on other -# architectures, assume that the version of make being used has an -# explicit MACHINE_ARCH setting and treat a missing MACHINE_ARCH -# as an i386 architecture. -MACHINE_ARCH ?= i386 +# The 'make' program is expected to define the following. +# +# MACHINE machine class +# MACHINE_ARCH machine architecture (i386, amd64, vkernel, etc) +# MACHINE_CPU cpu architecture (i386) +# +.if !defined(MACHINE) +.error "MACHINE was not defined by make" +.endif +.if !defined(MACHINE_ARCH) +.error "MACHINE_ARCH was not defined by make" +.endif +.if !defined(MACHINE_CPU) +.error "MACHINE_CPU was not defined by make" +.endif .if defined(%POSIX) # Posix 1003.2 mandated rules diff --git a/test/sysperf/syscall1.c b/test/sysperf/syscall1.c index 551bfa85ef..721846857a 100644 --- a/test/sysperf/syscall1.c +++ b/test/sysperf/syscall1.c @@ -1,7 +1,7 @@ /* * syscall1.c * - * $DragonFly: src/test/sysperf/syscall1.c,v 1.1 2003/08/12 02:29:44 dillon Exp $ + * $DragonFly: src/test/sysperf/syscall1.c,v 1.2 2006/11/07 06:57:02 dillon Exp $ */ #include "blib.h" @@ -11,6 +11,7 @@ main(int ac, char **av) { long long count = 0; long long max; + char c; int j; printf("timing standard getuid() syscall\n"); @@ -18,14 +19,14 @@ main(int ac, char **av) start_timing(); while (stop_timing(0, NULL) == 0) { for (j = 0; j < 100; ++j) - getuid(); + read(0, &c, 1); count += 100; } max = count; start_timing(); for (count = 0; count < max; count += 100) { for (j = 0; j < 100; ++j) - getuid(); + read(0, &c, 1); } stop_timing(count, "getuid()"); return(0); diff --git a/usr.bin/doscmd/register.h b/usr.bin/doscmd/register.h index 39582ecbed..c98e41841f 100644 --- a/usr.bin/doscmd/register.h +++ b/usr.bin/doscmd/register.h @@ -24,7 +24,7 @@ ** SUCH DAMAGE. ** ** $FreeBSD: src/usr.bin/doscmd/register.h,v 1.4 1999/10/08 09:02:38 marcel Exp $ -** $DragonFly: src/usr.bin/doscmd/register.h,v 1.4 2004/01/22 03:22:52 rob Exp $ +** $DragonFly: src/usr.bin/doscmd/register.h,v 1.5 2006/11/07 06:57:02 dillon Exp $ */ /****************************************************************************** @@ -32,7 +32,7 @@ ** */ -#ifndef _MACHINE_VM86_H_ +#ifndef _CPU_VM86_H_ /* standard register representation */ typedef union diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index 6fd07e464f..2c2756e972 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -38,7 +38,7 @@ * @(#) Copyright (c) 1988, 1989, 1990, 1993 The Regents of the University of California. All rights reserved. * @(#)main.c 8.3 (Berkeley) 3/19/94 * $FreeBSD: src/usr.bin/make/main.c,v 1.118 2005/02/13 13:33:56 harti Exp $ - * $DragonFly: src/usr.bin/make/main.c,v 1.144 2006/08/25 22:37:09 swildner Exp $ + * $DragonFly: src/usr.bin/make/main.c,v 1.145 2006/11/07 06:57:02 dillon Exp $ */ /* @@ -59,6 +59,7 @@ #endif #include #include +#include #include #include #include @@ -768,6 +769,8 @@ InitVariables(const char progname[]) const char *machine; const char *machine_arch; const char *machine_cpu; + char buf[256]; + size_t bufsiz; Var_SetGlobal("MAKE", progname); Var_SetGlobal(".MAKEFLAGS", ""); @@ -780,41 +783,52 @@ InitVariables(const char progname[]) #endif /* - * Get the name of this type of MACHINE from utsname - * so we can share an executable for similar machines. - * (i.e. m68k: amiga hp300, mac68k, sun3, ...) + * The make program defines MACHINE and MACHINE_ARCH. These + * parameters are taken from the running system but can be + * overridden by environment variables. * - * Note that while MACHINE is decided at run-time, - * MACHINE_ARCH is always known at compile time. + * MACHINE - This is the platform, e.g. "vkernel", "i386", "sun", + * and so forth. + * + * MACHINE_ARCH - This is the cpu architecture, for example "i386". + * Several different platforms may use the same + * cpu architecture. + * + * MACHINE_CPU - This is the minimum supported cpu revision based on + * the target cpu architecture. e.g. "i486", "i586", + * etc. NOTE: This field will often be "i386" even + * for kernels built without I386_CPU. + * + * In some, but not all cases, MACHINE == MACHINE_ARCH. A virtual + * kernel build, for example, would set MACHINE to "vkernel" and + * MACHINE_ARCH to the cpu architecture. */ if ((machine = getenv("MACHINE")) == NULL) { -#ifdef MACHINE - machine = MACHINE; -#else - static struct utsname utsname; - if (uname(&utsname) == -1) - err(2, "uname"); - machine = utsname.machine; -#endif + bufsiz = sizeof(buf); + if (sysctlbyname("hw.machine", buf, &bufsiz, NULL, 0) < 0) + machine = "unknown"; + else + machine = strdup(buf); } if ((machine_arch = getenv("MACHINE_ARCH")) == NULL) { -#ifdef MACHINE_ARCH - machine_arch = MACHINE_ARCH; -#else - machine_arch = "unknown"; -#endif + bufsiz = sizeof(buf); + if (sysctlbyname("hw.machine_arch", buf, &bufsiz, NULL, 0) < 0) + machine_arch = "unknown"; + else + machine_arch = strdup(buf); } /* - * Set machine_cpu to the minumum supported CPU revision based - * on the target architecture, if not already set. + * Only newer kernels have machine_cpu. If not otherwise known set + * the minimum supported cpu architecture to the machine architecture. */ if ((machine_cpu = getenv("MACHINE_CPU")) == NULL) { - if (!strcmp(machine_arch, "i386")) - machine_cpu = "i386"; + bufsiz = sizeof(buf); + if (sysctlbyname("hw.machine_cpu", buf, &bufsiz, NULL, 0) < 0) + machine_cpu = machine_arch; else - machine_cpu = "unknown"; + machine_cpu = strdup(buf); } Var_SetGlobal("MACHINE", machine); diff --git a/usr.sbin/config/config.h b/usr.sbin/config/config.h index 9d978817f8..0c6a63c60d 100644 --- a/usr.sbin/config/config.h +++ b/usr.sbin/config/config.h @@ -32,7 +32,7 @@ * * @(#)config.h 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.sbin/config/config.h,v 1.35.2.1 2000/08/03 00:09:56 peter Exp $ - * $DragonFly: src/usr.sbin/config/config.h,v 1.7 2006/10/23 18:01:13 dillon Exp $ + * $DragonFly: src/usr.sbin/config/config.h,v 1.8 2006/11/07 06:57:02 dillon Exp $ */ /* @@ -108,8 +108,8 @@ struct config { * it will build from ``Makefile.i386'' and use ``../i386/inline'' * in the makerules, etc. */ -char *machinename; -char *cpuarchname; +char *machinename; /* machine/ headers and machine_base/ sources */ +char *machinearchname; /* cpu/ headers and cpu_base/ sources */ /* * For each machine, a set of CPU's may be specified as supported. diff --git a/usr.sbin/config/config.y b/usr.sbin/config/config.y index a6a4083817..577a7b91f5 100644 --- a/usr.sbin/config/config.y +++ b/usr.sbin/config/config.y @@ -5,15 +5,15 @@ } %token ANY -%token ARCH %token AT %token BUS %token COMMA %token CONFIG +%token CONFIG_MACHINE +%token CONFIG_MACHINE_ARCH %token CONFLICTS %token CONTROLLER %token CPU -%token CPU_ARCH %token DEVICE %token DISABLE %token DISK @@ -84,7 +84,7 @@ * * @(#)config.y 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.sbin/config/config.y,v 1.42.2.1 2001/01/23 00:09:32 peter Exp $ - * $DragonFly: src/usr.sbin/config/config.y,v 1.12 2006/10/23 18:01:13 dillon Exp $ + * $DragonFly: src/usr.sbin/config/config.y,v 1.13 2006/11/07 06:57:02 dillon Exp $ */ #include @@ -131,7 +131,7 @@ Spec: ; Config_spec: - ARCH Save_id + CONFIG_MACHINE Save_id = { if (machinename != NULL) { errx(1, "%d: only one machine directive is allowed", @@ -139,13 +139,13 @@ Config_spec: } machinename = $2; } | - CPU_ARCH Save_id + CONFIG_MACHINE_ARCH Save_id = { - if (cpuarchname != NULL) { - errx(1, "%d: only one cpu_arch directive is allowed", + if (machinearchname != NULL) { + errx(1, "%d: only one machine_arch directive is allowed", yyline); } - cpuarchname = $2; + machinearchname = $2; } | CPU Save_id = { diff --git a/usr.sbin/config/configvers.h b/usr.sbin/config/configvers.h index fe79260740..d1fb4563ed 100644 --- a/usr.sbin/config/configvers.h +++ b/usr.sbin/config/configvers.h @@ -7,6 +7,6 @@ * and system. * * $FreeBSD: src/usr.sbin/config/configvers.h,v 1.19.2.1 2001/12/19 18:09:32 silby Exp $ - * $DragonFly: src/usr.sbin/config/configvers.h,v 1.7 2006/10/23 18:01:13 dillon Exp $ + * $DragonFly: src/usr.sbin/config/configvers.h,v 1.8 2006/11/07 06:57:02 dillon Exp $ */ -#define CONFIGVERS 400024 +#define CONFIGVERS 400025 diff --git a/usr.sbin/config/lang.l b/usr.sbin/config/lang.l index adda12c2c1..ce9f5f890a 100644 --- a/usr.sbin/config/lang.l +++ b/usr.sbin/config/lang.l @@ -33,7 +33,7 @@ * * @(#)lang.l 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.sbin/config/lang.l,v 1.27 1999/11/09 07:20:22 peter Exp $ - * $DragonFly: src/usr.sbin/config/lang.l,v 1.11 2006/10/23 18:01:13 dillon Exp $ + * $DragonFly: src/usr.sbin/config/lang.l,v 1.12 2006/11/07 06:57:02 dillon Exp $ */ #include @@ -57,7 +57,6 @@ struct kt { { "config", CONFIG }, { "controller", CONTROLLER }, { "cpu", CPU }, - { "cpu_arch", CPU_ARCH }, { "device", DEVICE }, { "disable", DISABLE }, { "disk", DISK }, @@ -68,7 +67,8 @@ struct kt { { "iomem", IOMEM }, { "iosiz", IOSIZ }, { "irq", IRQ }, - { "machine", ARCH }, /* MACHINE is defined in /sys/param.h */ + { "machine", CONFIG_MACHINE }, + { "machine_arch", CONFIG_MACHINE_ARCH }, { "makeoptions", MAKEOPTIONS }, { "maxusers", MAXUSERS }, { "nexus", NEXUS }, diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c index 0eed3c3854..ba8947b048 100644 --- a/usr.sbin/config/main.c +++ b/usr.sbin/config/main.c @@ -33,7 +33,7 @@ * @(#) Copyright (c) 1980, 1993 The Regents of the University of California. All rights reserved. * @(#)main.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.sbin/config/main.c,v 1.37.2.3 2001/06/13 00:25:53 cg Exp $ - * $DragonFly: src/usr.sbin/config/main.c,v 1.18 2006/10/23 18:01:13 dillon Exp $ + * $DragonFly: src/usr.sbin/config/main.c,v 1.19 2006/11/07 06:57:02 dillon Exp $ */ #include @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include "y.tab.h" @@ -69,6 +70,7 @@ int profiling; static void configfile(void); static void get_srcdir(void); +static void generate_forwarding_headers(void); static void usage(void); /* @@ -157,59 +159,67 @@ main(int argc, char *argv[]) if (yyparse()) exit(3); if (machinename == NULL) { - printf("Specify machine type, e.g. ``machine i386''\n"); + printf("Specify platform architecture, e.g. 'machine pc32'\n"); exit(1); } - if (strcmp(machinename, "vkernel") == 0 && cpuarchname == NULL) { - printf("Specify cpu_arch for virtual kernel, e.g. " - "``cpu_arch i386''\n"); + if (machinearchname == NULL) { + printf("Specify cpu architecture, e.g. 'machine_arch i386'\n"); exit(1); } newbus_ioconf(); /* - * "machine" points into arch//include + * "machine" points into machine//include */ if (*srcdir == '\0') - snprintf(linkdest, sizeof(linkdest), "../../arch/%s/include", + snprintf(linkdest, sizeof(linkdest), "../../machine/%s/include", machinename); else - snprintf(linkdest, sizeof(linkdest), "%s/arch/%s/include", + snprintf(linkdest, sizeof(linkdest), "%s/machine/%s/include", srcdir, machinename); symlink(linkdest, path("machine")); /* - * "arch" points into / + * "machine_base" points into machine/ */ if (*srcdir == '\0') - snprintf(linkdest, sizeof(linkdest), "../../arch/%s", + snprintf(linkdest, sizeof(linkdest), "../../machine/%s", machinename); else - snprintf(linkdest, sizeof(linkdest), "%s/arch/%s", + snprintf(linkdest, sizeof(linkdest), "%s/machine/%s", srcdir, machinename); - symlink(linkdest, path("arch")); + symlink(linkdest, path("machine_base")); /* - * "cpu" points to //include, only if cpu_arch - * directive was specified. Used by virtual kernels. + * "cpu" points to cpu//include */ - if (cpuarchname != NULL) { - if (*srcdir == '\0') - snprintf(linkdest, sizeof(linkdest), - "../../arch/%s/include", cpuarchname); - else - snprintf(linkdest, sizeof(linkdest), - "%s/arch/%s/include", srcdir, cpuarchname); - symlink(linkdest, path("cpu")); + if (*srcdir == '\0') + snprintf(linkdest, sizeof(linkdest), + "../../cpu/%s/include", machinearchname); + else + snprintf(linkdest, sizeof(linkdest), + "%s/cpu/%s/include", srcdir, machinearchname); + symlink(linkdest, path("cpu")); - if (*srcdir == '\0') - snprintf(linkdest, sizeof(linkdest), "../../arch/%s", - cpuarchname); - else - snprintf(linkdest, sizeof(linkdest), "%s/arch/%s", - srcdir, cpuarchname); - symlink(linkdest, path("cpu_arch")); - } + /* + * "cpu_base" points to cpu/ + */ + if (*srcdir == '\0') + snprintf(linkdest, sizeof(linkdest), "../../cpu/%s", + machinearchname); + else + snprintf(linkdest, sizeof(linkdest), "%s/cpu/%s", + srcdir, machinearchname); + symlink(linkdest, path("cpu_base")); + + /* + * Create include/machine, in which we place forwarding header files + * for headers that exist in the cpu architecture but have not been + * overridden in the platform architecture. + */ + mkdir(path("include"), 0755); + mkdir(path("include/machine"), 0755); + generate_forwarding_headers(); /* * XXX check directory structure for architecture subdirectories and @@ -218,10 +228,10 @@ main(int argc, char *argv[]) if (*srcdir == '\0') snprintf(linkdest, sizeof(linkdest), "../../../../../net/i4b/include/%s", - machinename); + machinearchname); else snprintf(linkdest, sizeof(linkdest), "%s/net/i4b/include/%s", - srcdir, machinename); + srcdir, machinearchname); mkdir(path("net"), 0755); mkdir(path("net/i4b"), 0755); mkdir(path("net/i4b/include"), 0755); @@ -231,11 +241,11 @@ main(int argc, char *argv[]) if (*srcdir == 0) { snprintf(linkdest, sizeof(linkdest), "../../emulation/%s/%s", - emus[i], machinename); + emus[i], machinearchname); } else { snprintf(linkdest, sizeof(linkdest), "%s/emulation/%s/%s", - srcdir, emus[i], machinename); + srcdir, emus[i], machinearchname); } snprintf(linksrc, sizeof(linksrc), "arch_%s", emus[i]); symlink(linkdest, path(linksrc)); @@ -486,3 +496,71 @@ moveifchanged(const char *from_name, const char *to_name) err(EX_OSERR, "unlink(%s)", from_name); } } + +static +void +generate_forwarding_headers(void) +{ + char buf[MAXPATHLEN]; + char upper[256]; + char *ptr; + struct dirent *den; + DIR *dir; + FILE *fp; + + if (*srcdir == '\0') + snprintf(buf, sizeof(buf), "../../cpu/%s/include", + machinearchname); + else + snprintf(buf, sizeof(buf), "%s/cpu/%s/include", + srcdir, machinearchname); + + if ((dir = opendir(buf)) != NULL) { + while ((den = readdir(dir)) != NULL) { + if (den->d_name[0] == '.') + continue; + + /* + * Is this a header file? + */ + snprintf(upper, sizeof(upper), "%s", den->d_name); + ptr = strrchr(upper, '.'); + if (ptr == NULL || strcmp(ptr, ".h") != 0) + continue; + + /* + * Generate an upper case symbol + */ + *ptr = 0; + for (ptr = upper; *ptr; ++ptr) { + if (*ptr == '.') + *ptr = '_'; + else if (islower(*ptr)) + *ptr = toupper(*ptr); + } + + /* + * Generate a forwarding header file + */ + snprintf(buf, sizeof(buf), "%s/%s", + path("include/machine"), den->d_name); + fp = fopen(buf, "w"); + fprintf(fp, "/*\n" + " * CONFIG-GENERATED FILE, DO NOT EDIT\n" + " */\n" + "\n" + "#ifndef _MACHINE_%s_H_\n" + "#define _MACHINE_%s_H_\n" + "#include \n" + "#endif\n" + "\n", + upper, + upper, + den->d_name + ); + fclose(fp); + } + closedir(dir); + } +} + diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c index a67f79b96a..fb58706de7 100644 --- a/usr.sbin/config/mkmakefile.c +++ b/usr.sbin/config/mkmakefile.c @@ -32,7 +32,7 @@ * * @(#)mkmakefile.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.sbin/config/mkmakefile.c,v 1.51.2.3 2001/01/23 00:09:32 peter Exp $ - * $DragonFly: src/usr.sbin/config/mkmakefile.c,v 1.16 2006/10/22 16:09:08 dillon Exp $ + * $DragonFly: src/usr.sbin/config/mkmakefile.c,v 1.17 2006/11/07 06:57:02 dillon Exp $ */ /* @@ -144,8 +144,8 @@ makefile(void) int versreq; read_files(); - snprintf(line, sizeof(line), "../arch/%s/conf/Makefile.%s", - machinename, machinename); + snprintf(line, sizeof(line), "../machine/%s/conf/Makefile", + machinename); ifp = fopen(line, "r"); if (ifp == NULL) { snprintf(line, sizeof(line), "Makefile.%s", machinename); @@ -157,6 +157,10 @@ makefile(void) if (ofp == NULL) err(1, "%s", path("Makefile.new")); fprintf(ofp, "KERN_IDENT=%s\n", raisestr(ident)); + fprintf(ofp, "MACHINE=%s\n", machinename); + fprintf(ofp, "MACHINE_ARCH=%s\n", machinearchname); + fprintf(ofp, ".makeenv MACHINE\n"); + fprintf(ofp, ".makeenv MACHINE_ARCH\n"); fprintf(ofp, "IDENT="); if (profiling) fprintf(ofp, " -DGPROF"); @@ -263,8 +267,8 @@ next: if (first == 1) { first++; snprintf(fname, sizeof(fname), - "../arch/%s/conf/files.%s", - machinename, machinename); + "../machine/%s/conf/files", + machinename); fp = fopen(fname, "r"); if (fp != NULL) goto next; diff --git a/usr.sbin/config/mkoptions.c b/usr.sbin/config/mkoptions.c index d00d00017a..ac894dfb76 100644 --- a/usr.sbin/config/mkoptions.c +++ b/usr.sbin/config/mkoptions.c @@ -33,7 +33,7 @@ * * @(#)mkheaders.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.sbin/config/mkoptions.c,v 1.17.2.3 2001/12/13 19:18:01 dillon Exp $ - * $DragonFly: src/usr.sbin/config/mkoptions.c,v 1.17 2006/10/22 16:09:08 dillon Exp $ + * $DragonFly: src/usr.sbin/config/mkoptions.c,v 1.18 2006/11/07 06:57:02 dillon Exp $ */ /* @@ -302,12 +302,14 @@ next: fclose(fp); if (first == 1) { first++; - snprintf(fname, sizeof(fname), "../arch/%s/conf/options.%s", - machinename, machinename); + snprintf(fname, sizeof(fname), + "../machine/%s/conf/options", + machinename); fp = fopen(fname, "r"); if (fp != NULL) goto next; - snprintf(fname, sizeof(fname), "options.%s", machinename); + snprintf(fname, sizeof(fname), "options.%s", + machinename); goto openit; } if (first == 2) { -- 2.41.0