• GNU make manual 翻译(九十四)


    继续翻译

    4.5.4 Writing Recipes with Directory Search
    -------------------------------------------
    When a prerequisite is found in another directory through directory
    search, this cannot change the recipe of the rule; they will execute as
    written.  Therefore, you must write the recipe with care so that it
    will look for the prerequisite in the directory where `make' finds it.
    
       This is done with the "automatic variables" such as `$^' (*note
    Automatic Variables::).  For instance, the value of `$^' is a list of
    all the prerequisites of the rule, including the names of the
    directories in which they were found, and the value of `$@' is the
    target.  Thus:
    
         foo.o : foo.c
                 cc -c $(CFLAGS) $^ -o $@
    
    (The variable `CFLAGS' exists so you can specify flags for C
    compilation by implicit rules; we use it here for consistency so it will
    affect all C compilations uniformly; *note Variables Used by Implicit
    Rules: Implicit Variables.)
    
       Often the prerequisites include header files as well, which you do
    not want to mention in the recipe.  The automatic variable `$<' is just
    the first prerequisite:
    
         VPATH = src:../headers
         foo.o : foo.c defs.h hack.h
                 cc -c $(CFLAGS) $< -o $@

    4.5.4 写目录搜索相关的片段
    -------------------------------------------

    当一个前提条件通过目录搜索在另一个目录中被发现,这并不会改变规则的片段;片段将按照所写的被执行。因此,你必须仔细地书写片段这样它可以在make找到的目录中搜索前提条件。

    这是用 类似$^ 之类的自动变量来实现的(*note Automatic Variables::)。例如,$^的值是规则中所有前提条件的列表,其中也包括它们所在目录的名字,而$@是目的的名字。因此:

    foo.o : foo.c
    cc -c $(CFLAGS) $^ -o $@

    (变量 CFLAGS 已存在,所以你可以用隐式规则来为C编译指定此标志;我们为一贯性考虑而是用它,所以它将影响到所有的C 编译; *note Variables Used by Implicit Rules: Implicit Variables)

    通常,前提条件中也包括头文件,你可能不想在片段中提及此事。自动变量 $< 指代第一个前提条件:

    VPATH = src:../headers

    foo.o : foo.c defs.h hack.h
    cc -c $(CFLAGS) $< -o $@

    后文待续

  • 相关阅读:
    【PHP内存泄漏案例】PHP对象递归引用造成内存泄漏
    【总结】/etc/rc.d/rc.local 与 /etc/profile .bash_profile .bashrc 文件执行顺序
    MySQL数据类型
    PHP通用分页(Pager)类
    【抚琴煮酒】我们的网站压力究竟在哪里?
    Linux/CentOS 服务安装/卸载,开机启动chkconfig命令详解|如何让MySQL、Apache开机启动?
    /etc/rc.d/rc与/etc/rc.d/init.d的关系
    PHP正则表达式30分钟入门教程
    数学之路-分布式计算-disco(4)
    数据库中存储日期的字段类型究竟应该用varchar还是datetime ?
  • 原文地址:https://www.cnblogs.com/gaojian/p/2694089.html
Copyright © 2020-2023  润新知