- Add kern.fwd.mk to generate forward headers for missing machine/*.h
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Sun, 19 Nov 2006 07:49:34 +0000 (07:49 +0000)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Sun, 19 Nov 2006 07:49:34 +0000 (07:49 +0000)
  It avoids unnecessary regeneration of forward headers by default, thus
  quickkernel is speedy again :)
- Nuke no longer needed generate_forwarding_headers() in config(8)
- Add forward headers generation to the dependency list of "beforedepend"
  in kmod.mk.  This unbreaks module building which does not happen along
  with kernel building.

The original patch was submitted by y0netan1@, changes made to the original
patch are OKed by him too.

Reviewed-by: dillon@ corecode@
sys/conf/kern.fwd.mk [new file with mode: 0644]
sys/conf/kern.post.mk
sys/conf/kmod.mk
usr.sbin/config/main.c

diff --git a/sys/conf/kern.fwd.mk b/sys/conf/kern.fwd.mk
new file mode 100644 (file)
index 0000000..903e50b
--- /dev/null
@@ -0,0 +1,34 @@
+# $DragonFly: src/sys/conf/kern.fwd.mk,v 1.1 2006/11/19 07:49:34 sephe Exp $
+
+# Create forwarding headers for ${SYSDIR}/cpu/${MACHINE_ARCH}/*.h in
+# ${_MACHINE_FWD}/include/machine and share the directory among module build
+# directories.
+# Define _MACHINE_FWD before inclusion of this file.
+.if !defined(_MACHINE_FWD)
+.error you must define _MACHINE_FWD in which to generate forwarding headers.
+.endif
+
+_cpu_hdrs!=    echo ${SYSDIR}/cpu/${MACHINE_ARCH}/include/*.h
+_FWDHDRS=
+.for _h in ${_cpu_hdrs}
+_fwd:= ${_MACHINE_FWD}/include/machine/${_h:T}
+_FWDHDRS:=     ${_FWDHDRS} ${_fwd}
+${_fwd}: ${_h}
+.endfor
+${_MACHINE_FWD} ${_MACHINE_FWD}/include/machine:
+       @mkdir -p ${.TARGET}
+
+forwarding-headers: ${_MACHINE_FWD}/include/machine ${_FWDHDRS}
+       @touch ${_MACHINE_FWD}/.done
+
+${_FWDHDRS}:
+       @(echo "creating forwarding header ${.TARGET}" 1>&2; \
+       echo "/*" ; \
+       echo " * CONFIG-GENERATED FILE, DO NOT EDIT" ; \
+       echo " */" ; \
+       echo ; \
+       echo "#ifndef _MACHINE_${.TARGET:T:S/./_/g:U:R}_H_" ; \
+       echo "#define _MACHINE_${.TARGET:T:S/./_/g:U:R}_H_" ; \
+       echo "#include <cpu/${.TARGET:T}>" ; \
+       echo "#endif" ; \
+       echo) > ${.TARGET}
index 4a70cd5..1654c34 100644 (file)
@@ -1,4 +1,4 @@
-# $DragonFly: src/sys/conf/kern.post.mk,v 1.3 2006/11/07 06:43:22 dillon Exp $
+# $DragonFly: src/sys/conf/kern.post.mk,v 1.4 2006/11/19 07:49:34 sephe Exp $
 # 
 # This Makefile covers the bottom part of the MI build instructions
 #
@@ -7,6 +7,9 @@
 
 all: ${KERNEL}.stripped
 
+_MACHINE_FWD=  ${.OBJDIR}
+depend kernel-depend modules-depend: forwarding-headers
+
 depend: kernel-depend
 clean:  kernel-clean
 cleandepend:  kernel-cleandepend
@@ -208,4 +211,5 @@ vers.o:
 #vnode_if.o:
 #      ${NORMAL_C}
 
+.include "$S/conf/kern.fwd.mk"
 .include "$S/conf/bsd.kern.mk"
index bed2e10..88a8382 100644 (file)
@@ -1,6 +1,6 @@
 #      From: @(#)bsd.prog.mk   5.26 (Berkeley) 6/25/91
 # $FreeBSD: src/sys/conf/kmod.mk,v 1.82.2.15 2003/02/10 13:11:50 nyan Exp $
-# $DragonFly: src/sys/conf/kmod.mk,v 1.28 2006/11/07 06:43:22 dillon Exp $
+# $DragonFly: src/sys/conf/kmod.mk,v 1.29 2006/11/19 07:49:34 sephe Exp $
 #
 # The include file <bsd.kmod.mk> handles installing Kernel Loadable Device
 # drivers (KLD's).
@@ -93,8 +93,17 @@ CFLAGS+=     -I. -I@
 #
 .if defined(BUILDING_WITH_KERNEL)
 CFLAGS+=       -I${BUILDING_WITH_KERNEL}
-CFLAGS+=       -I${BUILDING_WITH_KERNEL}/include
+_MACHINE_FWD=  ${BUILDING_WITH_KERNEL}
+.else
+.if defined(MAKEOBJDIRPREFIX)
+_MACHINE_FWD=  ${MAKEOBJDIRPREFIX}/${SYSDIR}/forwarder_${MACHINE_ARCH}
+.else
+_MACHINE_FWD=  ${.OBJDIR}/forwarder_${MACHINE_ARCH}
+CLEANDIRS+=    ${_MACHINE_FWD}
+.endif
 .endif
+CFLAGS+=       -I${_MACHINE_FWD}/include
+.include "kern.fwd.mk"
 
 # Add a -I path to standard headers like <stddef.h>.  Use a relative
 # path to src/include if possible.  If the @ symlink hasn't been built
@@ -163,7 +172,7 @@ all: objwarn ${PROG}
 all: _manpages
 .endif
 
-beforedepend: ${_ILINKS}
+beforedepend: ${_ILINKS} forwarding-headers
 # Ensure that the links exist without depending on it when it exists which
 # causes all the modules to be rebuilt when the directory pointed to changes.
 .for _link in ${_ILINKS}
index ba8947b..8796e1c 100644 (file)
@@ -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.19 2006/11/07 06:57:02 dillon Exp $
+ * $DragonFly: src/usr.sbin/config/main.c,v 1.20 2006/11/19 07:49:34 sephe Exp $
  */
 
 #include <sys/types.h>
@@ -70,7 +70,6 @@ int   profiling;
 
 static void configfile(void);
 static void get_srcdir(void);
-static void generate_forwarding_headers(void);
 static void usage(void);
 
 /*
@@ -212,15 +211,6 @@ main(int argc, char *argv[])
                    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
         * create the symlinks automatically XXX
@@ -496,71 +486,3 @@ 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 <cpu/%s>\n"
-                                   "#endif\n"
-                                   "\n",
-                                   upper,
-                                   upper,
-                                   den->d_name
-                       );
-                       fclose(fp);
-               }
-               closedir(dir);
-       }
-}
-