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 $@

    后文待续

  • 相关阅读:
    模拟4题解 T3奇袭
    模拟4题解 T1礼物
    [BZOJ2427][HAOI2010]软件安装
    [BZOJ4010][HNOI2015]菜肴制作
    deeplearning 重要调参参数分析
    论文阅读笔记八:SegNet: A Deep Convolutional Encoder-Decoder Architecture for Image Segmentation (IEEE2017)
    向github上提交自己的project
    c++ 链表基础功能实现
    c++实现 给定直角停车位两个点,求取剩余两点坐标。
    matlab转c++代码实现(主要包含C++ std::vector,std::pair学习,包含数组与常数相乘,数组相加减,将数组拉成一维向量,图片的读入等内容)
  • 原文地址:https://www.cnblogs.com/gaojian/p/2694089.html
Copyright © 2011-2022 走看看