How to include clean target in Makefile?

后端 未结 3 776
面向向阳花
面向向阳花 2020-12-29 05:02

I have a Makefile that looks like this

CXX = g++ -O2 -Wall

all: code1 code2

code1: code1.cc utilities.cc
   $(CXX) $^ -o $@

code2: code2.cc utilities.cc
          


        
3条回答
  •  时光取名叫无心
    2020-12-29 05:44

    By the way it is written, clean rule is invoked only if it is explicitly called:

    make clean

    I think it is better, than make clean every time. If you want to do this by your way, try this:

    CXX = g++ -O2 -Wall
    
    all: clean code1 code2
    
    code1: code1.cc utilities.cc
       $(CXX) $^ -o $@
    
    code2: code2.cc utilities.cc
       $(CXX) $^ -o $@
    
    clean: 
        rm ...
        echo Clean done
    

提交回复
热议问题