Some tweaks to (hopefully) make the crunchgen-generated makefile

parallel-build-safe.
This commit is contained in:
sommerfeld 2002-05-02 21:18:31 +00:00
parent ab8f2fbc01
commit 508e207b01
1 changed files with 35 additions and 34 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: crunchgen.c,v 1.36 2002/04/29 04:20:56 sommerfeld Exp $ */
/* $NetBSD: crunchgen.c,v 1.37 2002/05/02 21:18:31 sommerfeld Exp $ */
/*
* Copyright (c) 1994 University of Maryland
* All Rights Reserved.
@ -29,11 +29,11 @@
* crunchgen.c
*
* Generates a Makefile and main C file for a crunched executable,
* from specs given in a .conf file.
* from specs given in a .conf file.
*/
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: crunchgen.c,v 1.36 2002/04/29 04:20:56 sommerfeld Exp $");
__RCSID("$NetBSD: crunchgen.c,v 1.37 2002/05/02 21:18:31 sommerfeld Exp $");
#endif
#if HAVE_CONFIG_H
@ -114,7 +114,7 @@ int is_nonempty_file(char *pathname);
/* helper routines for main() */
void usage(void);
void usage(void);
void parse_conf_file(void);
void gen_outputs(void);
@ -145,7 +145,7 @@ int main(int argc, char **argv)
readcache = 1;
useobjs = 0;
*outmkname = *outcfname = *execfname = '\0';
if(argc > 0) pname = argv[0];
while((optc = getopt(argc, argv, "m:c:d:e:foqD:L:")) != -1) {
@ -172,7 +172,7 @@ int main(int argc, char **argv)
if(argc != 1) usage();
/*
/*
* generate filenames
*/
@ -202,7 +202,7 @@ int main(int argc, char **argv)
void usage(void)
{
fprintf(stderr,
fprintf(stderr,
"%s [-fq] [-m <makefile>] [-c <c file>] [-e <exec file>] <conffile>\n",
pname);
exit(1);
@ -218,7 +218,7 @@ void usage(void)
/* helper routines for parse_conf_file */
void parse_one_file(char *filename);
void parse_line(char *line, int *fc, char **fv, int nf);
void parse_line(char *line, int *fc, char **fv, int nf);
void add_srcdirs(int argc, char **argv);
void add_progs(int argc, char **argv);
void add_link(int argc, char **argv);
@ -278,7 +278,7 @@ void parse_one_file(char *filename)
continue;
}
if(fieldc < 2) {
fprintf(stderr,
fprintf(stderr,
"%s:%d: %s command needs at least 1 argument, skipping.\n",
curfilename, linenum, fieldv[0]);
goterror = 1;
@ -330,7 +330,7 @@ void add_srcdirs(int argc, char **argv)
if(is_dir(tmppath))
add_string(&srcdirs, tmppath);
else {
fprintf(stderr, "%s:%d: `%s' is not a directory, skipping it.\n",
fprintf(stderr, "%s:%d: `%s' is not a directory, skipping it.\n",
curfilename, linenum, tmppath);
goterror = 1;
}
@ -358,7 +358,7 @@ void add_prog(char *progname)
p2 = malloc(sizeof(prog_t));
if(p2) p2->name = strdup(progname);
if(!p2 || !p2->name)
if(!p2 || !p2->name)
out_of_memory();
p2->next = NULL;
@ -377,7 +377,7 @@ void add_link(int argc, char **argv)
prog_t *p = find_prog(argv[1]);
if(p == NULL) {
fprintf(stderr,
fprintf(stderr,
"%s:%d: no prog %s previously declared, skipping link.\n",
curfilename, linenum, argv[1]);
goterror = 1;
@ -404,7 +404,7 @@ void add_special(int argc, char **argv)
if(p == NULL) {
if(reading_cache) return;
fprintf(stderr,
fprintf(stderr,
"%s:%d: no prog %s previously declared, skipping special.\n",
curfilename, linenum, argv[1]);
goterror = 1;
@ -459,7 +459,7 @@ void add_special(int argc, char **argv)
argcount:
fprintf(stderr,
fprintf(stderr,
"%s:%d: too %s arguments, expected \"special %s %s <string>\".\n",
curfilename, linenum, argc < 4? "few" : "many", argv[1], argv[2]);
goterror = 1;
@ -511,7 +511,7 @@ void gen_outputs(void)
gen_output_cfile();
gen_output_makefile();
status("");
fprintf(stderr,
fprintf(stderr,
"Run \"make -f %s objs exe\" to build crunched binary.\n",
outmkname);
}
@ -526,7 +526,7 @@ void fillin_program(prog_t *p)
(void)snprintf(line, sizeof(line), "filling in parms for %s", p->name);
status(line);
if(!p->ident)
if(!p->ident)
p->ident = genident(p->name);
if(!p->srcdir) {
srcparent = dir_search(p->name);
@ -575,16 +575,16 @@ void fillin_program(prog_t *p)
}
}
}
if(!p->srcdir && verbose)
fprintf(stderr, "%s: %s: warning: could not find source directory.\n",
infilename, p->name);
if(!p->objs && verbose)
fprintf(stderr, "%s: %s: warning: could not find any .o files.\n",
fprintf(stderr, "%s: %s: warning: could not find any .o files.\n",
infilename, p->name);
if(!p->objpaths) {
fprintf(stderr,
fprintf(stderr,
"%s: %s: error: no objpaths specified or calculated.\n",
infilename, p->name);
p->goterror = goterror = 1;
@ -612,7 +612,7 @@ void fillin_program_objs(prog_t *p, char *dirpath)
goterror = 1;
return;
}
fprintf(f, ".include \"${.CURDIR}/Makefile\"\n");
fprintf(f, ".if defined(PROG)\n");
fprintf(f, "OBJS?= ${PROG}.o\n");
@ -636,7 +636,7 @@ void fillin_program_objs(prog_t *p, char *dirpath)
"sh: warning: running as root with dot in PATH\n") == 0)
continue;
fprintf(stderr, "make error: %s", line);
goterror = 1;
goterror = 1;
continue;
}
cp = line + 6;
@ -660,8 +660,8 @@ void remove_error_progs(void)
{
prog_t *p1, *p2;
p1 = NULL; p2 = progs;
while(p2 != NULL) {
p1 = NULL; p2 = progs;
while(p2 != NULL) {
if(!p2->goterror)
p1 = p2, p2 = p2->next;
else {
@ -729,7 +729,7 @@ void gen_output_makefile(void)
top_makefile_rules(outmk);
for(p = progs; p != NULL; p = p->next)
prog_makefile_rules(outmk, p);
prog_makefile_rules(outmk, p);
fprintf(outmk, "\n.include <bsd.prog.mk>\n");
fprintf(outmk, "\n# ========\n");
@ -753,7 +753,7 @@ void gen_output_cfile(void)
return;
}
fprintf(outcf,
fprintf(outcf,
"/* %s - generated from %s by crunchgen %s */\n",
outcfname, infilename, CRUNCH_VERSION);
@ -772,7 +772,7 @@ void gen_output_cfile(void)
fprintf(outcf, "\t{ \"%s\", _crunched_%s_stub },\n",
s->str, p->ident);
}
fprintf(outcf, "\t{ EXECNAME, crunched_main },\n");
fprintf(outcf, "\t{ NULL, NULL }\n};\n");
fclose(outcf);
@ -835,7 +835,7 @@ void top_makefile_rules(FILE *outmk)
fprintf(outmk, "LDADD+= ${CRUNCHED_OBJS} ");
output_strlst(outmk, libs);
fprintf(outmk, "CRUNCHEDOBJSDIRS=${CRUNCHED_OBJS:R}\n\n");
fprintf(outmk, "SUBMAKE_TARGETS=");
for(p = progs; p != NULL; p = p->next)
fprintf(outmk, " %s_make", p->ident);
@ -843,7 +843,7 @@ void top_makefile_rules(FILE *outmk)
fprintf(outmk, "PROG=%s\n", execfname);
fprintf(outmk, "MKMAN=no\n\n");
fprintf(outmk, "all: ${PROG}\n\t${STRIP} ${PROG}\n");
fprintf(outmk, "objs: $(SUBMAKE_TARGETS)\n");
fprintf(outmk, "exe: %s\n", execfname);
@ -865,17 +865,18 @@ void prog_makefile_rules(FILE *outmk, prog_t *p)
fprintf(outmk, "%s_SRCDIR=%s\n", p->ident, p->srcdir);
fprintf(outmk, "%s_OBJS=", p->ident);
output_strlst(outmk, p->objs);
fprintf(outmk, "%s_make: ${%s_OBJPATHS}\n", p->ident, p->ident);
fprintf(outmk, "${%s_OBJPATHS}: \n", p->ident);
fprintf(outmk, "\tif [ \\! -d %s ]; then mkdir %s; fi; cd %s; \\\n",
p->ident, p->ident, p->ident);
fprintf(outmk, "%s_directory::\n", p->ident);
fprintf(outmk, "\t[ -d %s ] || mkdir %s\n", p->ident, p->ident);
fprintf(outmk, "%s_make:: .MAKE %s_directory\n", p->ident, p->ident);
fprintf(outmk, "\tcd %s; \\\n", p->ident);
fprintf(outmk, "\tprintf \".PATH: ${%s_SRCDIR}\\n.CURDIR:= ${%s_SRCDIR}\\n"
".include \\\"\\$${.CURDIR}/Makefile\\\"\\n\" \\\n", p->ident, p->ident);
fprintf(outmk, "\t| ${MAKE} CRUNCHEDPROG=1 DBG=\"${DBG}\" -f- depend ${%s_OBJS}\n\n",
p->ident);
fprintf(outmk, "${%s_OBJPATHS}:: %s_make\n", p->ident, p->ident);
}
else
fprintf(outmk, "%s_make:\n\t@echo \"** Using existing objs for %s\"\n\n",
fprintf(outmk, "%s_make:\n\t@echo \"** Using existing objs for %s\"\n\n",
p->ident, p->name);
@ -890,7 +891,7 @@ void prog_makefile_rules(FILE *outmk, prog_t *p)
else
fprintf(outmk, "%s.cro: %s_stub.o ${%s_OBJPATHS}\n",
p->name, p->name, p->ident);
fprintf(outmk, "\t${LD} -dc -r -o %s.cro %s_stub.o $(%s_OBJPATHS)\n",
fprintf(outmk, "\t${LD} -dc -r -o %s.cro %s_stub.o $(%s_OBJPATHS)\n",
p->name, p->name, p->ident);
#ifdef NEW_TOOLCHAIN
fprintf(outmk, "\t${OBJCOPY} --keep-global-symbol _crunched_%s_stub ",