Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Jul 2002 15:59:23 +0200
From:      Cyrille Lefevre <cyrille.lefevre@laposte.net>
To:        Ruslan Ermilov <ru@FreeBSD.ORG>
Cc:        Bruce Evans <bde@zeta.org.au>, Doug Barton <DougB@FreeBSD.ORG>, Mike Barcroft <mike@FreeBSD.ORG>, arch@FreeBSD.ORG, Juli Mallett <jmallett@FreeBSD.ORG>
Subject:   Re: Standardized make options (or no doesn't always mean no)
Message-ID:  <20020726135923.GA89959@gits.dyndns.org>
In-Reply-To: <20020725170940.GA40574@sunbay.com>
References:  <3D02AB11.F373AB4@FreeBSD.org> <20020609123557.X21758-100000@gamplex.bde.org> <20020725070145.GE56367@sunbay.com> <20020725165940.GF58642@gits.dyndns.org> <20020725170940.GA40574@sunbay.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Jul 25, 2002 at 08:09:40PM +0300, Ruslan Ermilov wrote:
> On Thu, Jul 25, 2002 at 06:59:40PM +0200, Cyrille Lefevre wrote:
> > On Thu, Jul 25, 2002 at 10:01:45AM +0300, Ruslan Ermilov wrote:
[snip]
> > > We'd provide the compatibility knobs that would also trigger a warning
> > > (a .warning to be added to make(1)) that NO_FOO should now be used
> > > instead of NOFOO (or vice versa, if we decide to go that way).
> > 
> > .warning isn't needed, let's try w/ .BEGIN :)

well, il fact, a .warning is needed for the newer knob because
it seems you can't do something like this :

.for something
.BEGIN:
	something
.endfor

nor

.for something
targets+= ${something}
pseudo_target:
	something
.endfor

.BEGIN: ${something}

nor

.for something
pseudo_target: .USE
	something
.endfor

.BEGIN: pseudo_target

[snip]
> > I'll try to make another knob for variable conversion such as :
> > NOALIAS -> PPP_NO_ALIAS, etc.

here is the newer knob which is more universal than the first one +
some patches to make... also, a set of command to help the transition :)

OLDBAD=	true
NEWGOOD=true
OLDWARN=true
NEWWARN=true
OLDERR=	true
NEWERR=	false

NOBAD=	true
NO_GOOD=true
NOWARN=	true
NO_WARN=true
NOERR=	true
NO_ERR=	false

_ASSOC_VARS=	OLDBAD NEWBAD OLDGOOD NEWGOOD OLDWARN NEWWARN OLDERR NEWERR
_NO_VARS=	BAD GOOD WARN ERR

.for _var in ${_NO_VARS}
_ASSOC_VARS+=	NO${_var} NO_${_var}
.endfor

_old=
.for _new in ${_ASSOC_VARS}
. if empty(_old)
_old=	${_new}
. else
.  if defined(${_old})
.   if defined(${_new})
.    if ${${_old}} != ${${_new}}
.     warning both ${_new} and ${_old} are defined with a different value --\
	using ${_new} and unsetting ${_old}.
.    else
.     warning both ${_new} and ${_old} are defined with the same value --\
	using ${_new} and unsetting ${_old}.
.    endif
.   else
.    warning ${_new} should be defined in place of ${_old} --\
	using ${_new} with the value of ${_old} and unsetting ${_old}.
${_new}:=${${_old}}
.   endif
.   undef ${_old}
.  endif
_old=
. endif
.endfor

all:
	@${ECHO_CMD} renamed variables
	@${ECHO_CMD} BAD=${OLDBAD}:${NEWBAD}
	@${ECHO_CMD} GOOD=${OLDGOOD}:${NEWGOOD}
	@${ECHO_CMD} WARN=${OLDWARN}:${NEWWARN}
	@${ECHO_CMD} ERR=${OLDERR}:${NEWERR}
	@${ECHO_CMD} no variables
	@${ECHO_CMD} BAD=${NOBAD}:${NO_BAD}
	@${ECHO_CMD} GOOD=${NOGOOD}:${NO_GOOD}
	@${ECHO_CMD} WARN=${NOWARN}:${NO_WARN}
	@${ECHO_CMD} ERR=${NOERR}:${NO_ERR}

parce.c
	saveline added to make lineno happy in `.for' loops.
	ParseDoWarning added
	Var_Subst added in `.undef' to avoid inconsistencies such as :
	.for var in ${vars}
	.undef ${var}
	.endfor
vs.
	.for var in ${vars}
	tmp=${var}
	.undef ${tmp}
	.endfor

Index: parse.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/make/parse.c,v
retrieving revision 1.22
diff -u -r1.22 parse.c
--- parse.c	28 Aug 1999 01:03:35 -0000	1.22
+++ parse.c	26 Jul 2002 02:12:52 -0000
@@ -120,6 +120,7 @@
 
 static char    	    *fname;	/* name of current file (for errors) */
 static int          lineno;	/* line number in current file */
+static int          savedlineno;	/* saved line number */
 static FILE   	    *curFILE = NULL; 	/* current makefile */
 
 static PTR 	    *curPTR = NULL; 	/* current makefile */
@@ -252,6 +253,7 @@
 static void ParseUnreadc __P((int));
 static void ParseHasCommands __P((ClientData));
 static void ParseDoInclude __P((char *));
