Re: make, list and M pattern

2009-04-08 Thread Boris Samorodov
On Wed, 08 Apr 2009 00:09:43 +0300 Giorgos Keramidas wrote:
> On Tue, 07 Apr 2009 23:54:13 +0400, Boris Samorodov  wrote:
> >
> > I need to create a list with some valid values and check an input
> > value. Should this makefile work?
> >
> > -
> > LIST=f8 f9
> >
> > all:
> > @echo USE_LINUX=${USE_LINUX}, LIST=${LIST}
> > .if empty(LIST:M${USE_LINUX})
> > @echo The value is invalid
> > .else
> > @echo The value is valid
> > .endif
> > -
> > % make USE_LINUX=f8
> > USE_LINUX=f8, LIST=f8 f9
> > The value is invalid
> > -

> Hi Boris! :)

Hi Giorgos, Mel and list!

> This is not exactly what you asked for, but you can probably loop
> instead of trying to match regular expressions:

>   keram...@kobe:/tmp$ cat -n Makefile
>1  LIST= f8 f9
>2  USE_LINUX?= f9
>3
>4  LINUX_VERSION= ${USE_LINUX:C/[ ]*([^ ]*)[ ]*/\1/}
>5
>6  .if defined(USE_LINUX)
>7  .for item in ${LIST}
>8  .if ${USE_LINUX} == ${item}
>9  RESULT= ${item}
>   10  .endif
>   11  .endfor
>   12  .endif
>   13
>   14  all:
>   15  .if empty(RESULT)
>   16  @echo Version ${LINUX_VERSION} is not valid.
>   17  .else
>   18  @echo Valid version ${RESULT} selected.
>   19  .endif
>   keram...@kobe:/tmp$ make
>   Valid version f9 selected.
>   keram...@kobe:/tmp$ make -e USE_LINUX=f10
>   Version f10 is not valid.
>   keram...@kobe:/tmp$

Hm, And what if I need to compare two lists and detect if they
have any common items?

VALID_LIST=f8 f9
INPUT_LIST=f6 f7 f8

Nested .for loops are not helpful since .if statement is not
useful here:
.for x in ${VALID_LIST}
. for y in ${INPUT_LIST}
.  if $x == $y   --  make error here


Thanks!


WBR
-- 
Boris Samorodov (bsam)
Research Engineer, http://www.ipt.ru Telephone & Internet SP
FreeBSD Committer, http://www.FreeBSD.org The Power To Serve
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: make, list and M pattern

2009-04-08 Thread Boris Samorodov
On Wed, 8 Apr 2009 08:45:04 +0200 Mel Flynn wrote:
> On Tuesday 07 April 2009 21:54:13 Boris Samorodov wrote:
> > Hello List,
> >
> >
> > I need to create a list with some valid values and check an input
> > value. Should this makefile work?
> > -
> > LIST=f8 f9
> >
> > all:
> > @echo USE_LINUX=${USE_LINUX}, LIST=${LIST}
> > .if empty(LIST:M${USE_LINUX})
> > @echo The value is invalid
> > .else
> > @echo The value is valid
> > .endif
> > -
> > % make USE_LINUX=f8
> > USE_LINUX=f8, LIST=f8 f9
> > The value is invalid
> > -

Hi Mel!

> Doesn't work because the match is not on words of the list but on the full 
> list and you're not using globs.

You are ringht, but not for the case. The case here seems to exist
because variables are not guaranteed to be expanded for M modifier.
I.e. even with globs the result will not be as expected.

> Aside from Giorgos' method, one might consider:
> LIST=f8 f9
> LINUX_VER=invalid

> .for _VERSION in ${LIST}
> .if (${USE_LINUX} == "${_VERSION}")
> LINUX_VER=${_VERSION}
> .endif
> .endfor

> all:
> .if !empty(LINUX_VER:Minvalid)
> @echo "Invalid linux version: ${USE_LINUX}"
> .else
> @echo "Using linux version ${LINUX_VER}"
> .endif

Works. Thanks!


WBR
-- 
Boris Samorodov (bsam)
Research Engineer, http://www.ipt.ru Telephone & Internet SP
FreeBSD Committer, http://www.FreeBSD.org The Power To Serve
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: make, list and M pattern

