Subject: Reworking minirot/ramdisk build tools
To: None <tech-install@netbsd.org>
From: Jonathan Stone <jonathan@DSG.Stanford.EDU>
List: tech-install
Date: 09/05/1999 00:58:31
Our setup for building miniroots and install-kernel ramdisk images
have gotten messy. Too much is duplicated: Multiple,
not-quite-consistent copies of runlist. No central place to list the
MI utilities which sysinst or the sh-script update/install require,
multiple list inputs, ...

I'd like to clean that up. Below are some (trivial) diffs to crunchgen
which let it read multiple .conf files. The idea is to break out
      1. stuff needed to boot: init, 
      2. a) MI stuff needed by install/upgrade scripts
         b) MD stuff needed by install/upgrade scripts
      3	 a) MI stuff needed by sysinst (or Perry's too)
         b) MD stuff needed by sysinst (or Perry's too)

and the same for the `list' run to populate the file.

This could be generalized to allow other configs for turnkey boot
floppies for "xterminal", "router" &c.

Anyway, here's the crunchgen diff. I've tested it by  breaking
out `tip' from the pmax ramdiskbin.conf  into a ramdiskbin.pmax.conf,
adding that to the ramdisk Makefile CRUNCHCONF. all goes OK.
Anyone care to review it before committing?


Index: crunchgen.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/crunch/crunchgen/crunchgen.c,v
retrieving revision 1.11
diff -w -u -r1.11 crunchgen.c
--- crunchgen.c	1999/06/21 05:57:10	1.11
+++ crunchgen.c	1999/09/05 07:52:50
@@ -81,7 +81,7 @@
 
 char line[MAXLINELEN];
 
-char confname[MAXPATHLEN], infilename[MAXPATHLEN];
+char confname[MAXPATHLEN], firstfilename[MAXPATHLEN];
 char outmkname[MAXPATHLEN], outcfname[MAXPATHLEN], execfname[MAXPATHLEN];
 char tempfname[MAXPATHLEN], cachename[MAXPATHLEN], curfilename[MAXPATHLEN];
 char topdir[MAXPATHLEN];
@@ -106,14 +106,13 @@
 /* helper routines for main() */
 
 void usage(void);			
-void parse_conf_file(void);
+void parse_conf_file(char*);
 void gen_outputs(void);
+void mkfilenames(char *);
 
-
 int main(int argc, char **argv)
 {
-    char *p;
-    int optc;
+    int optc, i;
     extern int optind;
     extern char *optarg;
 
@@ -145,18 +144,40 @@
     argc -= optind;
     argv += optind;
 
-    if(argc != 1) usage();
+    if(argc < 1) usage();
 
     /* 
      * generate filenames
      */
+    mkfilenames(argv[0]);
 
-    strcpy(infilename, argv[0]);
+    for (i=0; i < argc; i++) {
+    	parse_conf_file(argv[i]);
+    }
+    gen_outputs();
 
-    /* confname = `basename infilename .conf` */
+    exit(goterror);
+}
+
 
-    if((p=strrchr(infilename, '/')) != NULL) strcpy(confname, p+1);
-    else strcpy(confname, infilename);
+void usage(void)
+{
+    fprintf(stderr, 
+	"%s [-fq] [-m <makefile>] [-c <c file>] [-e <exec file>] <conffile>\n",
+	    pname);
+    exit(1);
+}
+
+void mkfilenames(char *fname)
+{
+    char *p;
+
+    strcpy(firstfilename, fname);
+
+    /* confname = `basename firstfilename .conf` */
+
+    if((p=strrchr(firstfilename, '/')) != NULL) strcpy(confname, p+1);
+    else strcpy(confname, firstfilename);
     if((p=strrchr(confname, '.')) != NULL && !strcmp(p, ".conf")) *p = '\0';
 
     if (!*outmkname)
@@ -169,22 +190,8 @@
     (void)snprintf(cachename, sizeof(cachename), "%s.cache", confname);
     (void)snprintf(tempfname, sizeof(tempfname), "/tmp/%sXXXXXX", confname);
 
-    parse_conf_file();
-    gen_outputs();
-
-    exit(goterror);
-}
-
-
-void usage(void)
-{
-    fprintf(stderr, 
-	"%s [-fq] [-m <makefile>] [-c <c file>] [-e <exec file>] <conffile>\n",
-	    pname);
-    exit(1);
 }
 
-
 /*
  * ========================================================================
  * parse_conf_file subsystem
@@ -205,14 +212,14 @@
 void add_prog(char *progname);
 
 
-void parse_conf_file(void)
+void parse_conf_file(char *filename)
 {
-    if(!is_nonempty_file(infilename)) {
+    if(!is_nonempty_file(filename)) {
 	fprintf(stderr, "%s: fatal: input file \"%s\" not found.\n",
-		pname, infilename);
+		pname, filename);
 	exit(1);
     }
-    parse_one_file(infilename);
+    parse_one_file(filename);
     if(readcache && is_nonempty_file(cachename)) {
 	reading_cache = 1;
 	parse_one_file(cachename);
@@ -533,15 +540,15 @@
 
     if(!p->srcdir && verbose)
 	fprintf(stderr, "%s: %s: warning: could not find source directory.\n",
-		infilename, p->name);
+		curfilename, p->name);
     if(!p->objs && verbose)
 	fprintf(stderr, "%s: %s: warning: could not find any .o files.\n", 
-		infilename, p->name);
+		curfilename, p->name);
 
     if(!p->objpaths) {
 	fprintf(stderr, 
 		"%s: %s: error: no objpaths specified or calculated.\n",
-		infilename, p->name);
+		curfilename, p->name);
 	p->goterror = goterror = 1;
     }
 }
@@ -618,7 +625,7 @@
 	else {
 	    /* delete it from linked list */
 	    fprintf(stderr, "%s: %s: ignoring program because of errors.\n",
-		    infilename, p2->name);
+		    curfilename, p2->name);
 	    if(p1) p1->next = p2->next;
 	    else progs = p2->next;
 	    p2 = p2->next;
@@ -641,7 +648,7 @@
     }
 
     fprintf(cachef, "# %s - parm cache generated from %s by crunchgen %s\n\n",
-	    cachename, infilename, CRUNCH_VERSION);
+	    cachename, firstfilename, CRUNCH_VERSION);
 
     for(p = progs; p != NULL; p = p->next) {
 	fprintf(cachef, "\n");
@@ -675,7 +682,7 @@
     }
 
     fprintf(outmk, "# %s - generated from %s by crunchgen %s\n\n",
-	    outmkname, infilename, CRUNCH_VERSION);
+	    outmkname, firstfilename, CRUNCH_VERSION);
 
     top_makefile_rules(outmk);
 
@@ -707,7 +714,7 @@
 
     fprintf(outcf, 
 	  "/* %s - generated from %s by crunchgen %s */\n",
-	    outcfname, infilename, CRUNCH_VERSION);
+	    outcfname, firstfilename, CRUNCH_VERSION);
 
     fprintf(outcf, "#define EXECNAME \"%s\"\n", execfname);
     for(cp = crunched_skel; *cp != NULL; cp++)
@@ -861,7 +868,8 @@
 
 void out_of_memory(void)
 {
-    fprintf(stderr, "%s: %d: out of memory, stopping.\n", infilename, linenum);
+    fprintf(stderr, "%s: %d: out of memory, stopping.\n",
+	    firstfilename, linenum);
     exit(1);
 }