Unix Programming - Reading user argument from make command

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > October 2006 > Reading user argument from make command





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Reading user argument from make command
Thierry

2006-10-13, 7:46 pm

On linux redhat, using GNU makefile, is it possible to read the
argument of a make command, for example:


make hello

Is there a programmable way to read the argument hello?

toby

2006-10-13, 7:46 pm

Thierry wrote:
> On linux redhat, using GNU makefile, is it possible to read the
> argument of a make command, for example:
>
>
> make hello
>
> Is there a programmable way to read the argument hello?


Not in the way you are probably expecting. Make processes arguments
into "goals" (build targets).

See 'info make':
\\
`Make' will set the special variable `MAKECMDGOALS' to the list of
goals you specified on the command line. If no goals were given on the
command line, this variable is empty. Note that this variable should
be used only in special circumstances.
//

SM Ryan

2006-10-13, 7:46 pm

"Thierry" <lamthierry@gmail.com> wrote:
# On linux redhat, using GNU makefile, is it possible to read the
# argument of a make command, for example:
#
#
# make hello

target=hello make $target

@ more makefile
TARGET=$(target)
hello:
echo hello $(TARGET)
bonjour:
cat t.c
cc t.c
a.out

@ target=hello make $target
echo hello hello
hello hello
@ target=bonjour make $target
cat t.c
#include <stdlib.h>
#include <stdio.h>

int main(int N,char **P) {
puts(getenv("target"));
return 0;
}
cc t.c
a.out
bonjour


It's trivial to write a shell script, say ~/bin/make, to do this
for you. Ignoring quote errors, something like
#!/bin/sh
target=$1 /usr/bin/make $*

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Don't say anything. Especially you.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com