Commit | Line | Data |
---|---|---|
cd68466f DF |
1 | /* |
2 | * Copyright (c) 1980 Regents of the University of California. | |
86f9c1e9 KB |
3 | * All rights reserved. |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
b8c620d6 KB |
6 | * provided that the above copyright notice and this paragraph are |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
cd68466f DF |
16 | */ |
17 | ||
18 | #ifndef lint | |
19 | char copyright[] = | |
20 | "@(#) Copyright (c) 1980 Regents of the University of California.\n\ | |
21 | All rights reserved.\n"; | |
86f9c1e9 | 22 | #endif /* not lint */ |
cd68466f | 23 | |
524aa063 | 24 | #ifndef lint |
b8c620d6 | 25 | static char sccsid[] = "@(#)main.c 5.9 (Berkeley) %G%"; |
86f9c1e9 | 26 | #endif /* not lint */ |
ca5d0476 | 27 | |
7633a3ca KB |
28 | #include <sys/types.h> |
29 | #include <sys/stat.h> | |
30 | #include <sys/file.h> | |
ca5d0476 MT |
31 | #include <stdio.h> |
32 | #include <ctype.h> | |
33 | #include "y.tab.h" | |
34 | #include "config.h" | |
35 | ||
7633a3ca KB |
36 | static char *PREFIX; |
37 | ||
9995ca8d BJ |
38 | /* |
39 | * Config builds a set of files for building a UNIX | |
40 | * system given a description of the desired system. | |
41 | */ | |
ca5d0476 | 42 | main(argc, argv) |
9995ca8d BJ |
43 | int argc; |
44 | char **argv; | |
ca5d0476 | 45 | { |
9995ca8d | 46 | |
7633a3ca KB |
47 | extern char *optarg; |
48 | extern int optind; | |
49 | struct stat buf; | |
50 | int ch; | |
51 | char *p; | |
52 | ||
53 | while ((ch = getopt(argc, argv, "p")) != EOF) | |
54 | switch((char)ch) { | |
55 | case 'p': | |
56 | profiling++; | |
57 | break; | |
58 | case '?': | |
59 | default: | |
60 | goto usage; | |
61 | } | |
62 | argc -= optind; | |
63 | argv += optind; | |
64 | ||
65 | if (argc != 1) { | |
66 | usage: fputs("usage: config [-p] sysname\n", stderr); | |
9995ca8d BJ |
67 | exit(1); |
68 | } | |
7633a3ca KB |
69 | |
70 | if (freopen(PREFIX = *argv, "r", stdin) == NULL) { | |
71 | perror(PREFIX); | |
9995ca8d BJ |
72 | exit(2); |
73 | } | |
7633a3ca KB |
74 | if (stat(p = path((char *)NULL), &buf)) { |
75 | if (mkdir(p, 0755)) { | |
76 | perror(p); | |
77 | exit(2); | |
78 | } | |
79 | } | |
80 | else if ((buf.st_mode & S_IFMT) != S_IFDIR) { | |
81 | fprintf(stderr, "config: %s isn't a directory.\n", p); | |
82 | exit(2); | |
83 | } | |
84 | ||
9995ca8d | 85 | dtab = NULL; |
36edb824 | 86 | confp = &conf_list; |
9995ca8d BJ |
87 | if (yyparse()) |
88 | exit(3); | |
89 | switch (machine) { | |
90 | ||
91 | case MACHINE_VAX: | |
92 | vax_ioconf(); /* Print ioconf.c */ | |
93 | ubglue(); /* Create ubglue.s */ | |
94 | break; | |
95 | ||
a0105456 SL |
96 | case MACHINE_TAHOE: |
97 | tahoe_ioconf(); | |
98 | vbglue(); | |
9995ca8d BJ |
99 | break; |
100 | ||
101 | default: | |
102 | printf("Specify machine type, e.g. ``machine vax''\n"); | |
103 | exit(1); | |
104 | } | |
11df43aa MK |
105 | /* |
106 | * make symbolic links in compilation directory | |
107 | * for "sys" (to make genassym.c work along with #include <sys/xxx>) | |
108 | * and similarly for "machine". | |
109 | */ | |
110 | { | |
111 | char xxx[80]; | |
112 | ||
7633a3ca | 113 | (void) symlink("../h", path("sys")); |
9bd38ba8 | 114 | (void) sprintf(xxx, "../%s", machinename); |
11df43aa MK |
115 | (void) symlink(xxx, path("machine")); |
116 | } | |
ca5d0476 MT |
117 | makefile(); /* build Makefile */ |
118 | headers(); /* make a lot of .h files */ | |
36edb824 | 119 | swapconf(); /* swap config files */ |
94e09492 | 120 | printf("Don't forget to run \"make depend\"\n"); |
70a77d13 | 121 | exit(0); |
ca5d0476 MT |
122 | } |
123 | ||
124 | /* | |
125 | * get_word | |
126 | * returns EOF on end of file | |
127 | * NULL on end of line | |
128 | * pointer to the word otherwise | |
129 | */ | |
9995ca8d BJ |
130 | char * |
131 | get_word(fp) | |
132 | register FILE *fp; | |
ca5d0476 | 133 | { |
9995ca8d BJ |
134 | static char line[80]; |
135 | register int ch; | |
136 | register char *cp; | |
ca5d0476 | 137 | |
9995ca8d BJ |
138 | while ((ch = getc(fp)) != EOF) |
139 | if (ch != ' ' && ch != '\t') | |
140 | break; | |
141 | if (ch == EOF) | |
22d68ad0 | 142 | return ((char *)EOF); |
9995ca8d BJ |
143 | if (ch == '\n') |
144 | return (NULL); | |
145 | cp = line; | |
ca5d0476 | 146 | *cp++ = ch; |
9995ca8d BJ |
147 | while ((ch = getc(fp)) != EOF) { |
148 | if (isspace(ch)) | |
149 | break; | |
150 | *cp++ = ch; | |
151 | } | |
152 | *cp = 0; | |
153 | if (ch == EOF) | |
22d68ad0 BJ |
154 | return ((char *)EOF); |
155 | (void) ungetc(ch, fp); | |
9995ca8d | 156 | return (line); |
ca5d0476 | 157 | } |
0a2de74e MT |
158 | |
159 | /* | |
9995ca8d | 160 | * prepend the path to a filename |
0a2de74e | 161 | */ |
22d68ad0 | 162 | char * |
0a2de74e | 163 | path(file) |
9995ca8d | 164 | char *file; |
0a2de74e | 165 | { |
9995ca8d | 166 | register char *cp; |
0a2de74e | 167 | |
22d68ad0 BJ |
168 | cp = malloc((unsigned)(strlen(PREFIX)+strlen(file)+5)); |
169 | (void) strcpy(cp, "../"); | |
170 | (void) strcat(cp, PREFIX); | |
7633a3ca KB |
171 | if (file) { |
172 | (void) strcat(cp, "/"); | |
173 | (void) strcat(cp, file); | |
174 | } | |
9995ca8d | 175 | return (cp); |
0a2de74e | 176 | } |