Bash – What does “-” mean in this “-cp” command

bashcommand linemakeshell

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.

Best Answer

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

Related Question