help-gnu-utils
[Top][All Lists]
Advanced

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

Re: Makefile target selection


From: John Graham-Cumming
Subject: Re: Makefile target selection
Date: Mon, 27 Dec 2004 17:10:25 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040208 Thunderbird/0.5 Mnenhy/0.6.0.104

zuheyr alsalihi wrote:
Is there any way to know in a Makefile which target is wanted to build?
E.g. if I have targets all, A and B, how can I use conditionals in the
Makefile depening on the target?

In GNU Make there's a built-in variable called MAKECMDGOALS which lists (in standard space-separated list format) the goals that were specified on the command line.

For example if you

    make foo bar

then MAKECMDGOALS will be foo bar. You can check for the presence of a specific goal by using the $(filter ) function.

For example, to check for the goal bar you could do the following

    BAR_PRESENT := $(filter bar,$(MAKECMDGOALS))

BAR_PRESENT will be set to bar if bar was specified on the command-line, or an empty string if not. So then you can make parts of the Makefile optional as follows:

    ifdef $(BAR_PRESENT)
        ... do this is bar is a goal ...
    endif

John.


reply via email to

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