date and time created 82/10/24 20:37:35 by root
[unix-history] / usr / src / usr.sbin / config / mkmakefile.c
index 462f4ea..e2a1ca6 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * mkmakefile.c        1.4     81/03/06
+ * mkmakefile.c        1.17    82/10/11
  *     Functions in this file build the makefile from the files list
  *     and the information in the config table
  */
  *     Functions in this file build the makefile from the files list
  *     and the information in the config table
  */
@@ -53,6 +53,7 @@ struct file_list *new_fent()
     return fp;
 }
 
     return fp;
 }
 
+char   *COPTS;                 /* pointer to ${COPTS} macro for gprof */
 /*
  * makefile:
  *     Build the makefile from the skeleton
 /*
  * makefile:
  *     Build the makefile from the skeleton
@@ -63,6 +64,7 @@ makefile()
     FILE *ifp, *ofp;
     char line[BUFSIZ];
     struct cputype *cp;
     FILE *ifp, *ofp;
     char line[BUFSIZ];
     struct cputype *cp;
+    struct opt *op;
 
     read_files();                      /* Read in the "files" file */
     ifp = fopen("../conf/makefile", "r");
 
     read_files();                      /* Read in the "files" file */
     ifp = fopen("../conf/makefile", "r");
@@ -76,16 +78,25 @@ makefile()
        exit(1);
     }
     fprintf(ofp, "IDENT=-D%s", raise(ident));
        exit(1);
     }
     fprintf(ofp, "IDENT=-D%s", raise(ident));
+    if (profiling)
+       fprintf(ofp, " -DGPROF");
     if (cputype == NULL) {
        printf("cpu type must be specified\n");
        exit(1);
     }
     for (cp = cputype; cp; cp = cp->cpu_next)
        fprintf(ofp, " -D%s", cp->cpu_name);
     if (cputype == NULL) {
        printf("cpu type must be specified\n");
        exit(1);
     }
     for (cp = cputype; cp; cp = cp->cpu_next)
        fprintf(ofp, " -D%s", cp->cpu_name);
+    for (op = opt; op; op = op->op_next)
+         if (op->op_value)
+               fprintf(ofp, " -D%s=\"%s\"", op->op_name, op->op_value);
+         else
+               fprintf(ofp, " -D%s", op->op_name);
     fprintf(ofp, "\n");
     if (hz == 0) {
     fprintf(ofp, "\n");
     if (hz == 0) {
+#ifdef notdef
        printf("hz not specified; 50hz assumed\n");
        printf("hz not specified; 50hz assumed\n");
-       hz = 50;
+#endif
+       hz = 60;
     }
     if (hadtz == 0)
        printf("timezone not specified; gmt assumed\n");
     }
     if (hadtz == 0)
        printf("timezone not specified; gmt assumed\n");
