linux - Escaping a system variable to pass as an argument to make -
i have makefile generated bakefile working fine. run executable needs libraries different folder. found command rpath used specify path these library. have send makefile argument when using command. cannot specify directly bakefile.
i can use ldflags arguments fine. , found here how use $origin variable.
my question how escaping works?
make ldflags="-wl,-rpath '-wl,\$\$origin'"
is single quote prevent make interpret variable? , why \$ here twice?
yeesh. mess.
so, first set of quotes removed shell, before starts make command. since outer set of quotes double-quotes, have escape $
otherwise shell treat shell variable (compare command echo "my path $pwd"
, how pwd
variable expanded). shell uses backslashes quote things $
.
so, time shell hands command line make, sees setting ldflags=-wl,-rpath '-wl,$$origin'
next in makefile recipe command this:
$(ld) $(ldflags) ...
make expand ldflags
variable above. make, name preceded $
considered make variable , escape expansion make doubling $
(not using backslashes shell), , writing $$
. make remove 1 $
during expansion.
so, make reduce ldflags
string -wl,-rpath '-wl,$origin'
, pass shell.
the shell strip next level of quoting, in case single quotes. variables not expanded inside single quotes, linker gets arguments, literally, -wl,-rpath
, -wl,$origin
, want.
Comments
Post a Comment