From nobody@FreeBSD.org  Thu Jan 10 18:28:15 2002
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 825EA37B404
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 10 Jan 2002 18:28:14 -0800 (PST)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.6/8.11.6) id g0B2SEr89565;
	Thu, 10 Jan 2002 18:28:14 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200201110228.g0B2SEr89565@freefall.freebsd.org>
Date: Thu, 10 Jan 2002 18:28:14 -0800 (PST)
From: Sam Leffler <sam@errno.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: crunchgen enhancements
X-Send-Pr-Version: www-1.0

>Number:         33778
>Category:       bin
>Synopsis:       [patch] crunchgen enhancements
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    linimon
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jan 10 18:30:01 PST 2002
>Closed-Date:    Mon Apr 17 23:31:03 GMT 2006
>Last-Modified:  Mon Apr 17 23:31:03 GMT 2006
>Originator:     Sam Leffler
>Release:        4.5-PRERELEASE
>Organization:
>Environment:
>Description:
crunchgen is hard to use for certain programs because you can't specify per-prog libraries to link into the .lo.  An example is dhcpd in ISC DHCP v3.0.1r4.  Included is a change to crunchgen.c that implements

special <prog> lib <pathname>

Also included is a "hack" to permit passing make variables through to the generated .mk file.  This lets you, for example, specify common pathnames in one place.
>How-To-Repeat:
      
>Fix:
cut&paste will ruin this diff so you'll probably want to ask me to send it by mail.

