xref: /csrg-svn/usr.sbin/config/main.c (revision 30379)
119987Sdist /*
219987Sdist  * Copyright (c) 1980 Regents of the University of California.
319987Sdist  * All rights reserved.  The Berkeley software License Agreement
419987Sdist  * specifies the terms and conditions for redistribution.
519987Sdist  */
619987Sdist 
714557Ssam #ifndef lint
819987Sdist char copyright[] =
919987Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\
1019987Sdist  All rights reserved.\n";
1119987Sdist #endif not lint
122653Stoy 
1319987Sdist #ifndef lint
14*30379Skarels static char sccsid[] = "@(#)main.c	5.4 (Berkeley) 01/13/87";
1519987Sdist #endif not lint
1619987Sdist 
172653Stoy #include <stdio.h>
182653Stoy #include <ctype.h>
192653Stoy #include "y.tab.h"
202653Stoy #include "config.h"
212653Stoy 
228892Sroot /*
238892Sroot  * Config builds a set of files for building a UNIX
248892Sroot  * system given a description of the desired system.
258892Sroot  */
262653Stoy main(argc, argv)
278892Sroot 	int argc;
288892Sroot 	char **argv;
292653Stoy {
308892Sroot 
319597Ssam 	if (argc > 1 && eq("-p", argv[1])) {
329597Ssam 		profiling++;
339597Ssam 		argc--, argv++;
349597Ssam 	}
358892Sroot 	if (argc != 2) {
369597Ssam 		fprintf(stderr, "usage: config [ -p ] sysname\n");
378892Sroot 		exit(1);
388892Sroot 	}
398892Sroot 	PREFIX = argv[1];
408892Sroot 	if (freopen(argv[1], "r", stdin) == NULL) {
418892Sroot 		perror(argv[1]);
428892Sroot 		exit(2);
438892Sroot 	}
448892Sroot 	dtab = NULL;
4512487Ssam 	confp = &conf_list;
468892Sroot 	if (yyparse())
478892Sroot 		exit(3);
488892Sroot 	switch (machine) {
498892Sroot 
508892Sroot 	case MACHINE_VAX:
518892Sroot 		vax_ioconf();		/* Print ioconf.c */
528892Sroot 		ubglue();		/* Create ubglue.s */
538892Sroot 		break;
548892Sroot 
5529841Ssam 	case MACHINE_TAHOE:
5629841Ssam 		tahoe_ioconf();
5729841Ssam 		vbglue();
588892Sroot 		break;
598892Sroot 
608892Sroot 	default:
618892Sroot 		printf("Specify machine type, e.g. ``machine vax''\n");
628892Sroot 		exit(1);
638892Sroot 	}
64*30379Skarels 	/*
65*30379Skarels 	 * make symbolic links in compilation directory
66*30379Skarels 	 * for "sys" (to make genassym.c work along with #include <sys/xxx>)
67*30379Skarels 	 * and similarly for "machine".
68*30379Skarels 	 */
69*30379Skarels 	{
70*30379Skarels 	char xxx[80];
71*30379Skarels 
72*30379Skarels 	(void) symlink("../h", path("sys"));
73*30379Skarels 	sprintf(xxx, "../%s", machinename);
74*30379Skarels 	(void) symlink(xxx, path("machine"));
75*30379Skarels 	}
762653Stoy 	makefile();			/* build Makefile */
772653Stoy 	headers();			/* make a lot of .h files */
7812487Ssam 	swapconf();			/* swap config files */
793156Stoy 	printf("Don't forget to run \"make depend\"\n");
802653Stoy }
812653Stoy 
822653Stoy /*
832653Stoy  * get_word
842653Stoy  *	returns EOF on end of file
852653Stoy  *	NULL on end of line
862653Stoy  *	pointer to the word otherwise
872653Stoy  */
888892Sroot char *
898892Sroot get_word(fp)
908892Sroot 	register FILE *fp;
912653Stoy {
928892Sroot 	static char line[80];
938892Sroot 	register int ch;
948892Sroot 	register char *cp;
952653Stoy 
968892Sroot 	while ((ch = getc(fp)) != EOF)
978892Sroot 		if (ch != ' ' && ch != '\t')
988892Sroot 			break;
998892Sroot 	if (ch == EOF)
1008900Sroot 		return ((char *)EOF);
1018892Sroot 	if (ch == '\n')
1028892Sroot 		return (NULL);
1038892Sroot 	cp = line;
1042653Stoy 	*cp++ = ch;
1058892Sroot 	while ((ch = getc(fp)) != EOF) {
1068892Sroot 		if (isspace(ch))
1078892Sroot 			break;
1088892Sroot 		*cp++ = ch;
1098892Sroot 	}
1108892Sroot 	*cp = 0;
1118892Sroot 	if (ch == EOF)
1128900Sroot 		return ((char *)EOF);
1138900Sroot 	(void) ungetc(ch, fp);
1148892Sroot 	return (line);
1152653Stoy }
1162682Stoy 
1172682Stoy /*
1188892Sroot  * prepend the path to a filename
1192682Stoy  */
1208900Sroot char *
1212682Stoy path(file)
1228892Sroot 	char *file;
1232682Stoy {
1248892Sroot 	register char *cp;
1252682Stoy 
1268900Sroot 	cp = malloc((unsigned)(strlen(PREFIX)+strlen(file)+5));
1278900Sroot 	(void) strcpy(cp, "../");
1288900Sroot 	(void) strcat(cp, PREFIX);
1298900Sroot 	(void) strcat(cp, "/");
1308900Sroot 	(void) strcat(cp, file);
1318892Sroot 	return (cp);
1322682Stoy }
133