• [skill][makefile] makefile 常用内容记录


    其实,makefile有点复杂。

    文档看了又看,还是要经常翻,做个记录备忘 :)

    1.  隐含命令 implicit rules

      与 implicit rule 相对应的有 pattern rules 和 suffix rules

    Compiling C programs
    n.o is made automatically from n.c with a recipe of the form ‘$(CC) $(CPPFLAGS) $(CFLAGS) -c’.
    
    Compiling C++ programs
    n.o is made automatically from n.cc, n.cpp, or n.C with a recipe of the form ‘$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c’. 
    We encourage you to use the suffix ‘.cc’ for C++ source files instead of ‘.C’.
    Linking a single object file
    n is made automatically from n.o by running the linker (usually called ld) via the C compiler. The precise recipe 
    used is ‘$(CC) $(LDFLAGS) n.o $(LOADLIBES) $(LDLIBS)’. This rule does the right thing for a simple program with only one source file. It will also do the right thing
    if there are multiple object files (presumably coming from various other source files), one of which has a name
    matching that of the executable file. Thus, x: y.o z.o when x.c, y.c and z.c all exist will execute: cc
    -c x.c -o x.o cc -c y.c -o y.o cc -c z.c -o z.o cc x.o y.o z.o -o x rm -f x.o rm -f y.o rm -f z.o In more complicated cases, such as when there is no object file whose name derives from the executable file name,
    you must write an explicit recipe for linking.
    CFLAGS
    Extra flags to give to the C compiler.
    
    CXXFLAGS
    Extra flags to give to the C++ compiler.
    
    CPPFLAGS
    Extra flags to give to the C preprocessor and programs that use it (the C and Fortran compilers).
    
    LDFLAGS
    Extra flags to give to compilers when they are supposed to invoke the linker, ‘ld’, such as -L. 
    Libraries (-lfoo) should be added to the LDLIBS variable instead. LDLIBS Library flags or names given to compilers when they are supposed to invoke the linker, ‘ld’.
    LOADLIBES
    is a deprecated (but still supported) alternative to LDLIBS. Non-library linker flags,
    such as -L, should go in the LDFLAGS variable.

      Canceling Implicit Rules

    定义一个空的 recipe 就可以取消隐含命令:

    %.o : %.s

    生成 *.o 的隐式命令,就被取消了。

    2. 更新所有目标文件

      以前是这样的: 先 make clean 然后 make。现在我们这样   make -B

    ‘-B’
    ‘--always-make’
    Consider all targets out-of-date. GNU make proceeds to consider targets and their prerequisites using 
    the normal algorithms; however, all targets so considered are always remade regardless of the status
    of their prerequisites. To avoid infinite recursion, if MAKE_RESTARTS (see Other Special Variables)
    is set to a number greater than 0 this option is disabled when considering whether to remake
    makefiles (see How Makefiles Are Remade).

    3.  使用隐含规则的时候,make,只会打印如下信息:

      由于项目工程makefile有好多自定义内容,也许此段内容有错误。

    [root@okk msre_engine]# make -B
      CC     ee_re_util.o
      CC     ee_pcre.o
      CC     mt_rand.o
      CC     utils.o
      CC     ruledb.o

      可是,我们有时候需要看编译参数。我还不知道怎么打印,即使用--debug也不打印。

      但是,可以用dry-run来临时解决这个问题。就是只打印不执行的意思。

    ‘-n’
    ‘--just-print’
    ‘--dry-run’
    ‘--recon’
    Print the recipe that would be executed, but do not execute it (except in certain circumstances). See Instead of 
    Executing Recipes.
  • 相关阅读:
    房地产电话销售资料
    为什么要买二手房,不买一手房
    三句话教你买对房子!买到好房子的都祝福哥三年内赚两个亿!
    如何建立与客户之间的信赖与友谊!和客户电话聊天时会出现那些突发障碍!客户到底想要找什么样的房子?
    技术帖:砖混、砖木、钢混、板楼、塔楼、框架、框架剪力墙等概念之区别优劣
    Redhat 企业版 LINUX AS5.0 下载地址
    写代码如坐禅:你是哪一类程序员
    VMware Workstation 8正式版下载+密钥序列号
    在线修改图片尺寸缩放网站(完美解决图片过大无法上传问题)
    程序员编程需要多少个小时?
  • 原文地址:https://www.cnblogs.com/hugetong/p/6952171.html
Copyright © 2020-2023  润新知