xref: /csrg-svn/usr.sbin/config/main.c (revision 34131)
119987Sdist /*
219987Sdist  * Copyright (c) 1980 Regents of the University of California.
3*34131Sbostic  * All rights reserved.
4*34131Sbostic  *
5*34131Sbostic  * Redistribution and use in source and binary forms are permitted
6*34131Sbostic  * provided that this notice is preserved and that due credit is given
7*34131Sbostic  * to the University of California at Berkeley. The name of the University
8*34131Sbostic  * may not be used to endorse or promote products derived from this
9*34131Sbostic  * software without specific prior written permission. This software
10*34131Sbostic  * is provided ``as is'' without express or implied warranty.
1119987Sdist  */
1219987Sdist 
1314557Ssam #ifndef lint
1419987Sdist char copyright[] =
1519987Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\
1619987Sdist  All rights reserved.\n";
17*34131Sbostic #endif /* not lint */
182653Stoy 
1919987Sdist #ifndef lint
20*34131Sbostic static char sccsid[] = "@(#)main.c	5.8 (Berkeley) 04/29/88";
21*34131Sbostic #endif /* not lint */
2219987Sdist 
2334109Sbostic #include <sys/types.h>
2434109Sbostic #include <sys/stat.h>
2534109Sbostic #include <sys/file.h>
262653Stoy #include <stdio.h>
272653Stoy #include <ctype.h>
282653Stoy #include "y.tab.h"
292653Stoy #include "config.h"
302653Stoy 
3134109Sbostic static char *PREFIX;
3234109Sbostic 
338892Sroot /*
348892Sroot  * Config builds a set of files for building a UNIX
358892Sroot  * system given a description of the desired system.
368892Sroot  */
372653Stoy main(argc, argv)
388892Sroot 	int argc;
398892Sroot 	char **argv;
402653Stoy {
418892Sroot 
4234109Sbostic 	extern char *optarg;
4334109Sbostic 	extern int optind;
4434109Sbostic 	struct stat buf;
4534109Sbostic 	int ch;
4634109Sbostic 	char *p;
4734109Sbostic 
4834109Sbostic 	while ((ch = getopt(argc, argv, "p")) != EOF)
4934109Sbostic 		switch((char)ch) {
5034109Sbostic 		case 'p':
5134109Sbostic 			profiling++;
5234109Sbostic 			break;
5334109Sbostic 		case '?':
5434109Sbostic 		default:
5534109Sbostic 			goto usage;
5634109Sbostic 		}
5734109Sbostic 	argc -= optind;
5834109Sbostic 	argv += optind;
5934109Sbostic 
6034109Sbostic 	if (argc != 1) {
6134109Sbostic usage:		fputs("usage: config [-p] sysname\n", stderr);
628892Sroot 		exit(1);
638892Sroot 	}
6434109Sbostic 
6534109Sbostic 	if (freopen(PREFIX = *argv, "r", stdin) == NULL) {
6634109Sbostic 		perror(PREFIX);
678892Sroot 		exit(2);
688892Sroot 	}
6934109Sbostic 	if (stat(p = path((char *)NULL), &buf)) {
7034109Sbostic 		if (mkdir(p, 0755)) {
7134109Sbostic 			perror(p);
7234109Sbostic 			exit(2);
7334109Sbostic 		}
7434109Sbostic 	}
7534109Sbostic 	else if ((buf.st_mode & S_IFMT) != S_IFDIR) {
7634109Sbostic 		fprintf(stderr, "config: %s isn't a directory.\n", p);
7734109Sbostic 		exit(2);
7834109Sbostic 	}
7934109Sbostic 
808892Sroot 	dtab = NULL;
8112487Ssam 	confp = &conf_list;
828892Sroot 	if (yyparse())
838892Sroot 		exit(3);
848892Sroot 	switch (machine) {
858892Sroot 
868892Sroot 	case MACHINE_VAX:
878892Sroot 		vax_ioconf();		/* Print ioconf.c */
888892Sroot 		ubglue();		/* Create ubglue.s */
898892Sroot 		break;
908892Sroot 
9129841Ssam 	case MACHINE_TAHOE:
9229841Ssam 		tahoe_ioconf();
9329841Ssam 		vbglue();
948892Sroot 		break;
958892Sroot 
968892Sroot 	default:
978892Sroot 		printf("Specify machine type, e.g. ``machine vax''\n");
988892Sroot 		exit(1);
998892Sroot 	}
10030379Skarels 	/*
10130379Skarels 	 * make symbolic links in compilation directory
10230379Skarels 	 * for "sys" (to make genassym.c work along with #include <sys/xxx>)
10330379Skarels 	 * and similarly for "machine".
10430379Skarels 	 */
10530379Skarels 	{
10630379Skarels 	char xxx[80];
10730379Skarels 
10834109Sbostic 	(void) symlink("../h", path("sys"));
10932458Sbostic 	(void) sprintf(xxx, "../%s", machinename);
11030379Skarels 	(void) symlink(xxx, path("machine"));
11130379Skarels 	}
1122653Stoy 	makefile();			/* build Makefile */
1132653Stoy 	headers();			/* make a lot of .h files */
11412487Ssam 	swapconf();			/* swap config files */
1153156Stoy 	printf("Don't forget to run \"make depend\"\n");
11632605Sbostic 	exit(0);
1172653Stoy }
1182653Stoy 
1192653Stoy /*
1202653Stoy  * get_word
1212653Stoy  *	returns EOF on end of file
1222653Stoy  *	NULL on end of line
1232653Stoy  *	pointer to the word otherwise
1242653Stoy  */
1258892Sroot char *
1268892Sroot get_word(fp)
1278892Sroot 	register FILE *fp;
1282653Stoy {
1298892Sroot 	static char line[80];
1308892Sroot 	register int ch;
1318892Sroot 	register char *cp;
1322653Stoy 
1338892Sroot 	while ((ch = getc(fp)) != EOF)
1348892Sroot 		if (ch != ' ' && ch != '\t')
1358892Sroot 			break;
1368892Sroot 	if (ch == EOF)
1378900Sroot 		return ((char *)EOF);
1388892Sroot 	if (ch == '\n')
1398892Sroot 		return (NULL);
1408892Sroot 	cp = line;
1412653Stoy 	*cp++ = ch;
1428892Sroot 	while ((ch = getc(fp)) != EOF) {
1438892Sroot 		if (isspace(ch))
1448892Sroot 			break;
1458892Sroot 		*cp++ = ch;
1468892Sroot 	}
1478892Sroot 	*cp = 0;
1488892Sroot 	if (ch == EOF)
1498900Sroot 		return ((char *)EOF);
1508900Sroot 	(void) ungetc(ch, fp);
1518892Sroot 	return (line);
1522653Stoy }
1532682Stoy 
1542682Stoy /*
1558892Sroot  * prepend the path to a filename
1562682Stoy  */
1578900Sroot char *
1582682Stoy path(file)
1598892Sroot 	char *file;
1602682Stoy {
1618892Sroot 	register char *cp;
1622682Stoy 
1638900Sroot 	cp = malloc((unsigned)(strlen(PREFIX)+strlen(file)+5));
1648900Sroot 	(void) strcpy(cp, "../");
1658900Sroot 	(void) strcat(cp, PREFIX);
16634109Sbostic 	if (file) {
16734109Sbostic 		(void) strcat(cp, "/");
16834109Sbostic 		(void) strcat(cp, file);
16934109Sbostic 	}
1708892Sroot 	return (cp);
1712682Stoy }
172