RCS file: /usr/ncvs/src/usr.sbin/crunch/crunchgen/crunchgen.c,v
retrieving revision 1.12.2.9
diff -r1.12.2.9 crunchgen.c
75a76
>       strlst_t *libs;
85a87
> strlst_t *vars      = NULL;
241a244
> void add_var(int argc, char **argv);
295a299,300
>               else if(!strcmp(fieldv[0], "var"))
>                       f = add_var;
411a417
>       p2->libs = NULL;
457a464,472
> void add_var(int argc, char **argv)
> {
>       int i;
> 
>       for (i = 1; i < argc; i++) 
>               add_string(&vars, argv[i]);
> }
> 
> 
508a524,526
>       } else if (!strcmp(argv[2], "lib")) {
>               for (i = 3; i < argc; i++)
>                       add_string(&p->libs, argv[i]);
580a599
>       strlst_t *s;
595c614,620
<               snprintf(line, MAXLINELEN, "cd %s && echo -n `/bin/pwd`",
---
>               char *cp = line;
>               for (s = vars; s != NULL; s = s->next) {
>                       snprintf(cp, MAXLINELEN - (cp-line), "%s;", s->str);
>                       cp = strchr(cp, '\0');
>               }
>               snprintf(cp, MAXLINELEN - (cp-line),
>                   "cd %s && echo -n `/bin/pwd`",
635c660
<                       snprintf(path, sizeof(path), "%s/Makefile", p->srcdir);
---
>                       snprintf(path, sizeof(path), "%s/Makefile", p->realsrcdir);
679a705,706
>       for (s = vars; s != NULL; s = s->next)
>               fprintf(f, "%s\n", s->str);
916a944,947
>       strlst_t *s;
> 
>       for (s = vars; s != NULL; s = s->next)
>               fprintf(outmk, "%s\n", s->str);
1012a1044,1047
>       if (p->libs) {
>               fprintf(outmk, "%s_LIBS=", p->ident);
>               output_strlst(outmk, p->libs);
>       }
1019c1054
<       fprintf(outmk, "%s.lo: %s_stub.o $(%s_OBJPATHS)\n",
---
>       fprintf(outmk, "%s.lo: %s_stub.o $(%s_OBJPATHS)",
1021c1056,1059
<       fprintf(outmk, "\tld -dc -r -o %s.lo %s_stub.o $(%s_OBJPATHS)\n",
---
>       if (p->libs)
>               fprintf(outmk, " $(%s_LIBS)", p->ident);
>       fprintf(outmk, "\n");
>       fprintf(outmk, "\tld -dc -r -o %s.lo %s_stub.o $(%s_OBJPATHS)",
1022a1061,1063
>       if (p->libs)
>               fprintf(outmk, " $(%s_LIBS)", p->ident);
>       fprintf(outmk, "\n");

    
>Release-Note:
>Audit-Trail:

From: Josef Karthauser <joe@tao.org.uk>
To: Sam Leffler <sam@errno.com>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: misc/33778: crunchgen enhancements
Date: Fri, 11 Jan 2002 13:47:55 +0000

 --cO2ZlOvi7VNgmdOy
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 Can you please resubmit your patch as a unified one.  (with the -u flag
 to diff.)
 
 Thanks,
 Joe
 
 --cO2ZlOvi7VNgmdOy
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.0.6 (FreeBSD)
 Comment: For info see http://www.gnupg.org
 
 iEYEARECAAYFAjw+7QoACgkQXVIcjOaxUBbohwCghFRaMXZ81gQnoM2LMuWOUkbQ
 46UAoJUY8IOpgeE7qdbMIqemGCay2qpS
 =gJ+C
 -----END PGP SIGNATURE-----
 
 --cO2ZlOvi7VNgmdOy--

From: "Sam Leffler" <sam@errno.com>
To: "Josef Karthauser" <joe@tao.org.uk>
Cc: <freebsd-gnats-submit@FreeBSD.org>
Subject: Re: misc/33778: crunchgen enhancements
Date: Fri, 11 Jan 2002 14:51:05 -0800

 This is a multi-part message in MIME format.
 
 ------=_NextPart_000_1A08_01C19AAF.652CBE70
 Content-Type: text/plain;
 	charset="iso-8859-1"
 Content-Transfer-Encoding: 7bit
 
 cvs diff -u is attached.
 
 ------=_NextPart_000_1A08_01C19AAF.652CBE70
 Content-Type: application/octet-stream;
 	name="crunch.diff"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment;
 	filename="crunch.diff"
 
 Index: crunchgen.c=0A=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
 RCS file: /usr/ncvs/src/usr.sbin/crunch/crunchgen/crunchgen.c,v=0A=
 retrieving revision 1.12.2.9=0A=
 diff -u -r1.12.2.9 crunchgen.c=0A=
 --- crunchgen.c	19 Aug 2001 10:41:57 -0000	1.12.2.9=0A=
 +++ crunchgen.c	11 Jan 2002 01:52:58 -0000=0A=
 @@ -73,6 +73,7 @@=0A=
  	strlst_t *buildopts;=0A=
  	strlst_t *keeplist;=0A=
  	strlst_t *links;=0A=
 +	strlst_t *libs;=0A=
  	int goterror;=0A=
  } prog_t;=0A=
  =0A=
 @@ -83,6 +84,7 @@=0A=
  strlst_t *srcdirs   =3D NULL;=0A=
  strlst_t *libs      =3D NULL;=0A=
  prog_t   *progs     =3D NULL;=0A=
 +strlst_t *vars      =3D NULL;=0A=
  =0A=
  char confname[MAXPATHLEN], infilename[MAXPATHLEN];=0A=
  char outmkname[MAXPATHLEN], outcfname[MAXPATHLEN], =
 execfname[MAXPATHLEN];=0A=
 @@ -239,6 +241,7 @@=0A=
  void add_libs(int argc, char **argv);=0A=
  void add_buildopts(int argc, char **argv);=0A=
  void add_special(int argc, char **argv);=0A=
 +void add_var(int argc, char **argv);=0A=
  =0A=
  prog_t *find_prog(char *str);=0A=
  void add_prog(char *progname);=0A=
 @@ -293,6 +296,8 @@=0A=
  			f =3D add_libs;=0A=
  		else if(!strcmp(fieldv[0], "buildopts"))=0A=
  			f =3D add_buildopts;=0A=
 +		else if(!strcmp(fieldv[0], "var"))=0A=
 +			f =3D add_var;=0A=
  		else if(!strcmp(fieldv[0], "special"))=0A=
  			f =3D add_special;=0A=
  		else {=0A=
 @@ -409,6 +414,7 @@=0A=
  	p2->objs =3D NULL;=0A=
  	p2->keeplist =3D NULL;=0A=
  	p2->buildopts =3D NULL;=0A=
 +	p2->libs =3D NULL;=0A=
  	p2->goterror =3D 0;=0A=
  =0A=
  	if (list_mode)=0A=
 @@ -455,6 +461,15 @@=0A=
  }=0A=
  =0A=
  =0A=
 +void add_var(int argc, char **argv)=0A=
 +{=0A=
 +	int i;=0A=
 +=0A=
 +	for (i =3D 1; i < argc; i++) =0A=
 +		add_string(&vars, argv[i]);=0A=
 +}=0A=
 +=0A=
 +=0A=
  void add_special(int argc, char **argv)=0A=
  {=0A=
  	int i;=0A=
 @@ -506,6 +521,9 @@=0A=
  		p->buildopts =3D NULL;=0A=
  		for (i =3D 3; i < argc; i++)=0A=
  			add_string(&p->buildopts, argv[i]);=0A=
 +	} else if (!strcmp(argv[2], "lib")) {=0A=
 +		for (i =3D 3; i < argc; i++)=0A=
 +			add_string(&p->libs, argv[i]);=0A=
  	} else {=0A=
  		warnx("%s:%d: bad parameter name `%s', skipping line",=0A=
  		    curfilename, linenum, argv[2]);=0A=
 @@ -578,6 +596,7 @@=0A=
  	char path[MAXPATHLEN];=0A=
  	char line[MAXLINELEN];=0A=
  	FILE *f;=0A=
 +	strlst_t *s;=0A=
  =0A=
  	snprintf(line, MAXLINELEN, "filling in parms for %s", p->name);=0A=
  	status(line);=0A=
 @@ -592,7 +611,13 @@=0A=
  =0A=
  	/* Determine the actual srcdir (maybe symlinked). */=0A=
  	if (p->srcdir) {=0A=
 -		snprintf(line, MAXLINELEN, "cd %s && echo -n `/bin/pwd`",=0A=
 +		char *cp =3D line;=0A=
 +		for (s =3D vars; s !=3D NULL; s =3D s->next) {=0A=
 +			snprintf(cp, MAXLINELEN - (cp-line), "%s;", s->str);=0A=
 +			cp =3D strchr(cp, '\0');=0A=
 +		}=0A=
 +		snprintf(cp, MAXLINELEN - (cp-line),=0A=
 +		    "cd %s && echo -n `/bin/pwd`",=0A=
  		    p->srcdir);=0A=
  		f =3D popen(line,"r");=0A=
  		if (!f)=0A=
 @@ -632,7 +657,7 @@=0A=
  		status(line);=0A=
  	} else=0A=
  		if (p->srcdir)=0A=
 -			snprintf(path, sizeof(path), "%s/Makefile", p->srcdir);=0A=
 +			snprintf(path, sizeof(path), "%s/Makefile", p->realsrcdir);=0A=
  	if (!p->objs && p->srcdir && is_nonempty_file(path))=0A=
  		fillin_program_objs(p, path);=0A=
  =0A=
 @@ -677,6 +702,8 @@=0A=
  	if (outhdrname[0] !=3D '\0')=0A=
  		fprintf(f, ".include \"%s\"\n", outhdrname);=0A=
  	fprintf(f, ".include \"%s\"\n", path);=0A=
 +	for (s =3D vars; s !=3D NULL; s =3D s->next)=0A=
 +		fprintf(f, "%s\n", s->str);=0A=
  	if (buildopts) {=0A=
  		fprintf(f, "BUILDOPTS+=3D");=0A=
  		output_strlst(f, buildopts);=0A=
 @@ -914,6 +941,10 @@=0A=
  void top_makefile_rules(FILE *outmk)=0A=
  {=0A=
  	prog_t *p;=0A=
 +	strlst_t *s;=0A=
 +=0A=
 +	for (s =3D vars; s !=3D NULL; s =3D s->next)=0A=
 +		fprintf(outmk, "%s\n", s->str);=0A=
  =0A=
  	fprintf(outmk, "LIBS+=3D");=0A=
  	output_strlst(outmk, libs);=0A=
 @@ -1010,16 +1041,26 @@=0A=
  		}=0A=
  		fprintf(outmk, "\n");=0A=
  	}=0A=
 +	if (p->libs) {=0A=
 +		fprintf(outmk, "%s_LIBS=3D", p->ident);=0A=
 +		output_strlst(outmk, p->libs);=0A=
 +	}=0A=
  =0A=
  	fprintf(outmk, "%s_stub.c:\n", p->name);=0A=
  	fprintf(outmk, "\techo \""=0A=
  	    "int _crunched_%s_stub(int argc, char **argv, char **envp)"=0A=
  	    "{return main(argc,argv,envp);}\" >%s_stub.c\n",=0A=
  	    p->ident, p->name);=0A=
 -	fprintf(outmk, "%s.lo: %s_stub.o $(%s_OBJPATHS)\n",=0A=
 +	fprintf(outmk, "%s.lo: %s_stub.o $(%s_OBJPATHS)",=0A=
  	    p->name, p->name, p->ident);=0A=
 -	fprintf(outmk, "\tld -dc -r -o %s.lo %s_stub.o $(%s_OBJPATHS)\n",=0A=
 +	if (p->libs)=0A=
 +		fprintf(outmk, " $(%s_LIBS)", p->ident);=0A=
 +	fprintf(outmk, "\n");=0A=
 +	fprintf(outmk, "\tld -dc -r -o %s.lo %s_stub.o $(%s_OBJPATHS)",=0A=
  	    p->name, p->name, p->ident);=0A=
 +	if (p->libs)=0A=
 +		fprintf(outmk, " $(%s_LIBS)", p->ident);=0A=
 +	fprintf(outmk, "\n");=0A=
  	fprintf(outmk, "\tcrunchide -k _crunched_%s_stub ", p->ident);=0A=
  	for (lst =3D p->keeplist; lst !=3D NULL; lst =3D lst->next)=0A=
  		fprintf(outmk, "-k _%s ", lst->str);=0A=
 
 ------=_NextPart_000_1A08_01C19AAF.652CBE70--
 
Responsible-Changed-From-To: freebsd-bugs->joe 
Responsible-Changed-By: joe 
Responsible-Changed-When: Sat Jan 26 03:50:32 PST 2002 
Responsible-Changed-Why:  
I'll take this one. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=33778 
State-Changed-From-To: open->feedback 
State-Changed-By: linimon 
State-Changed-When: Mon Apr 17 19:44:09 UTC 2006 
State-Changed-Why:  
Did this patch ever get incorporated? 


Responsible-Changed-From-To: joe->linimon 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Mon Apr 17 19:44:09 UTC 2006 
Responsible-Changed-Why:  
joe has returned his bit for safekeeping due to lack of time. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=33778 
State-Changed-From-To: feedback->closed 
State-Changed-By: sam 
State-Changed-When: Mon Apr 17 23:30:37 UTC 2006 
State-Changed-Why:  
committed as rev 1.31 3/30/200 

http://www.freebsd.org/cgi/query-pr.cgi?pr=33778 
>Unformatted:
