Passing arguments to customized makefile


 
Thread Tools Search this Thread
Top Forums Programming Passing arguments to customized makefile
# 1  
Old 02-25-2014
Passing arguments to customized makefile

Hello,
How to pass arguments to make thru command line? Have read this and that threads, but still not clear. My customized Makefile as:
Code:
# convert_program.mk:
run:
    bash bash_srcipt.sh 
clean:
    rm ${OUT_PATH}/result.txt

What I intend is to run like this:
Code:
$ make -f convert_progam.mk run --infile_path=/home/path/to/infile --outfile_path=/home/path/to/outfile

to pass the "infile_path" and "outfile_path" to my bash_script.sh.
How to accomplish this?
Thanks a lot!

Last edited by yifangt; 02-28-2014 at 05:09 PM.. Reason: expression not accurate
# 2  
Old 03-06-2014
Use makefile variables - they $(look_like_this) - and pass them as environment variables on the command line, e.g.:

Code:
$ cat makefile 
speak:
    echo $(PHRASE)
$ make speak PHRASE=hi
echo hi
hi

# 3  
Old 03-06-2014
Thanks John!

One step further, how to let make accept some clues like:
Code:
 make speak --phrase=hi

It seems quite common to see makefile accept some argument as
Code:
make --prefix=/path/to/where/install --k=some_value --phrase=hi

The advantage for this format is the order of the argument will not matter, and the -- format can provide some clues on the parameters to be passed.
Got lost with most online makefile tutorials, especially with those automatic variables $@, $<, $|, $* and $? etc. Before coming to those tricks I feel should catch the straight-forward format first. Thank you again!
# 4  
Old 03-06-2014
Quote:
Originally Posted by yifangt
It seems quite common to see makefile accept some argument as

Code:
make --prefix=/path/to/where/install --k=some_value --phrase=hi

You're thinking of configure scripts - they take a --prefix argument, makefiles don't.

Quote:
Originally Posted by yifangt
The advantage for this format is the order of the argument will not matter, and the -- format can provide some clues on the parameters to be passed.
Order of arguments with "make val=arg" doesn't matter either, and I don't know what you mean by the format providing clues on the parameters to be passed - give the variables in your makefile sensible names, and they'll make sense.

Also, this helps distinguish between arguments to your makefile (look like val=arg) and arguments to the make program itself (look like --val=arg), so it's clearer where it's being used. Also, they can be set from the environment variable - i.e. if a user knows they always want PHRASE to be "hi", they can just do:

Code:
export PHRASE=hi

and they'll not have to pass it to your makefile.

Bottom line: This is how you pass arguments to makefiles. You cannot do it --this-way.
This User Gave Thanks to JohnGraham For This Post:
# 5  
Old 03-06-2014
I took it for an example of what I was trying:
Code:
You're thinking of configure scripts - they take a --prefix argument, makefiles don't.

OK, I got the point now, the -- does not matter too much if the arguments can be set as phrase=hi, kmer=24, gmer=something would be good enough. I am aware of the configure options, which I should have looked into deeper to have more idea. Thank you very much again!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Processing Arguments pased to Makefile

I have a makefile and want to allow passing -01 -02 -03 for the user to define the level of optimization he wants. Doing this gets make to send an error. make -03 make: invalid option -- '0' make: invalid option -- '3' Usage: make ... (5 Replies)
Discussion started by: kristinu
5 Replies

2. Shell Programming and Scripting

To pass arguments to makefile using script

Hi, I want to run a target of makfile using script by passing different arguments to it again n again. I i need to grep certain things from the log file. eg make abc KAB=8 BAC=8 >& KAB_BAC.log grep "timeA" KAB_BAC.log grep "timeB" KAB_BAC.log (i want to store the difference of the two time... (0 Replies)
Discussion started by: vdhingra123
0 Replies

3. Shell Programming and Scripting

Passing arguments--Error

Hi, i have a file.txt with data Bangalore Chennai Hyd filename of the script is: new.sh result=`cat file.txt | grep $1` if then echo pass else echo fail fi i am executing the file in the cmd line as "sh new.sh Bangalore" o/p is pass if i give "sh new.sh delhi" o/p is... (6 Replies)
Discussion started by: harsha85
6 Replies

4. Shell Programming and Scripting

Reading a string and passing passing arguments to a while loop

I have an for loop that reads the following file cat param.cfg val1:env1:opt1 val2:env2:opt2 val3:env3:opt3 val4:env4:opt4 . . The for loop extracts the each line of the file so that at any one point, the value of i is val1:env1:opt1 etc... I would like to extract each... (19 Replies)
Discussion started by: goddevil
19 Replies

5. UNIX for Dummies Questions & Answers

Passing arguments

I need to pass arguments to a shell script.My batch is calling some java program. ################# x=$1 y=$2 java -classpath program ################### if first parameter and second parameter is null then java -classpath program if first parameter is not null and second parameter is... (3 Replies)
Discussion started by: mnjx
3 Replies

6. Shell Programming and Scripting

passing arguments

Hi I have a script to which I pass multiple arguments, for example lets say the script name is "abc". I run the script like ./abc def /file <directory location> In the above "def" is the first argument and "/file" is the second argument. I expect <directory location> that is passed after... (4 Replies)
Discussion started by: zmfcat1
4 Replies

7. Shell Programming and Scripting

Passing Arguments-Help

Hi, I have a script which adds the user credentials to an ldap server. Im passing the variables as below.. /path/my_script $uname $pwd $environ ${deposit} If i enter some special characters like ';' in $pwd, script returns an error which is set to display if the user enters... (5 Replies)
Discussion started by: Tuxidow
5 Replies

8. Programming

Passing parameter to makefile?

Hi, How to pass parameter to makefile? Please let me know if any one knows and also please put an example of makefile with this feature. thanks, Manju. (3 Replies)
Discussion started by: manju_p
3 Replies

9. Shell Programming and Scripting

Passing arguments to a script

I've written a script (bgrep) for a more advanced grep command (& attached a cut down version below). I'm trying allow all grep options to be used, or in any combination. The script works fine if I type say bgrep -i -files product it will return a non-case sensitive list of matches for... (3 Replies)
Discussion started by: Kevin Pryke
3 Replies

10. UNIX for Dummies Questions & Answers

passing arguments

I'm trying to pass a filename, or all the files in the current directory to the ls command with a script. Unsuccessful so far, here are a few of my attempts: #!/bin/ksh read fname #if (( $# > 0 )); then $fname | ls -l #fi this produces a long listing of all the files in my current... (4 Replies)
Discussion started by: jpprial
4 Replies
Login or Register to Ask a Question