[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: Paul Smith
Subject: Re: How to use shell builtin command in Makefile?
Date: Wed, 22 Oct 2008 09:39:01 -0400

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

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

(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.

 Paul D. Smith <address@hidden>          Find some GNU make tips at:            
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist

reply via email to

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