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

       Consider an example where your targets are to be placed in a separate directory, and that directory might not exist before `make' is run.  Inthis situation, you want the directory to be created before any targets are placed into it but, because the timestamps on directories change whenever a file is added, removed, or renamed, we certainly don't want to rebuild all the targets whenever the directory's timestamp changes.
       One way to manage this is with order-only prerequisites: make the 
    directory an order-only prerequisite on all the targets:                        
                            
         OBJDIR := objdir                        
         OBJS := $(addprefix $(OBJDIR)/,foo.o bar.o baz.o)                        
                            
         $(OBJDIR)/%.o : %.c                        
                 $(COMPILE.c) $(OUTPUT_OPTION) $<                        
                            
         all: $(OBJS)                        
                            
         $(OBJS): | $(OBJDIR)                        
                            
         $(OBJDIR):                        
                 mkdir $(OBJDIR)                        
                            
       Now the rule to create the `objdir' directory will be run, if needed, before any `.o' is built, but no `.o' will be built because the `objdir' directory timestamp changed. 

    考虑一个例子,你的目的可以放置到一个独立的目录,这个目录可能在make 运行时尚不存在。在这种场合下,你可能在任何目的被放入此目录前去创建它们,但是由于目录上的时间戳会因文件的增加移动或删除而变化,我们肯定不想在目录时间戳发生变化时去重新建立所有目的文件。

    管理此种问题的一个办法就是使用 order-only 前提条件: 使此目录成为所有目的的前提条件:

    OBJDIR := objdir
    OBJS := $(addprefix $(OBJDIR)/,foo.o bar.o baz.o)

    $(OBJDIR)/%.o : %.c
    $(COMPILE.c) $(OUTPUT_OPTION) $<

    all: $(OBJS)

    $(OBJS): | $(OBJDIR)

    $(OBJDIR):
    mkdir $(OBJDIR)

    现在如果有需要,在任何.o 文件被构建之前,创建 objdir 的规则会运行。但是目录时间戳的改变不会再导致 .o 文件的重新创建。

    后文待续

  • 相关阅读:
    Gradle在大型Java项目上的应用
    Spring MVC 构建入门级 Web 应用程序
    大公司最喜欢问的Java集合类面试题
    在Java中正确使用注释
    Java的wait(), notify()和notifyAll()使用心得
    Java中HashMap和TreeMap的区别深入理解
    初识PGM图片
    VS2013报错 error MSB8031解决方法
    matconvnet在MATLAB2013配置过程中遇到的问题
    配置VLFeat-0.9.20+MATLAB2013a
  • 原文地址:https://www.cnblogs.com/gaojian/p/2692672.html
Copyright © 2011-2022 走看看