xref: /original-bsd/usr.sbin/config/main.c (revision a4d3ae46)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  */
6 
7 #ifndef lint
8 char copyright[] =
9 "@(#) Copyright (c) 1980 Regents of the University of California.\n\
10  All rights reserved.\n";
11 #endif not lint
12 
13 #ifndef lint
14 static char sccsid[] = "@(#)main.c	5.6 (Berkeley) 11/12/87";
15 #endif not lint
16 
17 #include <stdio.h>
18 #include <ctype.h>
19 #include "y.tab.h"
20 #include "config.h"
21 
22 /*
23  * Config builds a set of files for building a UNIX
24  * system given a description of the desired system.
25  */
26 main(argc, argv)
27 	int argc;
28 	char **argv;
29 {
30 
31 	if (argc > 1 && eq("-p", argv[1])) {
32 		profiling++;
33 		argc--, argv++;
34 	}
35 	if (argc != 2) {
36 		fprintf(stderr, "usage: config [ -p ] sysname\n");
37 		exit(1);
38 	}
39 	PREFIX = argv[1];
40 	if (freopen(argv[1], "r", stdin) == NULL) {
41 		perror(argv[1]);
42 		exit(2);
43 	}
44 	dtab = NULL;
45 	confp = &conf_list;
46 	if (yyparse())
47 		exit(3);
48 	switch (machine) {
49 
50 	case MACHINE_VAX:
51 		vax_ioconf();		/* Print ioconf.c */
52 		ubglue();		/* Create ubglue.s */
53 		break;
54 
55 	case MACHINE_TAHOE:
56 		tahoe_ioconf();
57 		vbglue();
58 		break;
59 
60 	default:
61 		printf("Specify machine type, e.g. ``machine vax''\n");
62 		exit(1);
63 	}
64 	/*
65 	 * make symbolic links in compilation directory
66 	 * for "sys" (to make genassym.c work along with #include <sys/xxx>)
67 	 * and similarly for "machine".
68 	 */
69 	{
70 	char xxx[80];
71 
72 	(void) symlink("../h", path("sys"));
73 	(void) sprintf(xxx, "../%s", machinename);
74 	(void) symlink(xxx, path("machine"));
75 	}
76 	makefile();			/* build Makefile */
77 	headers();			/* make a lot of .h files */
78 	swapconf();			/* swap config files */
79 	printf("Don't forget to run \"make depend\"\n");
80 	exit(0);
81 }
82 
83 /*
84  * get_word
85  *	returns EOF on end of file
86  *	NULL on end of line
87  *	pointer to the word otherwise
88  */
89 char *
90 get_word(fp)
91 	register FILE *fp;
92 {
93 	static char line[80];
94 	register int ch;
95 	register char *cp;
96 
97 	while ((ch = getc(fp)) != EOF)
98 		if (ch != ' ' && ch != '\t')
99 			break;
100 	if (ch == EOF)
101 		return ((char *)EOF);
102 	if (ch == '\n')
103 		return (NULL);
104 	cp = line;
105 	*cp++ = ch;
106 	while ((ch = getc(fp)) != EOF) {
107 		if (isspace(ch))
108 			break;
109 		*cp++ = ch;
110 	}
111 	*cp = 0;
112 	if (ch == EOF)
113 		return ((char *)EOF);
114 	(void) ungetc(ch, fp);
115 	return (line);
116 }
117 
118 /*
119  * prepend the path to a filename
120  */
121 char *
122 path(file)
123 	char *file;
124 {
125 	register char *cp;
126 
127 	cp = malloc((unsigned)(strlen(PREFIX)+strlen(file)+5));
128 	(void) strcpy(cp, "../");
129 	(void) strcat(cp, PREFIX);
130 	(void) strcat(cp, "/");
131 	(void) strcat(cp, file);
132 	return (cp);
133 }
134