2009-04-08 Thread Boris Samorodov
On Wed, 08 Apr 2009 00:09:43 +0300 Giorgos Keramidas wrote:
> On Tue, 07 Apr 2009 23:54:13 +0400, Boris Samorodov  wrote:
> > Hello List,
> >
> > I need to create a list with some valid values and check an input
> > value. Should this makefile work?
> >
> > -
> > LIST=f8 f9
> >
> > all:
> > @echo USE_LINUX=${USE_LINUX}, LIST=${LIST}
> > .if empty(LIST:M${USE_LINUX})
> > @echo The value is invalid
> > .else
> > @echo The value is valid
> > .endif
> > -
> > % make USE_LINUX=f8
> > USE_LINUX=f8, LIST=f8 f9
> > The value is invalid
> > -

> Hi Boris! :)

Hi Giorgos! :)

> This is not exactly what you asked for, but you can probably loop
> instead of trying to match regular expressions:

>   keram...@kobe:/tmp$ cat -n Makefile
>1  LIST= f8 f9
>2  USE_LINUX?= f9
>3
>4  LINUX_VERSION= ${USE_LINUX:C/[ ]*([^ ]*)[ ]*/\1/}
>5
>6  .if defined(USE_LINUX)
>7  .for item in ${LIST}
>8  .if ${USE_LINUX} == ${item}
>9  RESULT= ${item}
>   10  .endif
>   11  .endfor
>   12  .endif
>   13
>   14  all:
>   15  .if empty(RESULT)
>   16  @echo Version ${LINUX_VERSION} is not valid.
>   17  .else
>   18  @echo Valid version ${RESULT} selected.
>   19  .endif
>   keram...@kobe:/tmp$ make
>   Valid version f9 selected.
>   keram...@kobe:/tmp$ make -e USE_LINUX=f10
>   Version f10 is not valid.
>   keram...@kobe:/tmp$

Thanks, that would fit enough.


WBR
-- 
Boris Samorodov (bsam)
Research Engineer, http://www.ipt.ru Telephone & Internet SP
FreeBSD Committer, http://www.FreeBSD.org The Power To Serve
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: make, list and M pattern

2009-04-07 Thread Mel Flynn
On Tuesday 07 April 2009 21:54:13 Boris Samorodov wrote:
> Hello List,
>
>
> I need to create a list with some valid values and check an input
> value. Should this makefile work?
> -
> LIST=f8 f9
>
> all:
>   @echo USE_LINUX=${USE_LINUX}, LIST=${LIST}
> .if empty(LIST:M${USE_LINUX})
>   @echo The value is invalid
> .else
>   @echo The value is valid
> .endif
> -
> % make USE_LINUX=f8
> USE_LINUX=f8, LIST=f8 f9
> The value is invalid
> -

Doesn't work because the match is not on words of the list but on the full 
list and you're not using globs.
Aside from Giorgos' method, one might consider:
LIST=f8 f9
LINUX_VER=invalid

.for _VERSION in ${LIST}
.if (${USE_LINUX} == "${_VERSION}")
LINUX_VER=${_VERSION}
.endif
.endfor

all:
.if !empty(LINUX_VER:Minvalid)
@echo "Invalid linux version: ${USE_LINUX}"
.else
@echo "Using linux version ${LINUX_VER}"
.endif

-- 
Mel
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: make, list and M pattern

2009-04-07 Thread Giorgos Keramidas
On Tue, 07 Apr 2009 23:54:13 +0400, Boris Samorodov  wrote:
> Hello List,
>
> I need to create a list with some valid values and check an input
> value. Should this makefile work?
>
> -
> LIST=f8 f9
>
> all:
>   @echo USE_LINUX=${USE_LINUX}, LIST=${LIST}
> .if empty(LIST:M${USE_LINUX})
>   @echo The value is invalid
> .else
>   @echo The value is valid
> .endif
> -
> % make USE_LINUX=f8
> USE_LINUX=f8, LIST=f8 f9
> The value is invalid
> -

Hi Boris! :)

This is not exactly what you asked for, but you can probably loop
instead of trying to match regular expressions:

  keram...@kobe:/tmp$ cat -n Makefile
   1  LIST= f8 f9
   2  USE_LINUX?= f9
   3
   4  LINUX_VERSION= ${USE_LINUX:C/[ ]*([^ ]*)[ ]*/\1/}
   5
   6  .if defined(USE_LINUX)
   7  .for item in ${LIST}
   8  .if ${USE_LINUX} == ${item}
   9  RESULT= ${item}
  10  .endif
  11  .endfor
  12  .endif
  13
  14  all:
  15  .if empty(RESULT)
  16  @echo Version ${LINUX_VERSION} is not valid.
  17  .else
  18  @echo Valid version ${RESULT} selected.
  19  .endif
  keram...@kobe:/tmp$ make
  Valid version f9 selected.
  keram...@kobe:/tmp$ make -e USE_LINUX=f10
  Version f10 is not valid.
  keram...@kobe:/tmp$

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"