GNU Make. Why this complex syntax to generate dependencies?

后端 未结 3 719
醉梦人生
醉梦人生 2020-12-09 23:07

I\'m reading Managing Projects with GNU Make, and found this example in Chapter 2.7 - Automatic Dependency Generation. The Author says their from the GNU manual:

<         


        
3条回答
  •  有刺的猬
    2020-12-09 23:20

    Addressing the question: Why do a redirect of the file into sed? If you do:

    @$(CC) -M $(CPPFLAGS) $<  | sed 's|:| $*.d : |'  > $@;
    

    and the compilation fails (errors out and generates no output), you will create an empty target file. When make is run again, it will see the newly created empty file and not regenerate it, leading to build errors. Using intermediate files is a common defensive strategy to avoid accidentally created an empty target.

提交回复
热议问题