[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to use shell builtin command in Makefile?

From: Peng Yu
Subject: Re: How to use shell builtin command in Makefile?
Date: Wed, 22 Oct 2008 08:24:18 -0500

On Wed, Oct 22, 2008 at 8:13 AM, Paul Smith <address@hidden> wrote:
> On Wed, 2008-10-22 at 07:57 -0500, Peng Yu wrote:
>> I want to use the uncommented line rather than the commented line.
>> #SUBDIRS = $(shell find . -mindepth 1 -maxdepth 1 -type d ! -name
>> 'backup' ! -name 'bash')
>> SUBDIRS = $(shell compgen -d -X 'backup' -X 'bash')
>> But make gives me "make: compgen: Command not found". I'm wondering
>> how to use shell builtin command in make.
> make runs /bin/sh.  There is no such thing as a builtin named compgen in
> the POSIX standard for sh: that's a bash feature.  So one problem is
> that your /bin/sh is not bash.
> If you are using a system where /bin/sh is actually bash, then you
> should first note that relying on this makes your makefiles completely
> un-portable.
> make doesn't recognize compgen as a builtin, so it tries to use the
> "fast path" method of invoking your script: since it doesn't contain any
> special characters make runs it directly via fork/exec.
> You can solve most of these problems with:
>        SUBDIRS := $(shell /bin/bash -c "compgen -d -X 'backup' -X
>        'bash'")
> (note it's always best to use := instead of = with $(shell ...) unless
> you have a specific reason not to).
> This still requires that bash be installed but that's not too onerous
> these days.

The reason that I want to use 'compgen' rather than 'find' is that I
think it is faster than 'find', since it's a bash builtin command. I'm
not sure whether this is a good enough reason to use it. Do you have
any idea?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]