美文网首页
makefile cheatsheet

makefile cheatsheet

作者: 右中 | 来源:发表于2018-11-28 20:09 被阅读0次

    https://devhints.io/makefile
    很像shell的语法,如#表示注释
    但还是有些区别的,如a = val的等号两边是可以有空格的
    详细信息参照makefile 节选

    Assignment

    uglify = $(uglify)        # assignment
    compressor := $(uglify)   # lazy assignment
    prefix ?= /usr/local      # safe assignment
    

    Magic variables

    out.o: src.c src.h
      $@   # "out.o" (target)
      $<   # "src.c" (first prerequisite)
      $^   # "src.c src.h" (all prerequisites)
    
    %.o: %.c
      $*   # the 'stem' with which an implicit rule matches ("foo" in "foo.c")
    
    also:
      $+   # prerequisites (all, with duplication)
      $?   # prerequisites (new ones)
      $|   # prerequisites (order-only?)
    
      $(@D) # target directory
    

    Find files

    js_files  := $(wildcard test/*.js)
    all_files := $(shell find images -name "*")
    

    Includes

    -include foo.make
    

    Conditionals

    foo: $(objects)
    ifeq ($(CC),gcc)
            $(CC) -o foo $(objects) $(libs_for_gcc)
    else
            $(CC) -o foo $(objects) $(normal_libs)
    endif
    

    相关文章

      网友评论

          本文标题:makefile cheatsheet

          本文链接:https://www.haomeiwen.com/subject/qgnzqqtx.html