@@ -95,8 +106,8 @@ makefile()
     } else if (maxusers < 8) {
        printf("minimum of 8 maxusers assumed\n");
        maxusers = 8;
     } else if (maxusers < 8) {
        printf("minimum of 8 maxusers assumed\n");
        maxusers = 8;
-    } else if (maxusers > 100) {
-       printf("maxusers truncated to 100\n");
+    } else if (maxusers > 128) {
+       printf("maxusers truncated to 128\n");
        maxusers = 128;
     }
     fprintf(ofp, "PARAM=-DHZ=%d -DTIMEZONE=%d -DDST=%d -DMAXUSERS=%d\n",
        maxusers = 128;
     }
     fprintf(ofp, "PARAM=-DHZ=%d -DTIMEZONE=%d -DDST=%d -DMAXUSERS=%d\n",
@@ -105,6 +116,25 @@ makefile()
     {
        if (*line != '%')
        {
     {
        if (*line != '%')
        {
+           register char *cp;
+
+           if (profiling && strncmp(line, "COPTS=", 6) == 0) {
+               fprintf(ofp, "CRT0.EX=/usr/src/libc/csu/crt0.ex\n");
+               cp = index(line, '\n');
+               if (cp)
+                       *cp = '\0';
+               cp = line + 6;
+               while (*cp && (*cp == ' ' || *cp == '\t'))
+                       cp++;
+               COPTS = malloc(strlen(cp) + 1);
+               if (COPTS == 0) {
+                       fprintf(stderr, "config: out of memory\n");
+                       exit(1);
+               }
+               strcpy(COPTS, cp);
+               fprintf(ofp, "%s -pg\n", line);
+               continue;
+           }
            fprintf(ofp, "%s", line);
            continue;
        }
            fprintf(ofp, "%s", line);
            continue;
        }
@@ -135,7 +165,7 @@ read_files()
     register struct file_list *tp;
     register struct device *dp;
     register char *wd, *this;
     register struct file_list *tp;
     register struct device *dp;
     register char *wd, *this;
-    int type;
+    int type, nreqs, dev;
 
     fp = fopen("../conf/files", "r");
     if (fp == NULL) {
 
     fp = fopen("../conf/files", "r");
     if (fp == NULL) {
@@ -162,29 +192,50 @@ read_files()
        else
            free(tp->f_fn);
        tp->f_fn = this;
        else
            free(tp->f_fn);
        tp->f_fn = this;
-       type = 0;
+       nreqs = dev = type = 0;
        if (eq(wd, "optional"))
        {
        if (eq(wd, "optional"))
        {
-           next_word(fp, wd);
-           if (wd == NULL)
+           for (;;) 
            {
            {
-               fprintf(stderr, "Needed a dev for optional(%s)\n", this);
-               exit(11);
-           }
-           tp->f_needs = ns(wd);
-           for (dp = dtab ; dp != NULL; dp = dp->d_next)
-           {
-               if (eq(dp->d_name, wd))
+               next_word(fp, wd);
+               if (wd == NULL || (dev = eq(wd, "device-driver")))
+               {
+                   if (nreqs == 0)
+                   {
+                       fprintf(stderr, "Needed a dev for optional(%s)\n",
+                               this);
+                       exit(11);
+                   }
+                   else
+                       break;
+               }
+               nreqs++;
+               if (tp->f_needs == NULL)
+                       tp->f_needs = ns(wd);
+               for (dp = dtab ; dp != NULL; dp = dp->d_next)
+               {
+                   if (eq(dp->d_name, wd))
+                       break;
+               }
+               if (dp == NULL)
+               {
+                   type = INVISIBLE;
+                   while ((wd = get_word(fp)) != NULL)
+                       ;
                    break;
                    break;
+               }
            }
            }
-           if (dp == NULL)
-               type = INVISIBLE;
        }
        }
-       next_word(fp, wd);
-       if (type == 0 && wd != NULL)
-           type = DEVICE;
-       else if (type == 0)
-           type = NORMAL;
+       if (dev == 0 && wd != NULL)
+       {
+           next_word(fp, wd);
+           if (wd != NULL && eq(wd, "profiling-routine"))
+               type = PROFILING;
+           else
+               dev = (wd != NULL && eq(wd, "device-driver"));
+       }
+       if (type == 0)
+           type = dev ? DEVICE : NORMAL;
        tp->f_type = type;
     }
     fclose(fp);
        tp->f_type = type;
     }
     fclose(fp);
@@ -201,6 +252,7 @@ FILE *fp;
     register struct file_list *tp;
     register int lpos, len;
     register char *cp, och, *sp;
     register struct file_list *tp;
     register int lpos, len;
     register char *cp, och, *sp;
+    char *tail();
 
     fprintf(fp, "OBJS=");
     lpos = 6;
 
     fprintf(fp, "OBJS=");
     lpos = 6;
@@ -208,7 +260,7 @@ FILE *fp;
     {
        if (tp->f_type == INVISIBLE)
            continue;
     {
        if (tp->f_type == INVISIBLE)
            continue;
-       sp = rindex(tp->f_fn, '/') + 1;
+       sp = tail(tp->f_fn);
        cp = sp + (len = strlen(sp)) - 1;
        och = *cp;
        *cp = 'o';
        cp = sp + (len = strlen(sp)) - 1;
        och = *cp;
        *cp = 'o';
@@ -242,6 +294,8 @@ FILE *fp;
     {
        if (tp->f_type == INVISIBLE)
            continue;
     {
        if (tp->f_type == INVISIBLE)
            continue;
+       if (tp->f_fn[strlen(tp->f_fn)-1] != 'c')
+           continue;
        if ((len = 3 + strlen(tp->f_fn)) + lpos > 72)
        {
            lpos = 8;
        if ((len = 3 + strlen(tp->f_fn)) + lpos > 72)
        {
            lpos = 8;
@@ -293,18 +347,33 @@ FILE *f;
        else if (ftp->f_type == NORMAL)
        {
            fprintf(f, "\t${CC} -I. -c -S ${COPTS} ../%sc\n", np);
        else if (ftp->f_type == NORMAL)
        {
            fprintf(f, "\t${CC} -I. -c -S ${COPTS} ../%sc\n", np);
-           fprintf(f, "\t${C2} %ss | sed -f ../sys/asm.sed | ${AS} -o %so\n",
+           fprintf(f, "\t${C2} %ss | sed -f ../conf/asm.sed | ${AS} -o %so\n",
                    tp, tp);
            fprintf(f, "\trm -f %ss\n\n", tp);
        }
        else if (ftp->f_type == DEVICE)
        {
            fprintf(f, "\t${CC} -I. -c -S ${COPTS} ../%sc\n", np);
                    tp, tp);
            fprintf(f, "\trm -f %ss\n\n", tp);
        }
        else if (ftp->f_type == DEVICE)
        {
            fprintf(f, "\t${CC} -I. -c -S ${COPTS} ../%sc\n", np);
-           fprintf(f,"\t${C2} -i %ss | sed -f ../sys/asm.sed | ${AS} -o %so\n",
+           fprintf(f,"\t${C2} -i %ss | sed -f ../conf/asm.sed | ${AS} -o %so\n",
                    tp, tp);
            fprintf(f, "\trm -f %ss\n\n", tp);
        }
                    tp, tp);
            fprintf(f, "\trm -f %ss\n\n", tp);
        }
-       else
+       else if (ftp->f_type == PROFILING) {
+               if (!profiling)
+                       continue;
+               if (COPTS == 0) {
+                       fprintf(stderr,
+                               "config: COPTS undefined in generic makefile");
+                       COPTS = "";
+               }
+               fprintf(f,
+                 "\t${CC} -I. -c -S %s ../%sc\n", COPTS, np);
+               fprintf(f, "\tex - %ss < ${CRT0.EX}\n", tp);
+               fprintf(f,
+                 "\t/lib/cpp %ss | sed -f ../conf/asm.sed | ${AS} -o %so\n",
+                       tp, tp);
+               fprintf(f, "\trm -f %ss\n\n", tp);
+       } else
            fprintf(stderr, "Don't know rules for %s", np);
        *cp = och;
     }
            fprintf(stderr, "Don't know rules for %s", np);
        *cp = och;
     }
@@ -318,34 +387,41 @@ do_load(f)
 register FILE *f;
 {
     register struct file_list *fl;
 register FILE *f;
 {
     register struct file_list *fl;
+    register bool first = TRUE;
 
 
-    fprintf(f, "all:");
-    for (fl = conf_list; fl != NULL; fl = fl->f_next)
-       fprintf(f, " %s", fl->f_needs);
-    putc('\n', f);
     for (fl = conf_list; fl != NULL; fl = fl->f_next)
     {
     for (fl = conf_list; fl != NULL; fl = fl->f_next)
     {
-       fprintf(f, "\n%s: makefile locore.o ${OBJS} ioconf.o param.o swap%s.o\n",
+       fprintf(f, "%s: makefile locore.o ${OBJS} ioconf.o param.o swap%s.o\n",
                fl->f_needs, fl->f_fn);
                fl->f_needs, fl->f_fn);
-       fprintf(f, "\t@echo loading %s\n\t@rm -f %s\n\t",
+       fprintf(f, "\t@echo loading %s\n\t@rm -f %s\n",
                fl->f_needs, fl->f_needs);
                fl->f_needs, fl->f_needs);
+       if (first)
+       {
+               first = FALSE;
+               fprintf(f, "\t@sh ../conf/newvers.sh\n");
+               fprintf(f, "\t@cc $(CFLAGS) -c vers.c\n");
+       }
        fprintf(f,
        fprintf(f,
-           "@ld -n -o %s -e start -x -T 80000000 locore.o ${OBJS} ioconf.o param.o swap%s.o\n",
+           "\t@ld -n -o %s -e start -x -T 80000000 locore.o ${OBJS} vers.o ioconf.o param.o swap%s.o\n",
            fl->f_needs, fl->f_fn);
        fprintf(f, "\t@echo rearranging symbols\n");
            fl->f_needs, fl->f_fn);
        fprintf(f, "\t@echo rearranging symbols\n");
-       fprintf(f, "\t@-symorder ../sys/symbols.sort %s\n", fl->f_needs);
+       fprintf(f, "\t@-symorder ../conf/symbols.sort %s\n", fl->f_needs);
        fprintf(f, "\t@size %s\n", fl->f_needs);
        fprintf(f, "\t@size %s\n", fl->f_needs);
-       fprintf(f, "\t@chmod 755 %s\n", fl->f_needs);
+       fprintf(f, "\t@chmod 755 %s\n\n", fl->f_needs);
     }
     for (fl = conf_list; fl != NULL; fl = fl->f_next)
     {
     }
     for (fl = conf_list; fl != NULL; fl = fl->f_next)
     {
-       fprintf(f, "\nswap%s.o: ../dev/swap%s.c\n", fl->f_fn, fl->f_fn);
+       fprintf(f, "swap%s.o: ../dev/swap%s.c\n", fl->f_fn, fl->f_fn);
        fprintf(f, "\t${CC} -I. -c -S ${COPTS} ../dev/swap%s.c\n", fl->f_fn);
        fprintf(f,
        fprintf(f, "\t${CC} -I. -c -S ${COPTS} ../dev/swap%s.c\n", fl->f_fn);
        fprintf(f,
-           "\t${C2} swap%s.s | sed -f ../sys/asm.sed | ${AS} -o swap%s.o\n",
+           "\t${C2} swap%s.s | sed -f ../conf/asm.sed | ${AS} -o swap%s.o\n",
            fl->f_fn, fl->f_fn);
            fl->f_fn, fl->f_fn);
-       fprintf(f, "\trm -f swap%s.s\n", fl->f_fn);
+       fprintf(f, "\trm -f swap%s.s\n\n", fl->f_fn);
     }
     }
+    fprintf(f, "all:");
+    for (fl = conf_list; fl != NULL; fl = fl->f_next)
+       fprintf(f, " %s", fl->f_needs);
+    putc('\n', f);
 }
 
 raise(str)
 }
 
 raise(str)