Makefile: read input variable and set several variables -
i have makefile want read file name input , make other names based on it`s name. have tried following code
mlext = .ml testext = test.ml nativeext = test.native test: @read -p "enter file name: " file; \ echo $$file$(mlext); \ echo $$file$(testext); \ echo $$file$(nativeext)
for example:
if type: foo
then want foo.ml
, footest.ml
, footest.native
however, can foo.ml
. rest 2 .ml
, .native
how can fix this?
first, let see exact recipe given shell removing @
in makefile:
read -p "enter file name: " file; \ echo $file.ml; \ echo $filetest.ml; \ echo $filetest.native;
the issue content of $(testext)
gets appended $$file
, creating shell variable $filetest
, (very probably) not exist, resulting in empty string in end. not occur $(mlext)
, initial dot cannot part of variable name.
to overcome this, use $${file}
instead of $$file
in makefile rule.
Comments
Post a Comment