grep -P in OF template Makefile: really useful?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

grep -P in OF template Makefile: really useful?

Julien Bect-2
Hi everyone,

The template Makefile for OF packages
(https://octave.sourceforge.io/templates/Makefile) contains this line:

PKG_ADD := $(shell grep -sPho '(?<=(//|\#\#) PKG_ADD: ).*' $(CC_SOURCES)
$(M_SOURCES))

It turns out that this can cause problems on some platforms where grep
-P is not supported [1].

Could anybody familiar enough with regexps tell me if the -P flag is
actually useful for this particular regexp?

If it is, could we find a way to rewrite the regexp that would not
require PCRE?

@++
Julien


[1] See https://sourceforge.net/p/octave/package-releases/298/#c4a6/ab8b 
for an example

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: grep -P in OF template Makefile: really useful?

Mike Miller-4
On Sat, Mar 04, 2017 at 23:18:29 +0100, Julien Bect wrote:

> Hi everyone,
>
> The template Makefile for OF packages
> (https://octave.sourceforge.io/templates/Makefile) contains this line:
>
> PKG_ADD := $(shell grep -sPho '(?<=(//|\#\#) PKG_ADD: ).*' $(CC_SOURCES)
> $(M_SOURCES))
>
> It turns out that this can cause problems on some platforms where grep -P is
> not supported [1].
>
> Could anybody familiar enough with regexps tell me if the -P flag is
> actually useful for this particular regexp?
>
> If it is, could we find a way to rewrite the regexp that would not require
> PCRE?

I guess you're using the lookbehind syntax to just avoid matching that
part of the line when using the -o option? That looks like overkill to
me. The -h and -o options are also not specified by the POSIX definition
of grep.

IMHO this is a much safer and more portable alternative:

  sed -n 's/^\(##\|\/\/\) PKG_ADD: \(.*\)/\2/p' ...

--
mike

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: grep -P in OF template Makefile: really useful?

Julien Bect-2
Le 04/03/2017 à 23:31, Mike Miller a écrit :

> On Sat, Mar 04, 2017 at 23:18:29 +0100, Julien Bect wrote:
>> Hi everyone,
>>
>> The template Makefile for OF packages
>> (https://octave.sourceforge.io/templates/Makefile) contains this line:
>>
>> PKG_ADD := $(shell grep -sPho '(?<=(//|\#\#) PKG_ADD: ).*' $(CC_SOURCES)
>> $(M_SOURCES))
>>
>> It turns out that this can cause problems on some platforms where grep -P is
>> not supported [1].
>>
>> Could anybody familiar enough with regexps tell me if the -P flag is
>> actually useful for this particular regexp?
>>
>> If it is, could we find a way to rewrite the regexp that would not require
>> PCRE?
> I guess you're using the lookbehind syntax to just avoid matching that
> part of the line when using the -o option?

I have no idea why it is written like that.  I didn't write it.


> That looks like overkill to
> me. The -h and -o options are also not specified by the POSIX definition
> of grep.
>
> IMHO this is a much safer and more portable alternative:
>
>    sed -n 's/^\(##\|\/\/\) PKG_ADD: \(.*\)/\2/p' ...


I will try that, thanks.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: grep -P in OF template Makefile: really useful?

Carnë Draug
On 5 March 2017 at 08:58, Julien Bect <[hidden email]> wrote:

> Le 04/03/2017 à 23:31, Mike Miller a écrit :
>>
>> On Sat, Mar 04, 2017 at 23:18:29 +0100, Julien Bect wrote:
>>>
>>> Hi everyone,
>>>
>>> The template Makefile for OF packages
>>> (https://octave.sourceforge.io/templates/Makefile) contains this line:
>>>
>>> PKG_ADD := $(shell grep -sPho '(?<=(//|\#\#) PKG_ADD: ).*' $(CC_SOURCES)
>>> $(M_SOURCES))
>>>
>>> It turns out that this can cause problems on some platforms where grep -P
>>> is
>>> not supported [1].
>>>
>>> Could anybody familiar enough with regexps tell me if the -P flag is
>>> actually useful for this particular regexp?
>>>
>>> If it is, could we find a way to rewrite the regexp that would not
>>> require
>>> PCRE?
>>
>> I guess you're using the lookbehind syntax to just avoid matching that
>> part of the line when using the -o option?
>
>
> I have no idea why it is written like that.  I didn't write it.
>
>> That looks like overkill to
>> me. The -h and -o options are also not specified by the POSIX definition
>> of grep.
>>
>> IMHO this is a much safer and more portable alternative:
>>
>>    sed -n 's/^\(##\|\/\/\) PKG_ADD: \(.*\)/\2/p' ...
>
> I will try that, thanks.
>

I wrote the original use of "grep -sPho".  It was do what Mike said.
I am guilty of abusing grep, and the use of sed seems much better.

Carnë

Loading...