zoukankan      html  css  js  c++  java
  • GNU make manual 翻译(八十四)

    继续翻译

    4.4.1 Wildcard Examples                        
    -----------------------                        
                            
    Wildcards can be used in the recipe of a rule, where they are expanded by the shell.  For example, here is a rule to delete all the object files: 
         clean:                        
                 rm -f *.o                        
                            
       Wildcards are also useful in the prerequisites of a rule.  With the following rule in the makefile, `make print' will print all the `.c' files that have changed since the last time you printed them:                        
                            
         print: *.c                        
                 lpr -p $?                        
                 touch print                        
                            
    This rule uses `print' as an empty target file; see *note Empty Target Files to Record Events: Empty Targets.  (The automatic variable `$?' is used to print only those files that have changed; see *note Automatic Variables::.) 
                            
       Wildcard expansion does not happen when you define a variable. 
    Thus, if you write this:                        
                            
         objects = *.o                        
                            
    then the value of the variable `objects' is the actual string `*.o'.However, if you use the value of `objects' in a target or prerequisite, wildcard expansion will take place there.  If you use the value of `objects' in a recipe, the shell may perform wildcard expansion when the recipe runs.  To set `objects' to the expansion, instead use:              
         objects := $(wildcard *.o) 
    *Note Wildcard Function::.                        

    4.4.1 通配符例子 
    -----------------------
    通配符可以被使用在规则的片段中,在此时它们被shell所解释/展开。例如,这里有一个删除所有目标文件的规则:
    clean:
      rm -f *.o

    通配符在一个规则的前提条件中也是很有用的。通过makefile的下列例子,

    make print 会打印出所有自从上次打印后改变的.c 文件:

    print: *.c
      lpr -p $?
      touch print

    这个规则 使用 print 作为空的目的文件;参见 *note Empty Target Files to Record Events: Empty Targets (自动变量 $ 用来只打印出那些发生了改变的文件;参见 *note Automatic Variables::)

    在你定义一个变量的时候,通配符扩展不会发生,所以,如果你这么写:

    objects = *.o

    那么变量 objects 的值会是真的字符串 '*.o'。但是如果你是在目的或者前提条件中使用 objects的值,通配符扩展还是会发生。如果你在片段里使用 objects 的值,当片段运行时,通配符扩展会发生。

    如果想要把 objects 设置在扩展里,应当使用:

    objects := $(wildcard *.o)

    *Note Wildcard Function::.

    后文待续

  • 相关阅读:
    如何在一个页面后面随机跳转到多个链接地址Math.floor()和Math.random()
    thinkphp中volist标签
    PHP中删除数组空值的方法
    PHP实现四种基本排序算法
    如何解决自动加载与模板中(如Smarty)的自动加载冲突的问题
    GD库常用函数
    内网最小化安装CentOS后,想安装ISO文件中的包怎么办呢?
    Elasticsearch插件安装
    python类的反射使用方法
    python类的继承
  • 原文地址:https://www.cnblogs.com/gaojian/p/2693202.html
Copyright © 2011-2022 走看看