date and time created 82/10/24 20:37:35 by root
[unix-history] / usr / src / usr.sbin / config / mkmakefile.c
index 5cec388..e2a1ca6 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * mkmakefile.c        1.8     81/04/03
+ * 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
@@ -77,6 +78,8 @@ 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);
     if (cputype == NULL) {
        printf("cpu type must be specified\n");
        exit(1);
@@ -84,11 +87,16 @@ makefile()
     for (cp = cputype; cp; cp = cp->cpu_next)
        fprintf(ofp, " -D%s", cp->cpu_name);
     for (op = opt; op; op = op->op_next)
     for (cp = cputype; cp; cp = cp->cpu_next)
        fprintf(ofp, " -D%s", cp->cpu_name);
     for (op = opt; op; op = op->op_next)
-         fprintf(ofp, " -D%s", op->op_name);
+         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");
@@ -108,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;
        }
@@ -138,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) {
@@ -152,7 +179,7 @@ read_files()
            continue;
        this = ns(wd);
        /*
            continue;
        this = ns(wd);
        /*
-        * Readad standard/optional
+        * Read standard/optional
         */
        next_word(fp, wd);
        if (wd == NULL)
         */
        next_word(fp, wd);
        if (wd == NULL)
@@ -165,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);
@@ -299,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;
     }
@@ -330,19 +393,19 @@ register FILE *f;
     {
        fprintf(f, "%s: makefile locore.o ${OBJS} ioconf.o param.o swap%s.o\n",
                fl->f_needs, fl->f_fn);
     {
        fprintf(f, "%s: makefile locore.o ${OBJS} ioconf.o param.o swap%s.o\n",
                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);
        if (first)
        {
                first = FALSE;
                fprintf(f, "\t@sh ../conf/newvers.sh\n");
                fl->f_needs, fl->f_needs);
        if (first)
        {
                first = FALSE;
                fprintf(f, "\t@sh ../conf/newvers.sh\n");
-               fprintf(f, "\t@cc $(COPTS) -c vers.c\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} vers.o 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@chmod 755 %s\n\n", fl->f_needs);
     }
        fprintf(f, "\t@size %s\n", fl->f_needs);
        fprintf(f, "\t@chmod 755 %s\n\n", fl->f_needs);
     }
@@ -351,7 +414,7 @@ register FILE *f;
        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, "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,
-           "\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);
        fprintf(f, "\trm -f swap%s.s\n\n", fl->f_fn);
     }
            fl->f_fn, fl->f_fn);
        fprintf(f, "\trm -f swap%s.s\n\n", fl->f_fn);
     }