Makefile 一点一滴(三)—— 尝试简单的变量替换

上一版的 makefile:

TestCpp : ./debug/TestCpp.o
    g++ -o TestCpp ./debug/TestCpp.o

./debug/TestCpp.o : ./src/TestCpp.cpp
    g++ -c -o ./debug/TestCpp.o ./src/TestCpp.cpp
    
clean : 
    rm -rf ./debug/TestCpp.o

这次尝试,用一些 makefile 函数对其进行替换,方便修改和移植。

TARGET= ./bin/TestCpp

$(TARGET): ./debug/TestCpp.o
    g++ -o $(TARGET) ./debug/TestCpp.o

# $@ —— 冒号前面的变量 $< —— 冒号后面的变量
./debug/TestCpp.o : ./src/TestCpp.cpp
    g++ -c -o $@ $<
    
clean : 
    rm -rf ./debug/TestCpp.o

这次总算是一次成功了。。。输出和前一版本一致

原文地址:https://www.cnblogs.com/sunrisezhang/p/3535686.html