Makefile的基础语法
makefile 的注释类似py , 以#开头的行为注释行
#比如这样
变量的用法也类似py, = 来赋值,+= 来添加字符串
$(xx) 来取出xx的值
$@ 指代target
$^ 指代 依赖列表
$< 指代 依赖列表的第一项
$(wildcard ./*.cpp) wildcard用来筛选下面来看个例子
exe = helloworld
find_cpp = $(wildcard *.cpp)
find_o = $(patsubst %.cpp, %.o ,$(find_cpp))
find_h = $(patsubst %.o, %.d ,$(find_o))
$(exe): $(find_o)
g++ $(find_o) -o $(exe)
%.o: %.cpp
g++ -c -MMD $< -o $@
-include $(find_h)
这段makefile基本可以适应大部分小程序
—MMD 是自动去包括.h文件
patsubst 来转换(看一下基本用法就好)
-include来导入自动shengcheng的.d文件来导入.h 依赖
%.o 来自动去编译
大大减少了我们的书写量