xref: /original-bsd/usr.sbin/config/mkmakefile.c (revision 557ac071)
1d067911eSdist /*
2*557ac071Sbostic  * Copyright (c) 1993, 19801990
3*557ac071Sbostic  *	The Regents of the University of California.  All rights reserved.
4923d6574Sbostic  *
56da65516Sbostic  * %sccs.include.redist.c%
6d067911eSdist  */
7d067911eSdist 
848d9f3e9Ssam #ifndef lint
9*557ac071Sbostic static char sccsid[] = "@(#)mkmakefile.c	8.1 (Berkeley) 06/06/93";
10923d6574Sbostic #endif /* not lint */
116748886bSroot 
12c37ded4eStoy /*
136748886bSroot  * Build the makefile for the system, from
146748886bSroot  * the information in the files files and the
156748886bSroot  * additional files for the machine being compiled to.
16c37ded4eStoy  */
17c37ded4eStoy 
18c37ded4eStoy #include <stdio.h>
198af1f1f6Swnj #include <ctype.h>
20c37ded4eStoy #include "y.tab.h"
21c37ded4eStoy #include "config.h"
22c37ded4eStoy 
23c37ded4eStoy #define next_word(fp, wd) \
24c37ded4eStoy 	{ register char *word = get_word(fp); \
25761f060aSroot 	  if (word == (char *)EOF) \
26761f060aSroot 		return; \
276748886bSroot 	  else \
286748886bSroot 		wd = word; \
296748886bSroot 	}
306373cc2fSkarels #define next_quoted_word(fp, wd) \
316373cc2fSkarels 	{ register char *word = get_quoted_word(fp); \
326373cc2fSkarels 	  if (word == (char *)EOF) \
336373cc2fSkarels 		return; \
346373cc2fSkarels 	  else \
356373cc2fSkarels 		wd = word; \
366373cc2fSkarels 	}
37c37ded4eStoy 
38c37ded4eStoy static	struct file_list *fcur;
39713645a4Smckusick char *tail();
40c37ded4eStoy 
41c37ded4eStoy /*
42e29f12cdSkarels  * Lookup a file, by name.
43c37ded4eStoy  */
446748886bSroot struct file_list *
fl_lookup(file)456748886bSroot fl_lookup(file)
46c37ded4eStoy 	register char *file;
47c37ded4eStoy {
48c37ded4eStoy 	register struct file_list *fp;
49c37ded4eStoy 
50761f060aSroot 	for (fp = ftab ; fp != 0; fp = fp->f_next) {
51c37ded4eStoy 		if (eq(fp->f_fn, file))
526748886bSroot 			return (fp);
53c37ded4eStoy 	}
546748886bSroot 	return (0);
55c37ded4eStoy }
56c37ded4eStoy 
57c37ded4eStoy /*
58713645a4Smckusick  * Lookup a file, by final component name.
59713645a4Smckusick  */
60713645a4Smckusick struct file_list *
fltail_lookup(file)61713645a4Smckusick fltail_lookup(file)
62713645a4Smckusick 	register char *file;
63713645a4Smckusick {
64713645a4Smckusick 	register struct file_list *fp;
65713645a4Smckusick 
66713645a4Smckusick 	for (fp = ftab ; fp != 0; fp = fp->f_next) {
67713645a4Smckusick 		if (eq(tail(fp->f_fn), tail(file)))
68713645a4Smckusick 			return (fp);
69713645a4Smckusick 	}
70713645a4Smckusick 	return (0);
71713645a4Smckusick }
72713645a4Smckusick 
73713645a4Smckusick /*
74c37ded4eStoy  * Make a new file list entry
75c37ded4eStoy  */
766748886bSroot struct file_list *
new_fent()776748886bSroot new_fent()
78c37ded4eStoy {
79c37ded4eStoy 	register struct file_list *fp;
80c37ded4eStoy 
81c37ded4eStoy 	fp = (struct file_list *) malloc(sizeof *fp);
826373cc2fSkarels 	bzero(fp, sizeof *fp);
83761f060aSroot 	if (fcur == 0)
84c37ded4eStoy 		fcur = ftab = fp;
85c37ded4eStoy 	else
86c37ded4eStoy 		fcur->f_next = fp;
87c37ded4eStoy 	fcur = fp;
886748886bSroot 	return (fp);
89c37ded4eStoy }
90c37ded4eStoy 
915d08c183Ssam static	struct users {
925d08c183Ssam 	int	u_default;
935d08c183Ssam 	int	u_min;
945d08c183Ssam 	int	u_max;
955d08c183Ssam } users[] = {
965d08c183Ssam 	{ 24, 8, 1024 },		/* MACHINE_VAX */
97d8672969Ssam 	{ 4, 2, 128 },			/* MACHINE_TAHOE */
981b829108Smckusick 	{ 8, 2, 64 },			/* MACHINE_HP300 */
9935683881Swilliam 	{ 8, 2, 64 },			/* MACHINE_I386 */
100f541909eSralph 	{ 8, 2, 64 },			/* MACHINE_MIPS */
101f541909eSralph 	{ 8, 2, 64 },			/* MACHINE_PMAX */
102057802f0Smckusick 	{ 8, 2, 64 },			/* MACHINE_LUNA68K */
103877e30caSmckusick 	{ 8, 2, 64 },			/* MACHINE_NEWS3400 */
1045d08c183Ssam };
1055d08c183Ssam #define	NUSERS	(sizeof (users) / sizeof (users[0]))
1066748886bSroot 
107c37ded4eStoy /*
108c37ded4eStoy  * Build the makefile from the skeleton
109c37ded4eStoy  */
makefile()110c37ded4eStoy makefile()
111c37ded4eStoy {
112c37ded4eStoy 	FILE *ifp, *ofp;
113739d7557Swnj 	char line[BUFSIZ];
11458d45129Stoy 	struct opt *op;
1155d08c183Ssam 	struct users *up;
116c37ded4eStoy 
1176748886bSroot 	read_files();
1183d3389a8Sbostic 	strcpy(line, "Makefile.");
119761f060aSroot 	(void) strcat(line, machinename);
1206748886bSroot 	ifp = fopen(line, "r");
121761f060aSroot 	if (ifp == 0) {
1226748886bSroot 		perror(line);
123eb030620Stoy 		exit(1);
124eb030620Stoy 	}
125939826dbSkarels 	ofp = fopen(path("Makefile"), "w");
126761f060aSroot 	if (ofp == 0) {
127939826dbSkarels 		perror(path("Makefile"));
128eb030620Stoy 		exit(1);
129eb030620Stoy 	}
130eb030620Stoy 	fprintf(ofp, "IDENT=-D%s", raise(ident));
131bd17112dSsam 	if (profiling)
132bd17112dSsam 		fprintf(ofp, " -DGPROF");
1336748886bSroot 	if (cputype == 0) {
134eb030620Stoy 		printf("cpu type must be specified\n");
135eb030620Stoy 		exit(1);
136eb030620Stoy 	}
1376748886bSroot 	{ struct cputype *cp;
138eb030620Stoy 	  for (cp = cputype; cp; cp = cp->cpu_next)
139eb030620Stoy 		fprintf(ofp, " -D%s", cp->cpu_name);
1406748886bSroot 	}
14158d45129Stoy 	for (op = opt; op; op = op->op_next)
1429f3fe239Skre 		if (op->op_value)
1439f3fe239Skre 			fprintf(ofp, " -D%s=\"%s\"", op->op_name, op->op_value);
1449f3fe239Skre 		else
14558d45129Stoy 			fprintf(ofp, " -D%s", op->op_name);
146eb030620Stoy 	fprintf(ofp, "\n");
147eb030620Stoy 	if (hadtz == 0)
148eb030620Stoy 		printf("timezone not specified; gmt assumed\n");
1495d08c183Ssam 	if ((unsigned)machine > NUSERS) {
1505d08c183Ssam 		printf("maxusers config info isn't present, using vax\n");
1515d08c183Ssam 		up = &users[MACHINE_VAX-1];
1525d08c183Ssam 	} else
1535d08c183Ssam 		up = &users[machine-1];
154eb030620Stoy 	if (maxusers == 0) {
1555d08c183Ssam 		printf("maxusers not specified; %d assumed\n", up->u_default);
1565d08c183Ssam 		maxusers = up->u_default;
1575d08c183Ssam 	} else if (maxusers < up->u_min) {
1585d08c183Ssam 		printf("minimum of %d maxusers assumed\n", up->u_min);
1595d08c183Ssam 		maxusers = up->u_min;
1605d08c183Ssam 	} else if (maxusers > up->u_max)
1615d08c183Ssam 		printf("warning: maxusers > %d (%d)\n", up->u_max, maxusers);
16247676501Smckusick 	fprintf(ofp, "PARAM=-DTIMEZONE=%d -DDST=%d -DMAXUSERS=%d",
163b7637e2cSbostic 	    zone, dst, maxusers);
16447676501Smckusick 	if (hz > 0)
16547676501Smckusick 		fprintf(ofp, " -DHZ=%d", hz);
16647676501Smckusick 	fprintf(ofp, "\n");
167e19a3572Skarels 	for (op = mkopt; op; op = op->op_next)
168e19a3572Skarels 		fprintf(ofp, "%s=%s\n", op->op_name, op->op_value);
1691b829108Smckusick 	if (debugging)
1706373cc2fSkarels 		fprintf(ofp, "DEBUG=-g\n");
1716373cc2fSkarels 	if (profiling)
1726373cc2fSkarels 		fprintf(ofp, "PROF=-pg\n");
1736373cc2fSkarels 	while (fgets(line, BUFSIZ, ifp) != 0) {
1746373cc2fSkarels 		if (*line != '%') {
175c37ded4eStoy 			fprintf(ofp, "%s", line);
176c37ded4eStoy 			continue;
1776373cc2fSkarels 		}
1786748886bSroot 		if (eq(line, "%OBJS\n"))
179c37ded4eStoy 			do_objs(ofp);
180c37ded4eStoy 		else if (eq(line, "%CFILES\n"))
181c37ded4eStoy 			do_cfiles(ofp);
182c37ded4eStoy 		else if (eq(line, "%RULES\n"))
183c37ded4eStoy 			do_rules(ofp);
184c37ded4eStoy 		else if (eq(line, "%LOAD\n"))
185c37ded4eStoy 			do_load(ofp);
186c37ded4eStoy 		else
1876748886bSroot 			fprintf(stderr,
1886748886bSroot 			    "Unknown %% construct in generic makefile: %s",
1896748886bSroot 			    line);
190334103f2Ssam 	}
191761f060aSroot 	(void) fclose(ifp);
192761f060aSroot 	(void) fclose(ofp);
193c37ded4eStoy }
194c37ded4eStoy 
195c37ded4eStoy /*
1966748886bSroot  * Read in the information about files used in making the system.
1976748886bSroot  * Store it in the ftab linked list.
198c37ded4eStoy  */
read_files()199c37ded4eStoy read_files()
200c37ded4eStoy {
201c37ded4eStoy 	FILE *fp;
202e29f12cdSkarels 	register struct file_list *tp, *pf;
203c37ded4eStoy 	register struct device *dp;
2041b829108Smckusick 	struct device *save_dp;
205939826dbSkarels 	register struct opt *op;
2066373cc2fSkarels 	char *wd, *this, *needs, *special;
2076748886bSroot 	char fname[32];
2086373cc2fSkarels 	int nreqs, first = 1, configdep, isdup, std, filetype;
209c37ded4eStoy 
210761f060aSroot 	ftab = 0;
2113d3389a8Sbostic 	(void) strcpy(fname, "../../conf/files");
2126748886bSroot openit:
2136748886bSroot 	fp = fopen(fname, "r");
214761f060aSroot 	if (fp == 0) {
215334103f2Ssam 		perror(fname);
216739d7557Swnj 		exit(1);
217739d7557Swnj 	}
2186748886bSroot next:
219f7692ae3Ssam 	/*
220f7692ae3Ssam 	 * filename	[ standard | optional ] [ config-dependent ]
221f7692ae3Ssam 	 *	[ dev* | profiling-routine ] [ device-driver]
2226373cc2fSkarels 	 *	[ compile-with "compile rule" ]
223f7692ae3Ssam 	 */
2246748886bSroot 	wd = get_word(fp);
225761f060aSroot 	if (wd == (char *)EOF) {
226761f060aSroot 		(void) fclose(fp);
227713645a4Smckusick 		if (first == 1) {
228761f060aSroot 			(void) sprintf(fname, "files.%s", machinename);
229713645a4Smckusick 			first++;
2306748886bSroot 			goto openit;
2316748886bSroot 		}
232713645a4Smckusick 		if (first == 2) {
233713645a4Smckusick 			(void) sprintf(fname, "files.%s", raise(ident));
234713645a4Smckusick 			first++;
235713645a4Smckusick 			fp = fopen(fname, "r");
236713645a4Smckusick 			if (fp != 0)
237713645a4Smckusick 				goto next;
238713645a4Smckusick 		}
2396748886bSroot 		return;
2406748886bSroot 	}
241761f060aSroot 	if (wd == 0)
2426748886bSroot 		goto next;
243c37ded4eStoy 	this = ns(wd);
2446748886bSroot 	next_word(fp, wd);
245761f060aSroot 	if (wd == 0) {
24680de8138Sroot 		printf("%s: No type for %s.\n",
2476748886bSroot 		    fname, this);
2486748886bSroot 		exit(1);
2496748886bSroot 	}
250e29f12cdSkarels 	if ((pf = fl_lookup(this)) && (pf->f_type != INVISIBLE || pf->f_flags))
251939826dbSkarels 		isdup = 1;
252939826dbSkarels 	else
253939826dbSkarels 		isdup = 0;
254713645a4Smckusick 	tp = 0;
255713645a4Smckusick 	if (first == 3 && (tp = fltail_lookup(this)) != 0)
256713645a4Smckusick 		printf("%s: Local file %s overrides %s.\n",
257713645a4Smckusick 		    fname, this, tp->f_fn);
2586748886bSroot 	nreqs = 0;
2596373cc2fSkarels 	special = 0;
260f7692ae3Ssam 	configdep = 0;
2616748886bSroot 	needs = 0;
2621b829108Smckusick 	std = 0;
2636373cc2fSkarels 	filetype = NORMAL;
2646748886bSroot 	if (eq(wd, "standard"))
2651b829108Smckusick 		std = 1;
2661b829108Smckusick 	else if (!eq(wd, "optional")) {
267f7692ae3Ssam 		printf("%s: %s must be optional or standard\n", fname, this);
2686748886bSroot 		exit(1);
2696748886bSroot 	}
2701b829108Smckusick nextparam:
271c37ded4eStoy 	next_word(fp, wd);
272761f060aSroot 	if (wd == 0)
2731b829108Smckusick 		goto doneparam;
274f7692ae3Ssam 	if (eq(wd, "config-dependent")) {
275f7692ae3Ssam 		configdep++;
2761b829108Smckusick 		goto nextparam;
277f7692ae3Ssam 	}
2786373cc2fSkarels 	if (eq(wd, "compile-with")) {
2796373cc2fSkarels 		next_quoted_word(fp, wd);
2806373cc2fSkarels 		if (wd == 0) {
2816373cc2fSkarels 			printf("%s: %s missing compile command string.\n",
2826373cc2fSkarels 			       fname);
2836373cc2fSkarels 			exit(1);
2846373cc2fSkarels 		}
2856373cc2fSkarels 		special = ns(wd);
2866373cc2fSkarels 		goto nextparam;
287334103f2Ssam 	}
288c594105fSecc 	nreqs++;
2896373cc2fSkarels 	if (eq(wd, "device-driver")) {
2906373cc2fSkarels 		filetype = DRIVER;
2916373cc2fSkarels 		goto nextparam;
2926373cc2fSkarels 	}
2936373cc2fSkarels 	if (eq(wd, "profiling-routine")) {
2946373cc2fSkarels 		filetype = PROFILING;
2956373cc2fSkarels 		goto nextparam;
2966373cc2fSkarels 	}
297939826dbSkarels 	if (needs == 0 && nreqs == 1)
2986748886bSroot 		needs = ns(wd);
299939826dbSkarels 	if (isdup)
300939826dbSkarels 		goto invis;
3011b829108Smckusick 	for (dp = dtab; dp != 0; save_dp = dp, dp = dp->d_next)
3021b829108Smckusick 		if (eq(dp->d_name, wd)) {
3036373cc2fSkarels 			if (std && dp->d_type == PSEUDO_DEVICE &&
3046373cc2fSkarels 			    dp->d_slave <= 0)
3051b829108Smckusick 				dp->d_slave = 1;
3061b829108Smckusick 			goto nextparam;
3071b829108Smckusick 		}
3081b829108Smckusick 	if (std) {
3091b829108Smckusick 		dp = (struct device *) malloc(sizeof *dp);
3101b829108Smckusick 		init_dev(dp);
3111b829108Smckusick 		dp->d_name = ns(wd);
3121b829108Smckusick 		dp->d_type = PSEUDO_DEVICE;
3131b829108Smckusick 		dp->d_slave = 1;
3141b829108Smckusick 		save_dp->d_next = dp;
3151b829108Smckusick 		goto nextparam;
3161b829108Smckusick 	}
317939826dbSkarels 	for (op = opt; op != 0; op = op->op_next)
318939826dbSkarels 		if (op->op_value == 0 && opteq(op->op_name, wd)) {
319939826dbSkarels 			if (nreqs == 1) {
320939826dbSkarels 				free(needs);
321939826dbSkarels 				needs = 0;
322939826dbSkarels 			}
3231b829108Smckusick 			goto nextparam;
324939826dbSkarels 		}
325939826dbSkarels invis:
326761f060aSroot 	while ((wd = get_word(fp)) != 0)
327c594105fSecc 		;
3288c99f874Skarels 	if (tp == 0)
3296748886bSroot 		tp = new_fent();
3306748886bSroot 	tp->f_fn = this;
3316748886bSroot 	tp->f_type = INVISIBLE;
3326748886bSroot 	tp->f_needs = needs;
333939826dbSkarels 	tp->f_flags = isdup;
3346373cc2fSkarels 	tp->f_special = special;
3356748886bSroot 	goto next;
336f7692ae3Ssam 
3371b829108Smckusick doneparam:
3381b829108Smckusick 	if (std == 0 && nreqs == 0) {
33980de8138Sroot 		printf("%s: what is %s optional on?\n",
3406748886bSroot 		    fname, this);
3416748886bSroot 		exit(1);
342c37ded4eStoy 	}
343f7692ae3Ssam 
3446748886bSroot save:
345f7692ae3Ssam 	if (wd) {
34680de8138Sroot 		printf("%s: syntax error describing %s\n",
3476748886bSroot 		    fname, this);
3486748886bSroot 		exit(1);
3496748886bSroot 	}
3506373cc2fSkarels 	if (filetype == PROFILING && profiling == 0)
351334103f2Ssam 		goto next;
3528c99f874Skarels 	if (tp == 0)
3536748886bSroot 		tp = new_fent();
3546748886bSroot 	tp->f_fn = this;
3556373cc2fSkarels 	tp->f_type = filetype;
356f7692ae3Ssam 	tp->f_flags = 0;
357f7692ae3Ssam 	if (configdep)
358f7692ae3Ssam 		tp->f_flags |= CONFIGDEP;
3596748886bSroot 	tp->f_needs = needs;
3606373cc2fSkarels 	tp->f_special = special;
361e29f12cdSkarels 	if (pf && pf->f_type == INVISIBLE)
362e29f12cdSkarels 		pf->f_flags = 1;		/* mark as duplicate */
3636748886bSroot 	goto next;
364c594105fSecc }
365c37ded4eStoy 
opteq(cp,dp)366939826dbSkarels opteq(cp, dp)
367939826dbSkarels 	char *cp, *dp;
368939826dbSkarels {
369939826dbSkarels 	char c, d;
370939826dbSkarels 
371939826dbSkarels 	for (; ; cp++, dp++) {
372939826dbSkarels 		if (*cp != *dp) {
373939826dbSkarels 			c = isupper(*cp) ? tolower(*cp) : *cp;
374939826dbSkarels 			d = isupper(*dp) ? tolower(*dp) : *dp;
375939826dbSkarels 			if (c != d)
376939826dbSkarels 				return (0);
377939826dbSkarels 		}
378939826dbSkarels 		if (*cp == 0)
379939826dbSkarels 			return (1);
380939826dbSkarels 	}
381939826dbSkarels }
382939826dbSkarels 
do_objs(fp)383c37ded4eStoy do_objs(fp)
384c37ded4eStoy 	FILE *fp;
385c37ded4eStoy {
386713645a4Smckusick 	register struct file_list *tp, *fl;
387c37ded4eStoy 	register int lpos, len;
3888af1f1f6Swnj 	register char *cp, och, *sp;
389713645a4Smckusick 	char swapname[32];
390c37ded4eStoy 
391c37ded4eStoy 	fprintf(fp, "OBJS=");
392c37ded4eStoy 	lpos = 6;
393761f060aSroot 	for (tp = ftab; tp != 0; tp = tp->f_next) {
394c37ded4eStoy 		if (tp->f_type == INVISIBLE)
395c37ded4eStoy 			continue;
39658d45129Stoy 		sp = tail(tp->f_fn);
3972c7edef8Ssam 		for (fl = conf_list; fl; fl = fl->f_next) {
3982c7edef8Ssam 			if (fl->f_type != SWAPSPEC)
3992c7edef8Ssam 				continue;
400345741fcSbostic 			(void) sprintf(swapname, "swap%s.c", fl->f_fn);
401713645a4Smckusick 			if (eq(sp, swapname))
402713645a4Smckusick 				goto cont;
403713645a4Smckusick 		}
4048af1f1f6Swnj 		cp = sp + (len = strlen(sp)) - 1;
405c37ded4eStoy 		och = *cp;
406c37ded4eStoy 		*cp = 'o';
4076748886bSroot 		if (len + lpos > 72) {
408c37ded4eStoy 			lpos = 8;
409c37ded4eStoy 			fprintf(fp, "\\\n\t");
410c37ded4eStoy 		}
4118af1f1f6Swnj 		fprintf(fp, "%s ", sp);
412c37ded4eStoy 		lpos += len + 1;
413c37ded4eStoy 		*cp = och;
4142c7edef8Ssam cont:
4152c7edef8Ssam 		;
416c37ded4eStoy 	}
417c37ded4eStoy 	if (lpos != 8)
418c37ded4eStoy 		putc('\n', fp);
419c37ded4eStoy }
420c37ded4eStoy 
do_cfiles(fp)421c37ded4eStoy do_cfiles(fp)
422c37ded4eStoy 	FILE *fp;
423c37ded4eStoy {
4242c4e58eaSbostic 	register struct file_list *tp, *fl;
425c37ded4eStoy 	register int lpos, len;
4262c4e58eaSbostic 	char swapname[32];
427c37ded4eStoy 
4282c4e58eaSbostic 	fputs("CFILES=", fp);
429c37ded4eStoy 	lpos = 8;
4302c4e58eaSbostic 	for (tp = ftab; tp; tp = tp->f_next)
4312c4e58eaSbostic 		if (tp->f_type != INVISIBLE) {
4322c4e58eaSbostic 			len = strlen(tp->f_fn);
4332c4e58eaSbostic 			if (tp->f_fn[len - 1] != 'c')
434c37ded4eStoy 				continue;
4352c4e58eaSbostic 			if ((len = 3 + len) + lpos > 72) {
436c37ded4eStoy 				lpos = 8;
4372c4e58eaSbostic 				fputs("\\\n\t", fp);
438c37ded4eStoy 			}
4393d3389a8Sbostic 			fprintf(fp, "$S/%s ", tp->f_fn);
440c37ded4eStoy 			lpos += len + 1;
441c37ded4eStoy 		}
4422c4e58eaSbostic 	for (fl = conf_list; fl; fl = fl->f_next)
4432c4e58eaSbostic 		if (fl->f_type == SYSTEMSPEC) {
444345741fcSbostic 			(void) sprintf(swapname, "swap%s.c", fl->f_fn);
4452c4e58eaSbostic 			if ((len = 3 + strlen(swapname)) + lpos > 72) {
4462c4e58eaSbostic 				lpos = 8;
4472c4e58eaSbostic 				fputs("\\\n\t", fp);
4482c4e58eaSbostic 			}
44944896bb5Skarels 			if (eq(fl->f_fn, "generic"))
4503d3389a8Sbostic 				fprintf(fp, "$S/%s/%s/%s ",
4513d3389a8Sbostic 				    machinename, machinename, swapname);
45244896bb5Skarels 			else
45344896bb5Skarels 				fprintf(fp, "%s ", swapname);
4542c4e58eaSbostic 			lpos += len + 1;
4552c4e58eaSbostic 		}
456c37ded4eStoy 	if (lpos != 8)
457c37ded4eStoy 		putc('\n', fp);
458c37ded4eStoy }
459c37ded4eStoy 
4606748886bSroot char *
tail(fn)4616748886bSroot tail(fn)
462c37ded4eStoy 	char *fn;
463c37ded4eStoy {
464c37ded4eStoy 	register char *cp;
465c37ded4eStoy 
466c37ded4eStoy 	cp = rindex(fn, '/');
467713645a4Smckusick 	if (cp == 0)
468713645a4Smckusick 		return (fn);
4696748886bSroot 	return (cp+1);
470c37ded4eStoy }
471c37ded4eStoy 
472c37ded4eStoy /*
4736748886bSroot  * Create the makerules for each file
4746748886bSroot  * which is part of the system.
4756748886bSroot  * Devices are processed with the special c2 option -i
4766748886bSroot  * which avoids any problem areas with i/o addressing
4776748886bSroot  * (e.g. for the VAX); assembler files are processed by as.
478c37ded4eStoy  */
do_rules(f)479c37ded4eStoy do_rules(f)
480c37ded4eStoy 	FILE *f;
481c37ded4eStoy {
482c37ded4eStoy 	register char *cp, *np, och, *tp;
483c37ded4eStoy 	register struct file_list *ftp;
4846373cc2fSkarels 	char *special;
485c37ded4eStoy 
486761f060aSroot 	for (ftp = ftab; ftp != 0; ftp = ftp->f_next) {
487c37ded4eStoy 		if (ftp->f_type == INVISIBLE)
488c37ded4eStoy 			continue;
489c37ded4eStoy 		cp = (np = ftp->f_fn) + strlen(ftp->f_fn) - 1;
490c37ded4eStoy 		och = *cp;
491c37ded4eStoy 		*cp = '\0';
4929e8aab84Skarels 		if (och == 'o') {
4933d3389a8Sbostic 			fprintf(f, "%so:\n\t-cp $S/%so .\n\n", tail(np), np);
4949e8aab84Skarels 			continue;
4959e8aab84Skarels 		}
4963d3389a8Sbostic 		fprintf(f, "%so: $S/%s%c\n", tail(np), np, och);
497c37ded4eStoy 		tp = tail(np);
4986373cc2fSkarels 		special = ftp->f_special;
4996373cc2fSkarels 		if (special == 0) {
5006373cc2fSkarels 			char *ftype;
5016373cc2fSkarels 			static char cmd[128];
5026373cc2fSkarels 
5036748886bSroot 			switch (ftp->f_type) {
5046748886bSroot 
5056748886bSroot 			case NORMAL:
5066373cc2fSkarels 				ftype = "NORMAL";
5076748886bSroot 				break;
5086748886bSroot 
509f7692ae3Ssam 			case DRIVER:
5106373cc2fSkarels 				ftype = "DRIVER";
5116748886bSroot 				break;
5126748886bSroot 
5136748886bSroot 			case PROFILING:
514bd17112dSsam 				if (!profiling)
515bd17112dSsam 					continue;
5166373cc2fSkarels 				ftype = "PROFILE";
517334103f2Ssam 				break;
5186748886bSroot 
5196748886bSroot 			default:
5206373cc2fSkarels 				printf("config: don't know rules for %s\n", np);
5216748886bSroot 				break;
5226748886bSroot 			}
5236373cc2fSkarels 			(void)sprintf(cmd, "${%s_%c%s}", ftype, toupper(och),
5246373cc2fSkarels 				      ftp->f_flags & CONFIGDEP? "_C" : "");
5256373cc2fSkarels 			special = cmd;
5266373cc2fSkarels 		}
527c37ded4eStoy 		*cp = och;
5286373cc2fSkarels 		fprintf(f, "\t%s\n\n", special);
529c37ded4eStoy 	}
530c37ded4eStoy }
531c37ded4eStoy 
532c37ded4eStoy /*
533c37ded4eStoy  * Create the load strings
534c37ded4eStoy  */
do_load(f)535c37ded4eStoy do_load(f)
536c37ded4eStoy 	register FILE *f;
537c37ded4eStoy {
538c37ded4eStoy 	register struct file_list *fl;
5392c4e58eaSbostic 	register int first;
5402c7edef8Ssam 	struct file_list *do_systemspec();
541c37ded4eStoy 
5422c4e58eaSbostic 	for (first = 1, fl = conf_list; fl; first = 0)
5432c4e58eaSbostic 		fl = fl->f_type == SYSTEMSPEC ?
5442c4e58eaSbostic 			do_systemspec(f, fl, first) : fl->f_next;
5452c4e58eaSbostic 	fputs("all:", f);
5462c4e58eaSbostic 	for (fl = conf_list; fl; fl = fl->f_next)
5472c7edef8Ssam 		if (fl->f_type == SYSTEMSPEC)
5482c7edef8Ssam 			fprintf(f, " %s", fl->f_needs);
5492c4e58eaSbostic 	putc('\n', f);
5502c7edef8Ssam }
5512c7edef8Ssam 
5522c7edef8Ssam struct file_list *
do_systemspec(f,fl,first)5532c7edef8Ssam do_systemspec(f, fl, first)
5542c7edef8Ssam 	FILE *f;
5552c7edef8Ssam 	register struct file_list *fl;
5562c7edef8Ssam 	int first;
5572c7edef8Ssam {
5582c7edef8Ssam 
5596373cc2fSkarels 	fprintf(f, "%s: ${SYSTEM_DEP} swap%s.o", fl->f_needs, fl->f_fn);
5606373cc2fSkarels 	if (first)
5616373cc2fSkarels 		fprintf(f, " newvers");
5626373cc2fSkarels 	fprintf(f, "\n\t${SYSTEM_LD_HEAD}\n");
5636373cc2fSkarels 	fprintf(f, "\t${SYSTEM_LD} swap%s.o\n", fl->f_fn);
5646373cc2fSkarels 	fprintf(f, "\t${SYSTEM_LD_TAIL}\n\n");
5652c7edef8Ssam 	do_swapspec(f, fl->f_fn);
56694d96a9cSmckusick 	for (fl = fl->f_next; fl; fl = fl->f_next)
56794d96a9cSmckusick 		if (fl->f_type != SWAPSPEC)
56894d96a9cSmckusick 			break;
5692c7edef8Ssam 	return (fl);
570c37ded4eStoy }
5712c7edef8Ssam 
do_swapspec(f,name)5722c7edef8Ssam do_swapspec(f, name)
5732c7edef8Ssam 	FILE *f;
5742c7edef8Ssam 	register char *name;
5752c7edef8Ssam {
5762c7edef8Ssam 
5776373cc2fSkarels 	if (!eq(name, "generic"))
5782c7edef8Ssam 		fprintf(f, "swap%s.o: swap%s.c\n", name, name);
5796373cc2fSkarels 	else
580f541909eSralph 		fprintf(f, "swapgeneric.o: $S/%s/%s/swapgeneric.c\n",
581f541909eSralph 			machinename, machinename);
5826373cc2fSkarels 	fprintf(f, "\t${NORMAL_C}\n\n");
583c37ded4eStoy }
5848af1f1f6Swnj 
585761f060aSroot char *
raise(str)5868af1f1f6Swnj raise(str)
5878af1f1f6Swnj 	register char *str;
5888af1f1f6Swnj {
5898af1f1f6Swnj 	register char *cp = str;
5908af1f1f6Swnj 
5916748886bSroot 	while (*str) {
5928af1f1f6Swnj 		if (islower(*str))
5938af1f1f6Swnj 			*str = toupper(*str);
5948af1f1f6Swnj 		str++;
5958af1f1f6Swnj 	}
5966748886bSroot 	return (cp);
5978af1f1f6Swnj }
598