Seamus
Seamus

Reputation: 2101

Pass makefile automatic variable value to bash function called from make

Say I have the following function defined in my .bashrc:

foo (){
    touch $1
    }

I want to call this function in a makefile like so:

%.png : %.tex
    bash -i -c foo $<

But this complains about a missing operand. (The error is "touch: missing file operand", so it is calling touch...). I've seen some solutions to similar issues, but they aren't applicable since I need the automatic variable $< (or rather, its value) to be passed as an argument to the shell script.

I know I could work around this problem (copy the function wholesale into the makefile, for example) but I'm curious to see how I could solve my problem within the makefile.

Upvotes: 0

Views: 135

Answers (1)

MadScientist
MadScientist

Reputation: 100816

Your problem is probably because you don't have enough quoting. The shell -c option takes its script as a single argument.

Consider:

$ bash -c echo hi
<prints nothing>

Versus:

$ bash -c 'echo hi'
hi

Upvotes: 1

Related Questions