Reputation: 2109
I want to run command perl -MConfig -e 'print $Config{archlib}'
in my makefile and use the location it returns in my LDFLAGS
. Can anyone help me. I tried different ways using $(shell ..)
but it did not work
I want to do something like this
PERLPATH = $(shell 'perl -MConfig -e "print $Config{archlib}"')
LDFLAGS += -L/usr/lib64/perl5/CORE
Thanks!!
Upvotes: 1
Views: 7810
Reputation: 101081
You should specify what you mean by it did not work. When asking questions you should always provide the exact command you ran and the exact error that was generated.
However, the problem with your invocation of shell
is that you're quoting the entire command. You should just put the command you want to run directly, as you would type it to the shell prompt. That means you need to either use single-quotes around the shell script, or escape the $
from the shell. Then you need to escape $
from make, by doubling it. Basically, you should get the command to run properly at your shell prompt then simply cut and paste that exactly that string into the shell
function. Then change every instance of $
to $$
to escape it from make.
Also you should (for efficiency) use :=
instead:
PERLPATH := $(shell perl -MConfig -e 'print $$Config{archlib}')
And of course you want to use this path variable:
LDFLAGS += -L$(PERLPATH)/CORE
Upvotes: 3
Reputation: 242343
In a Makefile, you have to use double dollar signs if you do not want make
to interpret them. Avoid double quotes, though, as shell would try to expand variables.
PERLPATH = $(shell perl -MConfig -e 'print $$Config{archlib}')
Upvotes: 6