* mkmakefile.c 1.16 82/07/21
* Functions in this file build the makefile from the files list
* and the information in the config table
#define next_word(fp, wd)\
{ register char *word = get_word(fp);\
if (word == EOF) return EOF; \
static struct file_list
*fcur
;
struct file_list
*fl_lookup(file
)
register struct file_list
*fp
;
for (fp
= ftab
; fp
!= NULL
; fp
= fp
->f_next
)
* Make a new file list entry
struct file_list
*new_fent()
register struct file_list
*fp
;
fp
= (struct file_list
*) malloc(sizeof *fp
);
fp
->f_needs
= fp
->f_next
= NULL
;
* Build the makefile from the skeleton
read_files(); /* Read in the "files" file */
ifp
= fopen("../conf/makefile", "r");
perror("../conf/makefile");
ofp
= fopen(path("makefile"), "w");
perror(path("makefile"));
fprintf(ofp
, "IDENT=-D%s", raise(ident
));
printf("cpu type must be specified\n");
for (cp
= cputype
; cp
; cp
= cp
->cpu_next
)
fprintf(ofp
, " -D%s", cp
->cpu_name
);
for (op
= opt
; op
; op
= op
->op_next
)
fprintf(ofp
, " -D%s=\"%s\"", op
->op_name
, op
->op_value
);
fprintf(ofp
, " -D%s", op
->op_name
);
printf("hz not specified; 50hz assumed\n");
printf("timezone not specified; gmt assumed\n");
printf("maxusers not specified; 24 assumed\n");
} else if (maxusers
< 8) {
printf("minimum of 8 maxusers assumed\n");
} else if (maxusers
> 128) {
printf("maxusers truncated to 128\n");
fprintf(ofp
, "PARAM=-DHZ=%d -DTIMEZONE=%d -DDST=%d -DMAXUSERS=%d\n",
hz
, timezone
, dst
, maxusers
);
while(fgets(line
, BUFSIZ
, ifp
) != NULL
)
fprintf(ofp
, "%s", line
);
else if (eq(line
, "%OBJS\n"))
else if (eq(line
, "%CFILES\n"))
else if (eq(line
, "%RULES\n"))
else if (eq(line
, "%LOAD\n"))
fprintf(stderr
, "Unknown %% construct in generic makefile: %s", line
);
* Read in the "files" file.
* Store it in the ftab linked list
register struct file_list
*tp
;
register struct device
*dp
;
register char *wd
, *this;
fp
= fopen("../conf/files", "r");
while((wd
= get_word(fp
)) != EOF
)
fprintf(stderr
, "Huh, no type for %s in files.\n", this);
if ((tp
= fl_lookup(wd
)) == NULL
)
if (wd
== NULL
|| (dev
= eq(wd
, "device-driver")))
fprintf(stderr
, "Needed a dev for optional(%s)\n",
for (dp
= dtab
; dp
!= NULL
; dp
= dp
->d_next
)
while ((wd
= get_word(fp
)) != NULL
)
if (dev
== 0 && wd
!= NULL
)
dev
= (wd
!= NULL
&& eq(wd
, "device-driver"));
type
= dev
? DEVICE
: NORMAL
;
* Spew forth the OBJS definition
register struct file_list
*tp
;
register char *cp
, och
, *sp
;
for (tp
= ftab
; tp
!= NULL
; tp
= tp
->f_next
)
if (tp
->f_type
== INVISIBLE
)
cp
= sp
+ (len
= strlen(sp
)) - 1;
* Spew forth the CFILES definition
register struct file_list
*tp
;
for (tp
= ftab
; tp
!= NULL
; tp
= tp
->f_next
)
if (tp
->f_type
== INVISIBLE
)
if (tp
->f_fn
[strlen(tp
->f_fn
)-1] != 'c')
if ((len
= 3 + strlen(tp
->f_fn
)) + lpos
> 72)
fprintf(fp
, "../%s ", tp
->f_fn
);
* Return tail end of a filename
* Spit out the rules for making each file
register char *cp
, *np
, och
, *tp
;
register struct file_list
*ftp
;
for (ftp
= ftab
; ftp
!= NULL
; ftp
= ftp
->f_next
)
if (ftp
->f_type
== INVISIBLE
)
cp
= (np
= ftp
->f_fn
) + strlen(ftp
->f_fn
) - 1;
fprintf(f
, "%so: ../%s%c\n", tail(np
), np
, och
);
fprintf(f
, "\t${AS} -o %so ../%ss\n\n", tp
, np
);
else if (ftp
->f_type
== NORMAL
)
fprintf(f
, "\t${CC} -I. -c -S ${COPTS} ../%sc\n", np
);
fprintf(f
, "\t${C2} %ss | sed -f ../conf/asm.sed | ${AS} -o %so\n",
fprintf(f
, "\trm -f %ss\n\n", tp
);
else if (ftp
->f_type
== DEVICE
)
fprintf(f
, "\t${CC} -I. -c -S ${COPTS} ../%sc\n", np
);
fprintf(f
,"\t${C2} -i %ss | sed -f ../conf/asm.sed | ${AS} -o %so\n",
fprintf(f
, "\trm -f %ss\n\n", tp
);
fprintf(stderr
, "Don't know rules for %s", np
);
* Create the load strings
register struct file_list
*fl
;
register bool first
= TRUE
;
for (fl
= conf_list
; fl
!= NULL
; fl
= fl
->f_next
)
fprintf(f
, "%s: makefile locore.o ${OBJS} ioconf.o param.o swap%s.o\n",
fprintf(f
, "\t@echo loading %s\n\t@rm -f %s\n",
fl
->f_needs
, fl
->f_needs
);
fprintf(f
, "\t@sh ../conf/newvers.sh\n");
fprintf(f
, "\t@cc $(CFLAGS) -c vers.c\n");
"\t@ld -n -o %s -e start -x -T 80000000 locore.o ${OBJS} vers.o ioconf.o param.o swap%s.o\n",
fprintf(f
, "\t@echo rearranging symbols\n");
fprintf(f
, "\t@-symorder ../conf/symbols.sort %s\n", fl
->f_needs
);
fprintf(f
, "\t@size %s\n", fl
->f_needs
);
fprintf(f
, "\t@chmod 755 %s\n\n", fl
->f_needs
);
for (fl
= conf_list
; fl
!= NULL
; fl
= fl
->f_next
)
fprintf(f
, "swap%s.o: ../dev/swap%s.c\n", fl
->f_fn
, fl
->f_fn
);
fprintf(f
, "\t${CC} -I. -c -S ${COPTS} ../dev/swap%s.c\n", fl
->f_fn
);
"\t${C2} swap%s.s | sed -f ../conf/asm.sed | ${AS} -o swap%s.o\n",
fprintf(f
, "\trm -f swap%s.s\n\n", fl
->f_fn
);
for (fl
= conf_list
; fl
!= NULL
; fl
= fl
->f_next
)
fprintf(f
, " %s", fl
->f_needs
);