tags:

views:

51

answers:

1

Hi,

I am looking at C makefile, and I have a question.

I know that 'make a' will make the target a, which is supposed to be defined in the makefile.

I want to know whether the target name itself can be supplied as an argument to make.

i.e. this is what I want to do:

$(target_name) is the name supplied to command 'make'. For example, 'make foo'.

and in the makefile,
$(target_name) = dependencies
command

I am not sure whether this is possible... could not find anything in the make manual too.

If anyone can help me with this, it'll be awesome.

Thanks,

+2  A: 

Everything you are asking about is what make does by default - there is no need to write any special code in the makefile to do this. You seem rather confused about make (it is not particularly C related, for example). The best guide to it is the GNU Make Manual, which is not only a manual but a pretty good tutorial.

anon
Yeah.. for example here it shows how you can specify different targets in one makefile http://www.gnu.org/software/make/manual/make.html#Rule-Introduction
littlegreen
Thanks for the responses.Perhaps I was not clear. What I meant was, 'the target name is not predefined in the makefile.' It is supplied from command-line and used in the makefile. Is that possible?
Chaitanya
@Chaitanya "make foo" will build the target named "foo". How can you expect it to build an undefined target?
anon
Well it is possible to build a target not in the makefile if you are using implicit rules, for instance if you have foo.c and no makefile running `make foo` will work and compile foo.
Scott Wales
Thanks for the clarifications!
Chaitanya