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 文件的重新创建。

    后文待续

  • 相关阅读:
    P1041 传染病控制(dfs)
    洛谷P1040 加分二叉树(树形dp)
    微信支付移动开发
    UVA
    Android开源框架ViewPageIndicator和ViewPager实现Tab导航
    Android Application Digital Signatures
    android:怎样在TextView实现图文混排
    python无私有成员变量
    unity3D游戏开发实战原创视频讲座系列11之相扑游戏开发并公布到WinWP8
    MFC:Win32-Dll及MFC-Dll编写调用
  • 原文地址:https://www.cnblogs.com/gaojian/p/2692672.html
Copyright © 2011-2022 走看看