makefile

Makefile笔记

[TOC]

foreach

  1. 格式
    1
    $(foreach n, source, operation(n))
    source里的变量用n表示,采用operation对n进行操作,返回操作后的结果
  2. 例子
    1
    2
    foo=a b c
    target=$(foreach n, $(foo), $(i).cpp)
    得到的target= a.cpp b.cpp c.cpp

wrod, i

  1. 格式

    1
    $(word i, source)

    返回source里的第i个变量

  2. 例子

    1
    2
    foo=a b c
    target=$(word 2, $(foo))
    得到的target=b

filter

  1. 格式

    1
    $$(filter method, source)

    使用method方法对source进行筛选,返回符合source里符合method筛选后的结果

  2. 例子

    1
    2
    foo=a.cpp b.h c.c
    target=$$(filter %.cpp, $(foo))
    得到的target=a.cpp

ifeq

  1. 格式

    1
    2
    3
    ifeq(a,b)
    function
    endif

    如果ifeq的条件满足,就执行function

  2. 例子

    1
    2
    3
    4
    foo=a b c
    ifeq($(foo),)
    xx
    endif
    不会执行xx的内容,因为foo不等于

call

  1. 格式

    1
    $(call function, param1, param2,... )

    调用函数function,并且为该函数传入参数param1, etc

  2. 例子

    1
    2
    reverse =  $(2) $(1)
    target = $(call reverse,a,b)

    得到的target=b a

template

  1. 格式

    1
    $(word i, source)

    返回source里的第i个变量

  2. 例子

    1
    2
    foo=a b c
    target=$(word 2, $(foo))
    得到的target=b