美文网首页
GNU Makefile

GNU Makefile

作者: branv | 来源:发表于2021-07-26 10:49 被阅读0次
    Makefile 规则:

    看个列子
    foo.o : foo.c defs.h
    cc -c -g foo.c
    文件“foo.o”是规则需要重建的文件(目标文件)。文件“foo.o”是规则需要重建的文件(目标的依赖)
    第二行“cc -c -g foo.c”是规则的“命令”

    规则语法:

    ARGETS : PREREQUISITES COMMAND
    规则中“TARGETS”可以是空格分开的多个文件名,也可以是一个标签(例如:
    执行清空的“clean”)

    规则的中心思想是:目标文件的内容是由依赖文件文件决定,依赖文件的任何一处
    改动,将导致目前已经存在的目标文件的内容过期

    依赖):

    对于这样的规则:A:B C,那么在构建目标 A 之前,首先需要完成对它的依赖文件 B 和 C 的构建

    通配符):
    rm -f *.o
    
    wildcard函数):
    objects := $(patsubst %.c,%.o,$(wildcard *.c))
           foo : $(objects) 
           cc -o foo $(objects)
    

    ~~~~wildcard :查找所有 .c的文件,patsubst :将所有的.c文件替换成.o后缀的文件

    目录搜寻):

    变量VPATH:
    ~~~~定义变量“VPATH”时,使用空格或者冒号(:)将多个需要搜索的目录分开
    ~~~~ VPATH = src:../headers
    ~~~~ 这样我们就为所有规则的依赖指定了两个搜索目录,“src”和“../headers”
    变量vpath
    ~~~~vpath %.c foo
    ~~~~ vpath % blish
    ~~~~vpath %.c bar
    ~~~~ 表示对所有的.c 文件,make 依次查找目录:“foo”、blish”、“bar”
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~
    ~~~~

    相关文章

      网友评论

          本文标题:GNU Makefile

          本文链接:https://www.haomeiwen.com/subject/ymwwmltx.html