diff options
author | luigi <luigi@FreeBSD.org> | 2000-02-05 10:29:19 +0000 |
---|---|---|
committer | luigi <luigi@FreeBSD.org> | 2000-02-05 10:29:19 +0000 |
commit | de5e1b620a0b99a65cbd75dfc5f1708b5535b8ee (patch) | |
tree | c6eaf9d2952a4feb832c089328b9ec53c95cc7fa /usr.sbin/crunch/crunchgen | |
parent | 1ed4e27f18edf2f6a9610dca3466a4819ecb375f (diff) | |
download | FreeBSD-src-de5e1b620a0b99a65cbd75dfc5f1708b5535b8ee.zip FreeBSD-src-de5e1b620a0b99a65cbd75dfc5f1708b5535b8ee.tar.gz |
Add a few features to crunchgen to simplify the use of existing
makefiles (for use with picobsd among other things).
See the manpage for details, but:
* -h makefile-include-name
can be used to specify a file to include in the makefiles
generated by crunchgen . This is a good place to specify make
variables such as RELEASE_CRUNCH, NOTHIS, NOTHAT and the like.
* special progname objvar variable_name
in the crunch config file declares a different variable than
OBJS to be used to get the list of objects.
* crunchgen now looks first for Makefile.<progname> in the current
directory to override the makefile in <progname> source dir.
This in many cases avoids the need to patch the original makefile
if the above two features are still not enough.
Approved-By: jordan
Diffstat (limited to 'usr.sbin/crunch/crunchgen')
-rw-r--r-- | usr.sbin/crunch/crunchgen/crunchgen.1 | 18 | ||||
-rw-r--r-- | usr.sbin/crunch/crunchgen/crunchgen.c | 51 |
2 files changed, 60 insertions, 9 deletions
diff --git a/usr.sbin/crunch/crunchgen/crunchgen.1 b/usr.sbin/crunch/crunchgen/crunchgen.1 index f01ee2a..0aec659 100644 --- a/usr.sbin/crunch/crunchgen/crunchgen.1 +++ b/usr.sbin/crunch/crunchgen/crunchgen.1 @@ -33,6 +33,7 @@ .Sh SYNOPSIS .Nm \&crunchgen .Op Fl fql +.Op Fl h Ar makefile-header-name .Op Fl m Ar makefile-name .Op Fl c Ar c-file-name .Op Fl e Ar exec-file-name @@ -89,6 +90,14 @@ The default name is ``<conf-name>''. Flush cache. Forces the recalculation of cached parameters. .It Fl l List names. Lists the names this binary will respond to. +.It Fl h Ar makefile-header-name +Set the name of a file to be included at the beginning of the +Makefiles generated by +.Nm crunchgen . +This is useful to define some make variables such as +.Ar RELEASE_CRUNCH +or similar, which might affect the behaviour of make and +are annoying to pass through environment variables. .It Fl m Ar makefile-name Set output Makefile name to .Ar makefile-name . @@ -179,6 +188,15 @@ This is normally calculated by prepending the pathname to each file in the .Nm objs list. +.It Nm special Ar progname Nm objvar Ar variable_name +Sets the name of the Make variable which holds the list of +object files for program +.Ar progname . +This is normally +.Nm OBJS +but some Makefiles might like to use other conventions or +prepend the program's name to the variable, e.g. +.Nm SSHD_OBJS . .It Nm special Ar progname Nm keep Ar symbol-name ... Add specified list of symbols to the keep list for program .Ar progname . diff --git a/usr.sbin/crunch/crunchgen/crunchgen.c b/usr.sbin/crunch/crunchgen/crunchgen.c index 8998ea4..be25005 100644 --- a/usr.sbin/crunch/crunchgen/crunchgen.c +++ b/usr.sbin/crunch/crunchgen/crunchgen.c @@ -22,6 +22,8 @@ * Author: James da Silva, Systems Design and Analysis Group * Computer Science Department * University of Maryland at College Park + * + * $FreeBSD$ */ /* * ======================================================================== @@ -59,9 +61,12 @@ typedef struct strlst { /* progs have structure, each field can be set with "special" or calculated */ typedef struct prog { - struct prog *next; - char *name, *ident; - char *srcdir, *objdir; + struct prog *next; /* link field */ + char *name; /* program name */ + char *ident; /* C identifier for the program name */ + char *srcdir; + char *objdir; + char *objvar; /* Makefile variable to replace OBJS */ strlst_t *objs, *objpaths; strlst_t *keeplist; strlst_t *links; @@ -80,6 +85,7 @@ char line[MAXLINELEN]; char confname[MAXPATHLEN], infilename[MAXPATHLEN]; char outmkname[MAXPATHLEN], outcfname[MAXPATHLEN], execfname[MAXPATHLEN]; char tempfname[MAXPATHLEN], cachename[MAXPATHLEN], curfilename[MAXPATHLEN]; +char outhdrname[MAXPATHLEN] ; /* user-supplied header for *.mk */ int linenum = -1; int goterror = 0; @@ -112,12 +118,13 @@ int main(int argc, char **argv) readcache = 1; *outmkname = *outcfname = *execfname = '\0'; - while((optc = getopt(argc, argv, "lm:c:e:fq")) != -1) { + while((optc = getopt(argc, argv, "lh:m:c:e:fq")) != -1) { switch(optc) { case 'f': readcache = 0; break; case 'q': verbose = 0; break; case 'm': strcpy(outmkname, optarg); break; + case 'h': strcpy(outhdrname, optarg); break; case 'c': strcpy(outcfname, optarg); break; case 'e': strcpy(execfname, optarg); break; case 'l': list_mode++; verbose = 0; break; @@ -400,6 +407,12 @@ void add_special(int argc, char **argv) for(i=3;i<argc;i++) add_string(&p->keeplist, argv[i]); } + else if(!strcmp(argv[2], "objvar")) { + if(argc != 4) + goto argcount; + if((p->objvar = strdup(argv[3])) == NULL) + out_of_memory(); + } else { warnx("%s:%d: bad parameter name `%s', skipping line", curfilename, linenum, argv[2]); @@ -465,7 +478,9 @@ void gen_outputs(void) outmkname); } - +/* + * run the makefile for the program to find which objects are necessary + */ void fillin_program(prog_t *p) { char path[MAXPATHLEN]; @@ -498,7 +513,15 @@ void fillin_program(prog_t *p) } } } - +/* + * XXX look for a Makefile.{name} in local directory first. + * This lets us override the original Makefile. + */ + sprintf(path, "Makefile.%s", p->name); + if (is_nonempty_file(path)) { + sprintf(line, "Using %s for %s", path, p->name); + status(line); + } else if(p->srcdir) sprintf(path, "%s/Makefile", p->srcdir); if(!p->objs && p->srcdir && is_nonempty_file(path)) fillin_program_objs(p, path); @@ -528,6 +551,7 @@ void fillin_program_objs(prog_t *p, char *path) char *obj, *cp; int rc; FILE *f; + char *objvar="OBJS"; /* discover the objs from the srcdir Makefile */ @@ -536,12 +560,19 @@ void fillin_program_objs(prog_t *p, char *path) goterror = 1; return; } + if (p->objvar) + objvar = p->objvar ; + /* + * XXX include outhdrname (e.g. to contain Make variables) + */ + if (outhdrname[0] != '\0') + fprintf(f, ".include \"%s\"\n", outhdrname); fprintf(f, ".include \"%s\"\n", path); - fprintf(f, ".if defined(PROG) && !defined(OBJS)\n"); - fprintf(f, "OBJS=${PROG}.o\n"); + fprintf(f, ".if defined(PROG) && !defined(%s)\n", objvar); + fprintf(f, "%s=${PROG}.o\n", objvar); fprintf(f, ".endif\n"); - fprintf(f, "crunchgen_objs:\n\t@echo 'OBJS= '${OBJS}\n"); + fprintf(f, "crunchgen_objs:\n\t@echo 'OBJS= '${%s}\n", objvar); fclose(f); sprintf(line, "make -f %s crunchgen_objs 2>&1", tempfname); @@ -643,6 +674,8 @@ void gen_output_makefile(void) fprintf(outmk, "# %s - generated from %s by crunchgen %s\n\n", outmkname, infilename, CRUNCH_VERSION); + if (outhdrname[0] != '\0') + fprintf(outmk, ".include \"%s\"\n", outhdrname); top_makefile_rules(outmk); |