Subject: Re: bmake and bootstrap and own.mk and MKCONF
To: None <tech-pkg@netbsd.org>
From: Joerg Sonnenberger <joerg@britannica.bec.de>
List: tech-pkg
Date: 09/30/2005 12:15:55
--nFreZHaLTZJo0R7j
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Thu, Sep 22, 2005 at 08:19:09PM -0700, Simon J. Gerraty wrote:
> My preference is to only add functionality to make.  
> Thus, the only difference b/w make and bmake should be those needed to
> support autoconf.  Send me the diffs and I'll take a look.

Can I please commit the attached patch as interim solution for
DragonFly? It is a direct merge from src/usr.bin/make and is an
alternate and more portable fix for pkg/30319. It means we can take the
time to fix bmake on !NetBSD properly.

Joerg

--nFreZHaLTZJo0R7j
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="bmake.diff"

Index: main.c
===================================================================
RCS file: /repo/netbsd/pkgsrc/bootstrap/bmake/main.c,v
retrieving revision 1.2
diff -u -r1.2 main.c
--- main.c	5 Jan 2005 21:54:40 -0000	1.2
+++ main.c	29 Sep 2005 15:58:32 -0000
@@ -194,6 +194,11 @@
 	char **argv;
 {
 	char *p;
+	int arginc;
+	char *argvalue;
+	const char *getopt_def;
+	char *optscan;
+	Boolean inOption;
 	int c;
 
 	if (argv[0] == 0)
@@ -205,8 +210,49 @@
 #else
 # define OPTFLAGS "BD:I:J:NPST:V:Wd:ef:ij:km:nqrst"
 #endif
-rearg:	while((c = getopt(argc, argv, OPTFLAGS)) != -1) {
+#undef optarg
+#define optarg argvalue	
+/* Can't actually use getopt(3) because rescanning is not portable */
+
+	getopt_def = OPTFLAGS;
+rearg:	
+	inOption = FALSE;
+	while(argc > 1) {
+		char *getopt_spec;
+		if(!inOption)
+			optscan = argv[1];
+		c = *optscan++;
+		arginc = 0;
+		if(inOption) {
+			if(c == '\0') {
+				++argv;
+				--argc;
+				inOption = FALSE;
+				continue;
+			}
+		} else {
+			if (c != '-')
+				break;
+			inOption = TRUE;
+			c = *optscan++;
+		}
+		/* '-' found at some earlier point */
+		getopt_spec = strchr(getopt_def, c);
+		if(c != '\0' && getopt_spec != NULL && getopt_spec[1] == ':') {
+			/* -<something> found, and <something> should have an arg */
+			inOption = FALSE;
+			arginc = 1;
+			argvalue = optscan;
+			if(*argvalue == '\0') {
+				argvalue = argv[2];
+				arginc = 2;
+			}
+		}
 		switch(c) {
+		case '\0':
+			arginc = 1;
+			inOption = FALSE;
+			break;
 		case 'D':
 			Var_Set(optarg, "1", VAR_GLOBAL, 0);
 			Var_Append(MAKEFLAGS, "-D", VAR_GLOBAL);
@@ -404,6 +450,8 @@
 #endif
 			usage();
 		}
+		argv += arginc;
+		argc -= arginc;
 	}
 
 	oldVars = TRUE;
@@ -413,20 +461,15 @@
 	 * perform them if so. Else take them to be targets and stuff them
 	 * on the end of the "create" list.
 	 */
-	for (argv += optind, argc -= optind; *argv; ++argv, --argc)
-		if (Parse_IsVar(*argv)) {
-			Parse_DoVar(*argv, VAR_CMD);
+	for (; argc > 1; ++argv, --argc)
+		if (Parse_IsVar(argv[1])) {
+			Parse_DoVar(argv[1], VAR_CMD);
 		} else {
-			if (!**argv)
+			if (!*argv[1])
 				Punt("illegal (null) argument.");
-			if (**argv == '-') {
-				if ((*argv)[1])
-					optind = 0;     /* -flag... */
-				else
-					optind = 1;     /* - */
+			if (*argv[1] == '-')
 				goto rearg;
-			}
-			(void)Lst_AtEnd(create, (ClientData)estrdup(*argv));
+			(void)Lst_AtEnd(create, (ClientData)estrdup(argv[1]));
 		}
 }
 

--nFreZHaLTZJo0R7j--