5

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.

12

- 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.

  • 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 '17 at 16:15
  • 3
    Yeah, $(hide) probably messes things up, the - is supposed to be the first character after the tab. – Stephen Kitt Feb 13 '17 at 16:17
  • @szx another option is || : at the end. – Aaron D. Marasco Feb 13 '17 at 19:03

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.