Module Name:    src
Committed By:   uebayasi
Date:           Thu Oct  9 17:00:15 UTC 2014

Modified Files:
        src/usr.bin/config: mkmakefile.c

Log Message:
Implement code to generate Makefile to build netbsd via intermediate relocatable
object files.  Disabled for now.  Commit this for further experiments.

Kernel (netbsd) has been built as:

        netbsd: *.o
                ld -o netbsd *.o

Change this to:

        netbsd: *.ko
                ld -o netbsd *.ko
        acpica.ko: ${OBJS.acpica}
                ld -r acpica.ko ${OBJS.acpica}
        :

You can call *.ko as a module, but this is not only beneficial for loadable
module, but also localize related text/data.  Various options/flags/params
will be able to be per-ko.  Unnecessary symbols can be hidden.  Many ideas
will follow.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/config/mkmakefile.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/config/mkmakefile.c
diff -u src/usr.bin/config/mkmakefile.c:1.17 src/usr.bin/config/mkmakefile.c:1.18
--- src/usr.bin/config/mkmakefile.c:1.17	Mon Aug 18 08:07:02 2014
+++ src/usr.bin/config/mkmakefile.c	Thu Oct  9 17:00:15 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: mkmakefile.c,v 1.17 2014/08/18 08:07:02 joerg Exp $	*/
+/*	$NetBSD: mkmakefile.c,v 1.18 2014/10/09 17:00:15 uebayasi Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -68,6 +68,11 @@ static void emitdefs(FILE *);
 static void emitfiles(FILE *, int, int);
 
 static void emitobjs(FILE *);
+static void emitallkobjs(FILE *);
+static int emitallkobjscb(const char *, void *, void *);
+static void emitattrkobjs(FILE *);
+static int emitattrkobjscb(const char *, void *, void *);
+static void emitkobjs(FILE *);
 static void emitcfiles(FILE *);
 static void emitsfiles(FILE *);
 static void emitrules(FILE *);
@@ -77,6 +82,9 @@ static void emitappmkoptions(FILE *);
 static void emitsubs(FILE *, const char *, const char *, int);
 static int  selectopt(const char *, void *);
 
+/* Generate Makefile to build things per-attribute *.ko (a.k.a modular build). */
+int usekobjs = 0;	/* XXX */
+
 int
 mkmakefile(void)
 {
@@ -120,7 +128,7 @@ mkmakefile(void)
 			continue;
 		}
 		if (strcmp(line, "%OBJS\n") == 0)
-			fn = emitobjs;
+			fn = usekobjs ? emitobjs : emitkobjs;
 		else if (strcmp(line, "%CFILES\n") == 0)
 			fn = emitcfiles;
 		else if (strcmp(line, "%SFILES\n") == 0)
@@ -372,6 +380,66 @@ emitobjs(FILE *fp)
 }
 
 static void
+emitkobjs(FILE *fp)
+{
+	emitallkobjs(fp);
+	emitattrkobjs(fp);
+}
+
+static void
+emitallkobjs(FILE *fp)
+{
+
+	fputs("OBJS=", fp);
+	ht_enumerate(attrtab, emitallkobjscb, fp);
+	putc('\n', fp);
+}
+
+static int
+emitallkobjscb(const char *name, void *v, void *arg)
+{
+	struct attr *a = v;
+	FILE *fp = arg;
+
+	if (ht_lookup(selecttab, name) == NULL)
+		return 0;
+	if (TAILQ_EMPTY(&a->a_files))
+		return 0;
+	fprintf(fp, " %s.ko", name);
+	return 0;
+}
+
+static void
+emitattrkobjs(FILE *fp)
+{
+	extern struct	hashtab *attrtab;
+
+	ht_enumerate(attrtab, emitattrkobjscb, fp);
+}
+
+static int
+emitattrkobjscb(const char *name, void *v, void *arg)
+{
+	struct attr *a = v;
+	struct files *fi;
+	FILE *fp = arg;
+
+	if (ht_lookup(selecttab, name) == NULL)
+		return 0;
+	if (TAILQ_EMPTY(&a->a_files))
+		return 0;
+	fputc('\n', fp);
+	fprintf(fp, "OBJS.%s=", name);
+	TAILQ_FOREACH(fi, &a->a_files, fi_anext) {
+		fprintf(fp, " %s.o", fi->fi_base);
+	}
+	fputc('\n', fp);
+	fprintf(fp, "%s.ko: ${OBJS.%s}\n", name, name);
+	fprintf(fp, "\t${LINK_O}\n");
+	return 0;
+}
+
+static void
 emitcfiles(FILE *fp)
 {
 

Reply via email to