+static void ParseDoWarning __P((char *));
 static void ParseDoError __P((char *));
 #ifdef SYSVINCLUDE
 static void ParseTraditionalInclude __P((char *));
@@ -1557,6 +1559,33 @@
 }
 
 /*---------------------------------------------------------------------
+ * ParseDoWarning  --
+ *	Handle warning directive
+ *
+ *	The input is the line minus the ".warning".  We substitute variables
+ *	and the message or print a warning if the ".warning" directive is
+ *	malformed.
+ *
+ *---------------------------------------------------------------------
+ */
+static void
+ParseDoWarning(errmsg)
+    char          *errmsg;	/* error message */
+{
+	if (!isspace(*errmsg)) {
+		Parse_Error(PARSE_WARNING, "invalid syntax: .warning%s", errmsg);
+		return;
+	}
+	
+	while (isspace(*errmsg))
+		errmsg++;
+	
+	errmsg = Var_Subst(NULL, errmsg, VAR_GLOBAL, FALSE);
+
+	Parse_Error(PARSE_WARNING, "%s", errmsg);
+}
+
+/*---------------------------------------------------------------------
  * ParseDoError  --
  *	Handle error directive
  *
@@ -1580,8 +1609,7 @@
 	
 	errmsg = Var_Subst(NULL, errmsg, VAR_GLOBAL, FALSE);
 
-	/* use fprintf/exit instead of Parse_Error to terminate immediately */
-	fprintf(stderr, "\"%s\", line %d: %s\n", fname, lineno, errmsg);
+	Parse_Error(PARSE_FATAL, "%s", errmsg);
 	exit(1);
 }
 
@@ -1801,7 +1829,7 @@
     curFILE = NULL;
     curPTR = (PTR *) emalloc (sizeof (PTR));
     curPTR->str = curPTR->ptr = str;
-    lineno = 0;
+    lineno = savedlineno;
     fname = estrdup(fname);
 }
 
@@ -2321,6 +2349,7 @@
 		if (For_Eval(line)) {
 		    int ok;
 		    free(line);
+		    savedlineno = lineno;
 		    do {
 			/*
 			 * Skip after the matching end
@@ -2421,7 +2450,10 @@
 		    goto nextLine;
 		} else if (strncmp (cp, "error", 5) == 0) {
 		    ParseDoError(cp + 5);
-	            goto nextLine;	    
+		    /* NOTREACHED */
+		} else if (strncmp (cp, "warning", 7) == 0) {
+		    ParseDoWarning(cp + 7);
+	            goto nextLine;
 		} else if (strncmp(cp, "undef", 5) == 0) {
 		    char *cp2;
 		    for (cp += 5; isspace((unsigned char) *cp); cp++) {
@@ -2434,6 +2466,8 @@
 		    }
 
 		    *cp2 = '\0';
+
+		    cp = Var_Subst(NULL, cp, VAR_GLOBAL, FALSE);
 
 		    Var_Delete(cp, VAR_GLOBAL);
 		    goto nextLine;

find . -name 'Makefile*' -o -name 'bsd.*.mk' |
egrep -v '[./](new|old)[/:]' |
xargs egrep '(^\. *if(n?def)|defined) *\(?NO[^_]' /dev/null >| /tmp/no1
sed -E -e 's/\.if(n?def)? //;s/exists *([^)]+)//g;s/ *[|&=][|&=] *//g' \
       -e 's/!? *defined//g;s/[()\\"]/ /g;s/\${MACHINE_ARCH}//g' \
       -e 's/ i386//g;s/alpha//g;s/:/ /g;s/ +/ /g;s|^\./||' /tmp/no1 >| /tmp/no2
awk '{for(i=2;i<=NF;i++)if($i~/^NO[^_]/)print $1,$i}' /tmp/no2 |
sort -u >| /tmp/no3
awk '{for(i=2;i<=NF;i++)if($i~/^NO[^_]/)print $i,$1}' /tmp/no2 |
sort -u >| /tmp/no4
awk '$1!=f{if(f)print f;f=$1;printf "sed -E -i.bak"}
     {v=$2;sub("NO","&_",v);
      printf " -e %cs/%s([^A-Z_]|$)/%s\\1/g%c ", 39, $2, v, 39}
     END{print f}' /tmp/no3 >| /tmp/no5
awk '$1!=v{if(v){sub("NO","",v);print "_NO_VARS+=\t"v};v=$1}
     {print "#", $2}
     END{sub("NO","",v);print "_NO_VARS+=\t"v}' /tmp/no4 >| /tmp/no6
sed -E -e 's/([^A-Z_])(ALIAS|I4B|KLDLOAD|NAT|NETGRAPH|RADIUS|SUID)([^A-Z_]|$)/\1NO\2	PPP_NO\2\3/' \
       -e 't e' -e b -e :e -e 's/_NO_VARS/_ASSOC_VARS/' /tmp/no6 >| /tmp/no7

no5 contains the sed commands to replace every occurences of NOFOO
    to NO_FOO in every files
no6 contains the list (_NO_VARS) of NO variables for the above knob
no7 same a no6 except that NOFOO ppp variables have been renamed to PPP_NOFOO
    and put in _ASSOC_VARS

hope this help :)

PS : about the make patch, I could submit a PR if you prefer ?

CC -jmallett

Cyrille.
-- 
Cyrille Lefevre                 mailto:cyrille.lefevre@laposte.net

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020726135923.GA89959>