0

I'm new to Makefile and just trying to change a file suffix. I want to convert files from one format to another eg .mov to .mp4

In bash I would do something like

out1 = "${input/mov/mp4}"

(is there a way to just use inline Bash syntax in Make?)

anyway it doesn't work. So I found these docs on Text functions https://www.gnu.org/software/make/manual/html_node/Text-Functions.html

$(var:suffix=replacement)

so trying to translate that into something I can use...

out1 := "${input/mov/mp4}"   ##bash syntax doesnt work
out2 := $(input:suffix=mp4)

check:
    @echo " input: ${input}"
    @echo "  out1: ${out1}"
    @echo "  out2: ${out2}"

but it doesn't work, the suffix is untouched

$ input=tutorial-v1.mov make check
 input: tutorial-v1.mov
  out1:
  out2: tutorial-v1.mov

I've seen other scripts using sed, but just for changing a suffix I just need to get the incantation syntax right.

second question, i dont s'pose there's a nicer way to pass params to a makefile script than have to define named env vars. eg just make cmd param1 param2 like any other shell script for $1 ?

  • I think you misunderstood the syntax; for your example it would be $(input:.mov=.mp4). See for example GNU make: 6.3.1 Substitution References – steeldriver Oct 17 at 2:33
  • hmm that part you are right. but now i can't put the assignment block inside a make command, only once at the top of the file. so it's basically pointless if i need different suffixes :/ – dcsan Oct 17 at 4:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.