• 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::.

    后文待续

  • 相关阅读:
    WindowsPhone7 经典3D游戏《刺客信条》评测
    WPF案例 — 展厅触摸屏展示系统
    Silverlight三维柱状图3D饼图的Silverlight图表组件案例
    应聘Silverlight讲师(全职或兼职均可)
    WPF案例之生产线控制器管理系统
    Silverlight 5 Beta 版发布日期确定
    《银光志Silverlight 3.0开发详解与最佳实践》发行第三版总销量过万册
    微软Silverlight5发布会提供线上注册
    Silverlight WebOS案例2.0版本(基于Silverlight4开发的Web操作系统)
    长年承接WP7游戏和WP7软件外包
  • 原文地址:https://www.cnblogs.com/gaojian/p/2693202.html
Copyright © 2020-2023  润新知