install correct aliases file
[unix-history] / usr / src / usr.sbin / config / main.c
index d0760fa..be2966f 100644 (file)
@@ -1,24 +1,40 @@
 /*
  * Copyright (c) 1980 Regents of the University of California.
 /*
  * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #ifndef lint
 char copyright[] =
 "@(#) Copyright (c) 1980 Regents of the University of California.\n\
  All rights reserved.\n";
  */
 
 #ifndef lint
 char copyright[] =
 "@(#) Copyright (c) 1980 Regents of the University of California.\n\
  All rights reserved.\n";
-#endif not lint
+#endif /* not lint */
 
 #ifndef lint
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.2 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)main.c     5.9 (Berkeley) %G%";
+#endif /* not lint */
 
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/file.h>
 #include <stdio.h>
 #include <ctype.h>
 #include "y.tab.h"
 #include "config.h"
 
 #include <stdio.h>
 #include <ctype.h>
 #include "y.tab.h"
 #include "config.h"
 
+static char *PREFIX;
+
 /*
  * Config builds a set of files for building a UNIX
  * system given a description of the desired system.
 /*
  * Config builds a set of files for building a UNIX
  * system given a description of the desired system.
@@ -28,19 +44,44 @@ main(argc, argv)
        char **argv;
 {
 
        char **argv;
 {
 
-       if (argc > 1 && eq("-p", argv[1])) {
-               profiling++;
-               argc--, argv++;
-       }
-       if (argc != 2) {
-               fprintf(stderr, "usage: config [ -p ] sysname\n");
+       extern char *optarg;
+       extern int optind;
+       struct stat buf;
+       int ch;
+       char *p;
+
+       while ((ch = getopt(argc, argv, "p")) != EOF)
+               switch((char)ch) {
+               case 'p':
+                       profiling++;
+                       break;
+               case '?':
+               default:
+                       goto usage;
+               }
+       argc -= optind;
+       argv += optind;
+
+       if (argc != 1) {
+usage:         fputs("usage: config [-p] sysname\n", stderr);
                exit(1);
        }
                exit(1);
        }
-       PREFIX = argv[1];
-       if (freopen(argv[1], "r", stdin) == NULL) {
-               perror(argv[1]);
+
+       if (freopen(PREFIX = *argv, "r", stdin) == NULL) {
+               perror(PREFIX);
                exit(2);
        }
                exit(2);
        }
+       if (stat(p = path((char *)NULL), &buf)) {
+               if (mkdir(p, 0755)) {
+                       perror(p);
+                       exit(2);
+               }
+       }
+       else if ((buf.st_mode & S_IFMT) != S_IFDIR) {
+               fprintf(stderr, "config: %s isn't a directory.\n", p);
+               exit(2);
+       }
+
        dtab = NULL;
        confp = &conf_list;
        if (yyparse())
        dtab = NULL;
        confp = &conf_list;
        if (yyparse())
@@ -52,19 +93,32 @@ main(argc, argv)
                ubglue();               /* Create ubglue.s */
                break;
 
                ubglue();               /* Create ubglue.s */
                break;
 
-       case MACHINE_SUN:
-               sun_ioconf();
+       case MACHINE_TAHOE:
+               tahoe_ioconf();
+               vbglue();
                break;
 
        default:
                printf("Specify machine type, e.g. ``machine vax''\n");
                exit(1);
        }
                break;
 
        default:
                printf("Specify machine type, e.g. ``machine vax''\n");
                exit(1);
        }
-       symlink("../h", path("sys"));   /* make genassym.c work */
+       /*
+        * make symbolic links in compilation directory
+        * for "sys" (to make genassym.c work along with #include <sys/xxx>)
+        * and similarly for "machine".
+        */
+       {
+       char xxx[80];
+
+       (void) symlink("../h", path("sys"));
+       (void) sprintf(xxx, "../%s", machinename);
+       (void) symlink(xxx, path("machine"));
+       }
        makefile();                     /* build Makefile */
        headers();                      /* make a lot of .h files */
        swapconf();                     /* swap config files */
        printf("Don't forget to run \"make depend\"\n");
        makefile();                     /* build Makefile */
        headers();                      /* make a lot of .h files */
        swapconf();                     /* swap config files */
        printf("Don't forget to run \"make depend\"\n");
+       exit(0);
 }
 
 /*
 }
 
 /*
@@ -114,7 +168,9 @@ path(file)
        cp = malloc((unsigned)(strlen(PREFIX)+strlen(file)+5));
        (void) strcpy(cp, "../");
        (void) strcat(cp, PREFIX);
        cp = malloc((unsigned)(strlen(PREFIX)+strlen(file)+5));
        (void) strcpy(cp, "../");
        (void) strcat(cp, PREFIX);
-       (void) strcat(cp, "/");
-       (void) strcat(cp, file);
+       if (file) {
+               (void) strcat(cp, "/");
+               (void) strcat(cp, file);
+       }
        return (cp);
 }
        return (cp);
 }