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

    继续翻译

    4.4.2 Pitfalls of Using Wildcards                        
    ---------------------------------  
    Now here is an example of a naive way of using wildcard expansion, that
    does not do what you would intend.  Suppose you would like to say that 
    the executable file `foo' is made from all the object files in the
    directory, and you write this:                        
                            
         objects = *.o                        
                            
         foo : $(objects)                        
                 cc -o foo $(CFLAGS) $(objects)                        
                            
    The value of `objects' is the actual string `*.o'.  Wildcard expansion happens in the rule for `foo', so that each _existing_ `.o' file becomes a prerequisite of `foo' and will be recompiled if necessary.  
                            
       But what if you delete all the `.o' files?  When a wildcard matches no files, it is left as it is, so then `foo' will depend on the oddly-named file `*.o'.  Since no such file is likely to exist, `make' will give you an error saying it cannot figure out how to make `*.o'. This is not what you want!                        
                            
       Actually it is possible to obtain the desired result with wildcard expansion, but you need more sophisticated techniques, including the `wildcard' function and string substitution.  *Note The Function `wildcard': Wildcard Function.  
                            
       Microsoft operating systems (MS-DOS and MS-Windows) use backslashes 
    to separate directories in pathnames, like so:   
           c:\foo\bar\baz.c                        
                            
       This is equivalent to the Unix-style `c:/foo/bar/baz.c' (the `c:' part is the so-called drive letter).  When `make' runs on these  systems, it supports backslashes as well as the Unix-style forward slashes in pathnames.  However, this support does _not_ include the wildcard expansion, where backslash is a quote character.  Therefore, you _must_ use Unix-style slashes in these cases.                

    4.4.2 使用通配符的陷阱

    ---------------------------------

    Now here is an example of a naive way of using wildcard expansion,

    现在有一个以自然而然地方式使用通配符扩展的例子,但是给出的却不是你想要的结果。      
    设想一下,你希望从目录下所有的.o 文件中生成 可执行程序 foo。你写了如下的代码:

    objects = *.o

    foo : $(objects)
    cc -o foo $(CFLAGS) $(objects)

    objects 的值是真正的字符串 *.o。通配符扩展发生在 foo 的规则李,因此 每一个已经存在的 .o 文件成为 foo 的前提条件,当有需要的时候,将会被重新编译。

    但是当你删除所有的.o文件,会发生什么? 当通配符找不到匹配的文件,它将就此保留下来,所以 foo 就会依赖于一个拥有奇怪名字 *.o 的文件。由于没有此文件存在,make 将会告诉你一个错误信息表明无法生成 *.o , 这可不是你想要的!

    事实上,想要获得预想的 通配符扩展的结果,也是可能的。但是你需要更加复杂的技术,包括 wildcard函数和 字符串切割。 *Note The Function 'wildcard': Wildcard Function

    Microsoft 操作系统(MS-DOS 和 MS-Windows) 使用反斜线来分隔目录路径名,类似于:

    c:\foo\bar\baz.c

    这等价于 Unix 下的 c:/foo/bar/baz.c (c:部分是驱动器字母)。当 make 在这样的系统上运行时,它既支持反斜线也支持Unix形式的斜线。 但是这种支持并不包括 通配符扩展,此时反斜线是一个 需要放在引号中的字符。因此,遇到通配符的时候,你必须用Unix 格式。

    后文待续

  • 相关阅读:
    MySQL binlog中 format_desc event格式解析
    位bit和字节Byte
    MySQL利用mysqlbinlog模拟增量恢复
    mysqldump参数 --master-data详解
    开启MySQL二进制日志
    设置花里胡哨的Xshell字体与背景颜色(超全)
    Python操作MySQL数据库
    给定一个由括号([{)]}其中之一或多个组成的字符串判断是否符合左右括号成对标准,不同括号可任意嵌套
    给定一个字符串str,将str中连续两个字符为a的字符替换为b(一个或连续超过多个字符a则不替换)
    不使用局部变量和for循环或其它循环打印出如m=19,n=2結果为2 4 8 16 16 8 4 2形式的串
  • 原文地址:https://www.cnblogs.com/gaojian/p/2693366.html
Copyright © 2011-2022 走看看