zoukankan      html  css  js  c++  java
  • 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 $@

    后文待续

  • 相关阅读:
    《大道至简》3
    《大道至简》2
    《大道至简》1
    [转]python 中的字符串连接
    [转]Eclipse Python插件 PyDev 使用
    [转]Windows下python环境变量配置
    [转]aircrack-ng破解教程
    [转]Java获取当前路径
    [转]java程序打包成jar,图片文件问题
    关于2013,致2014
  • 原文地址:https://www.cnblogs.com/gaojian/p/2694089.html
Copyright © 2011-2022 走看看