tags:

views:

133

answers:

1

Hello,

In a Makefile, I read:

-rm -rf (instead of rm -rf). What does the first "-" mean at the beginning of the line in a Makefile ?

Regards, Apple92

+11  A: 

It means that make itself will ignore any error code from rm.

In a makefile, if any command fails then the make process itself discontinues processing. By prefixing your commands with -, you notify make that it should continue processing rules no matter the outcome of the command.

For example, the makefile rule:

clean:
    rm *.o
    rm *.a

will not remove the *.a files if rm *.o returns an error (if, for example, there aren't any *.o files to delete). Using:

clean:
    -rm *.o
    -rm *.a

will fix that particular problem.


Aside: Although it's probably not needed in your specific case (since the -f flag appears to prevent rm from returning an error when the file does not exist), it's still good practice to mark the line explicitly in the makefile - rm may return other errors under certain circumstances and it makes your intent clear.

paxdiablo
Clear and efficient! Thx.