6

I came across this in one of Android makefiles (build/core/Makefile):

$(hide) -cp $(TARGET_ROOT_OUT)/init.recovery.*.rc $(TARGET_RECOVERY_ROOT_OUT)/

What does the - mean in front of cp here? It probably has something to do with suppressing errors but I couldn't google documentation for this.

1 Answer 1

13

- in a recipe tells Make to ignore any errors (see Errors in recipes).

In this specific case, any error reported by cp will be ignored (the output will contain any messages, but the build will continue).

This only works if - is interpreted by Make, i.e. it's the first non-whitespace character in the line (or the characters preceding it are also interpreted by Make). In this case, $(hide) needs to be considered: if hide is empty or @, -cp will have the intended effect; but if hide is for instance @>/dev/null (so the command isn't echoed and its standard output is discarded), -cp will be passed as-is to the shell and the command will fail.

3
  • 1
    Thanks, didn't think it was a make thing. For some reason it didn't work last two times I tried to build CyanogenMod, I guess that's why they replaced it with a || true at the end.
    – szx
    Feb 13, 2017 at 16:15
  • 3
    Yeah, $(hide) probably messes things up, the - is supposed to be the first character after the tab. Feb 13, 2017 at 16:17
  • @szx another option is || : at the end. Feb 13, 2017 at 19:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .