xref: /csrg-svn/usr.sbin/config/main.c (revision 61816)
119987Sdist /*
2*61816Sbostic  * Copyright (c) 1980, 1993
3*61816Sbostic  *	The Regents of the University of California.  All rights reserved.
434131Sbostic  *
542795Sbostic  * %sccs.include.redist.c%
619987Sdist  */
719987Sdist 
814557Ssam #ifndef lint
9*61816Sbostic static char copyright[] =
10*61816Sbostic "@(#) Copyright (c) 1980, 1993\n\
11*61816Sbostic 	The Regents of the University of California.  All rights reserved.\n";
1234131Sbostic #endif /* not lint */
132653Stoy 
1419987Sdist #ifndef lint
15*61816Sbostic static char sccsid[] = "@(#)main.c	8.1 (Berkeley) 06/06/93";
1634131Sbostic #endif /* not lint */
1719987Sdist 
1834109Sbostic #include <sys/types.h>
1934109Sbostic #include <sys/stat.h>
2034109Sbostic #include <sys/file.h>
212653Stoy #include <stdio.h>
222653Stoy #include <ctype.h>
232653Stoy #include "y.tab.h"
242653Stoy #include "config.h"
252653Stoy 
2634109Sbostic static char *PREFIX;
2734109Sbostic 
288892Sroot /*
298892Sroot  * Config builds a set of files for building a UNIX
308892Sroot  * system given a description of the desired system.
318892Sroot  */
main(argc,argv)322653Stoy main(argc, argv)
338892Sroot 	int argc;
348892Sroot 	char **argv;
352653Stoy {
368892Sroot 
3734109Sbostic 	extern char *optarg;
3834109Sbostic 	extern int optind;
3934109Sbostic 	struct stat buf;
4034109Sbostic 	int ch;
4134109Sbostic 	char *p;
4234109Sbostic 
4342110Smckusick 	while ((ch = getopt(argc, argv, "gp")) != EOF)
4450348Skarels 		switch (ch) {
4542110Smckusick 		case 'g':
4642110Smckusick 			debugging++;
4742110Smckusick 			break;
4834109Sbostic 		case 'p':
4934109Sbostic 			profiling++;
5034109Sbostic 			break;
5134109Sbostic 		case '?':
5234109Sbostic 		default:
5334109Sbostic 			goto usage;
5434109Sbostic 		}
5534109Sbostic 	argc -= optind;
5634109Sbostic 	argv += optind;
5734109Sbostic 
5834109Sbostic 	if (argc != 1) {
5942110Smckusick usage:		fputs("usage: config [-gp] sysname\n", stderr);
608892Sroot 		exit(1);
618892Sroot 	}
6234109Sbostic 
6334109Sbostic 	if (freopen(PREFIX = *argv, "r", stdin) == NULL) {
6434109Sbostic 		perror(PREFIX);
658892Sroot 		exit(2);
668892Sroot 	}
6734109Sbostic 	if (stat(p = path((char *)NULL), &buf)) {
6842110Smckusick 		if (mkdir(p, 0777)) {
6934109Sbostic 			perror(p);
7034109Sbostic 			exit(2);
7134109Sbostic 		}
7234109Sbostic 	}
7334109Sbostic 	else if ((buf.st_mode & S_IFMT) != S_IFDIR) {
7434109Sbostic 		fprintf(stderr, "config: %s isn't a directory.\n", p);
7534109Sbostic 		exit(2);
7634109Sbostic 	}
7734109Sbostic 
788892Sroot 	dtab = NULL;
7912487Ssam 	confp = &conf_list;
8059855Shibler 	compp = &comp_list;
818892Sroot 	if (yyparse())
828892Sroot 		exit(3);
838892Sroot 	switch (machine) {
848892Sroot 
858892Sroot 	case MACHINE_VAX:
868892Sroot 		vax_ioconf();		/* Print ioconf.c */
878892Sroot 		ubglue();		/* Create ubglue.s */
888892Sroot 		break;
898892Sroot 
9029841Ssam 	case MACHINE_TAHOE:
9129841Ssam 		tahoe_ioconf();
9229841Ssam 		vbglue();
938892Sroot 		break;
948892Sroot 
9542110Smckusick 	case MACHINE_HP300:
9654093Smckusick 	case MACHINE_LUNA68K:
9742110Smckusick 		hp300_ioconf();
9842110Smckusick 		hpglue();
9942110Smckusick 		break;
10042110Smckusick 
10145952Swilliam 	case MACHINE_I386:
10245952Swilliam 		i386_ioconf();		/* Print ioconf.c */
10345952Swilliam 		vector();		/* Create vector.s */
10445952Swilliam 		break;
10545952Swilliam 
10651037Sralph 	case MACHINE_MIPS:
10751037Sralph 	case MACHINE_PMAX:
10851037Sralph 		pmax_ioconf();
10951037Sralph 		break;
11051037Sralph 
11155795Smckusick 	case MACHINE_NEWS3400:
11255795Smckusick 		news_ioconf();
11355795Smckusick 		break;
11455795Smckusick 
1158892Sroot 	default:
1168892Sroot 		printf("Specify machine type, e.g. ``machine vax''\n");
1178892Sroot 		exit(1);
1188892Sroot 	}
11930379Skarels 	/*
12030379Skarels 	 * make symbolic links in compilation directory
12130379Skarels 	 * for "sys" (to make genassym.c work along with #include <sys/xxx>)
12230379Skarels 	 * and similarly for "machine".
12330379Skarels 	 */
12430379Skarels 	{
12530379Skarels 	char xxx[80];
12630379Skarels 
12745888Sbostic 	(void) sprintf(xxx, "../../%s/include", machinename);
12830379Skarels 	(void) symlink(xxx, path("machine"));
12930379Skarels 	}
1302653Stoy 	makefile();			/* build Makefile */
1312653Stoy 	headers();			/* make a lot of .h files */
13212487Ssam 	swapconf();			/* swap config files */
1333156Stoy 	printf("Don't forget to run \"make depend\"\n");
13432605Sbostic 	exit(0);
1352653Stoy }
1362653Stoy 
1372653Stoy /*
1382653Stoy  * get_word
1392653Stoy  *	returns EOF on end of file
1402653Stoy  *	NULL on end of line
1412653Stoy  *	pointer to the word otherwise
1422653Stoy  */
1438892Sroot char *
get_word(fp)1448892Sroot get_word(fp)
1458892Sroot 	register FILE *fp;
1462653Stoy {
1478892Sroot 	static char line[80];
1488892Sroot 	register int ch;
1498892Sroot 	register char *cp;
1502653Stoy 
1518892Sroot 	while ((ch = getc(fp)) != EOF)
1528892Sroot 		if (ch != ' ' && ch != '\t')
1538892Sroot 			break;
1548892Sroot 	if (ch == EOF)
1558900Sroot 		return ((char *)EOF);
1568892Sroot 	if (ch == '\n')
1578892Sroot 		return (NULL);
1588892Sroot 	cp = line;
1592653Stoy 	*cp++ = ch;
1608892Sroot 	while ((ch = getc(fp)) != EOF) {
1618892Sroot 		if (isspace(ch))
1628892Sroot 			break;
1638892Sroot 		*cp++ = ch;
1648892Sroot 	}
1658892Sroot 	*cp = 0;
1668892Sroot 	if (ch == EOF)
1678900Sroot 		return ((char *)EOF);
1688900Sroot 	(void) ungetc(ch, fp);
1698892Sroot 	return (line);
1702653Stoy }
1712682Stoy 
1722682Stoy /*
17350348Skarels  * get_quoted_word
17450348Skarels  *	like get_word but will accept something in double or single quotes
17550348Skarels  *	(to allow embedded spaces).
17650348Skarels  */
17750348Skarels char *
get_quoted_word(fp)17850348Skarels get_quoted_word(fp)
17950348Skarels 	register FILE *fp;
18050348Skarels {
18150348Skarels 	static char line[256];
18250348Skarels 	register int ch;
18350348Skarels 	register char *cp;
18450348Skarels 
18550348Skarels 	while ((ch = getc(fp)) != EOF)
18650348Skarels 		if (ch != ' ' && ch != '\t')
18750348Skarels 			break;
18850348Skarels 	if (ch == EOF)
18950348Skarels 		return ((char *)EOF);
19050348Skarels 	if (ch == '\n')
19150348Skarels 		return (NULL);
19250348Skarels 	cp = line;
19350348Skarels 	if (ch == '"' || ch == '\'') {
19450348Skarels 		register int quote = ch;
19550348Skarels 
19650348Skarels 		while ((ch = getc(fp)) != EOF) {
19750348Skarels 			if (ch == quote)
19850348Skarels 				break;
19950348Skarels 			if (ch == '\n') {
20050348Skarels 				*cp = 0;
20150348Skarels 				printf("config: missing quote reading `%s'\n",
20250348Skarels 					line);
20350348Skarels 				exit(2);
20450348Skarels 			}
20550348Skarels 			*cp++ = ch;
20650348Skarels 		}
20750348Skarels 	} else {
20850348Skarels 		*cp++ = ch;
20950348Skarels 		while ((ch = getc(fp)) != EOF) {
21050348Skarels 			if (isspace(ch))
21150348Skarels 				break;
21250348Skarels 			*cp++ = ch;
21350348Skarels 		}
21450348Skarels 		if (ch != EOF)
21550348Skarels 			(void) ungetc(ch, fp);
21650348Skarels 	}
21750348Skarels 	*cp = 0;
21850348Skarels 	if (ch == EOF)
21950348Skarels 		return ((char *)EOF);
22050348Skarels 	return (line);
22150348Skarels }
22250348Skarels 
22350348Skarels /*
2248892Sroot  * prepend the path to a filename
2252682Stoy  */
2268900Sroot char *
path(file)2272682Stoy path(file)
2288892Sroot 	char *file;
2292682Stoy {
2308892Sroot 	register char *cp;
2312682Stoy 
23245888Sbostic #define	CDIR	"../../compile/"
23346297Sbostic 	cp = malloc((unsigned int)(sizeof(CDIR) + strlen(PREFIX) +
23447744Sbostic 	    (file ? strlen(file) : 0) + 2));
23545888Sbostic 	(void) strcpy(cp, CDIR);
2368900Sroot 	(void) strcat(cp, PREFIX);
23734109Sbostic 	if (file) {
23834109Sbostic 		(void) strcat(cp, "/");
23934109Sbostic 		(void) strcat(cp, file);
24034109Sbostic 	}
2418892Sroot 	return (cp);
2422682Stoy }
243