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:

# convert_program.mk:
run:
    bash bash_srcipt.sh 
clean:
    rm ${OUT_PATH}/result.txt

What I intend is to run like this:

$ 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!

Use makefile variables - they $(look_like_this) - and pass them as environment variables on the command line, e.g.:

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

Thanks John!

One step further, how to let make accept some clues like:

 make speak --phrase=hi

It seems quite common to see makefile accept some argument as

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!

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

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:

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.

1 Like

I took it for an example of what I was trying:

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!