help-make
[Top][All Lists]
Advanced

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

variable describing target


From: Bryan Ischo
Subject: variable describing target
Date: Sun, 9 Sep 2007 21:21:01 -0400 (EDT)
User-agent: SquirrelMail/1.4.8-4.fc5

Hi all.  Is there a variable describing the target(s) that make was
invoked with?  For example, if I do:

make libfoo

Is there a variable available in make that will evaluate to "libfoo"?

The reason that I ask for this is that I have a makefile which has
requirements for a PLATFORM variable to be set, and for normal operation I
want to issue an error if this variable is not set.  Something like this:

ifndef PLATFORM
    $(error PLATFORM must be set)
endif

However, I also have a target, "help", that I want to be able to invoke to
get help on using the makefile:

.PHONY: help
help:
     @ echo A bunch of help text.

The problem is, if I run make like this:

make help

I get:

Makefile:217: *** PLATFORM must be set.  Stop.

What I really want is to be able to do something like this:

ifndef PLATFORM
ifneq ($(MAKE_TARGET),"help")
    $(error PLATFORM must be set)
endif
endif

The point being that if you run "make help", the makefile doesn't exit
with an error because you didn't set PLATFORM; instead it shows you the
help text.  But if you try to make a 'real' target (anything other than
help), you will get an error if you haven't set the PLATFORM variable.

My reasoning is, make help (as I am trying to define it) should work even
if you don't set any variables that the makefile would otherwise depend
upon, because it is my make help command itself which will describe the
variables that you have to set and what you can set them to.

It is true that I can have my error be something like "PLATFORM must be
set to one of: unix, win32", and then the user would do something like
this:

$ make help
Makefile:217: *** PLATFORM must be set to one of: unix, win32.  Stop.

$ PLATFORM=unix make
(help text)

But I'd prefer not to have to make the user set variables that they may
not understand yet, just to see the help text describing what they are and
how they should be set.

Any suggestions?

Thank you!
Bryan

------------------------------------------------------------------------
Bryan Ischo                address@hidden            2001 Mazda 626 GLX
Hamilton, New Zealand      http://www.ischo.com     RedHat Fedora Core 5
------------------------------------------------------------------------






reply via email to

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