Conditional evaluation in make(1)

Ruslan Ermilov ru at FreeBSD.org
Mon Jul 28 04:00:39 PDT 2003


Gang,

> Script started on Mon Jul 28 11:02:58 2003
> goshik# cd /usr/ports ; make index ; cd /usr/local/etc; exit
> 
> Generating INDEX - please wait.."/usr/ports/print/pips2200/../pips800/Makefile", line 60: Malformed conditional (${PRTYPE} == 780cs)
> "/usr/ports/print/pips2200/../pips800/Makefile", line 63: Malformed conditional (${PRTYPE} == 820ug)
> "/usr/ports/print/pips2200/../pips800/Makefile", line 1: Malformed conditional (${PRTYPE} == 750_2000)
> "/usr/ports/print/pips2200/../pips800/Makefile", line 1: Need an operator
> "/usr/ports/print/pips2200/../pips800/Makefile", line 5: Malformed conditional (${PRTYPE} == 780cs)
> "/usr/ports/print/pips2200/../pips800/Makefile", line 7: Malformed conditional (${PRTYPE} == 820ug)
> "/usr/ports/print/pips2200/../pips800/Makefile", line 305: if-less endif
> "/usr/ports/print/pips2200/../pips800/Makefile", line 305: Need an operator
> make: fatal errors encountered -- cannot continue
> make_index: icemc-0.2.4: no entry for /usr/ports/x11-toolkits/qt31
> [...]
> make_index: bugzilla-2.16.3_1: no entry for /usr/ports/www/p5-Template-Toolkit
> Warning: Duplicate INDEX entry: *** Error code 1
> Warning: Duplicate INDEX entry:
>  Done.
> exit
> 
> Script done on Mon Jul 28 11:13:07 2003

I've just fixed ports/print/pips800/Makefile that was broken.
Its string conditional operators were broken, and just sitting
hidden behind another bug in make(1) that was recently fixed.

As explained in section 4.3 of the "PMake -- A Tutorial"
(PSD:12-39) book,

: The arithmetic and string operators may only be used to test
: the value of a variable.  The lefthand side must contain the
: variable expansion, while the righthand side contains either
: a string, enclosed in double-quotes, or a number.  The stan-
            ^^^^^^^^^^^^^^^^^^^^^^^^^
: dard C numeric conventions (except for specifying an octal
: number) apply to both sides.  E.g.
: 
:      #if $(OS) == 4.3
: 
:      #if $(MACHINE) == "sun3"
: 
:      #if $(LOAD_ADDR) < 0xc000
: 
: are all valid conditionals.

Since "1.3.2" doesn't represent a valid number, the test
condition against it should be written like this (with
RHS enclosed in quotes):

    .if ${PORTVERSION} == "1.3.2"

But not like this:

    .if ${PORTVERSION} == 1.3.2

which currently results in a "malformed conditional" complaint
from make(1), and in my opinion, for a good reason.  The reason
why I think conditionals of the form

    .if ${VAR} == (number)(non-number)

(without double quotes) should be complained about by make(1)
is to avoid hiding user bugs of the form:

    .if ${VAR} == 0z

where "z" was put by mistake.  Note that

    .if ${VAR} == (all-non-number)

conditionals with an unquoted RHS are still perfectly supported,
and result in a string comparison being performed.

The -dc option to make(1) can be used to debug conditional
evalulation.

I can easily "fix" our make code to restore the support for
broken string comparisons with the attached patch, so it's
rather a question of do we want to continue supporting this
bug or not.


Cheers,
-- 
Ruslan Ermilov		Sysadmin and DBA,
ru at sunbay.com		Sunbay Software Ltd,
ru at FreeBSD.org		FreeBSD committer
-------------- next part --------------
Index: cond.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/make/cond.c,v
retrieving revision 1.26
diff -u -r1.26 cond.c
--- cond.c	4 Jul 2003 13:33:48 -0000	1.26
+++ cond.c	28 Jul 2003 10:47:29 -0000
@@ -688,7 +688,8 @@
 			}
 		    } else {
 			char *c = CondCvtArg(rhs, &right);
-			if (c == rhs)
+			if (*c != '\0' && !isspace((unsigned char) *c) &&
+			    *c != ')')
 			    goto do_string_compare;
 			if (rhs == condExpr) {
 			    /*
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-arch/attachments/20030728/86a669fa/attachment.bin


More information about the freebsd-arch mailing list