GNU make - functions

$(function-name arg1 [, argn ])

#

String Functions

1. $(filter pattern…,text)

words := he the hen other the%
get-the:
@echo he matches: (filterhe, (words))
@echo %he matches: (filter (words))
@echo he% matches: (filterhe (words))
@echo %he% matches: (filter (words))

2. $(filter-out pattern… , text), 和 filter函数相反

all_source := count_words.c counter.c lexer.l counter.h lexer.h
to_compile := (filterout (all_source))
get-source:
@echo source file: $(to_compile)

3. $(findstring string , text)

find-tree:
# PWD=(PWD)   # PWD 是环境变量  
    #
(findstring /home/nfs/book/admin, $(PWD))

4. $(subst search-string , replace-string , text)

sources := count_words.c counter.c lexer.c
objects := (subst.c,.o, (sources))
get-subst:
@echo $(objects)

5. $(patsubst search-pattern , replace-pattern , text)

SOURCES = (wildcard.c)OBJS= (patsubst %.c, %.o, (SOURCES))  
get-words:  
    # OBJS IS:
(OBJS)

6. $(words text)

This returns the number of words in text .

CURRENT_PATH := (subst/,, (HOME))
words:
# (CURRENTPATH)@echoMyHOMEpathhas (words $(CURRENT_PATH)) directories.

7. $(word n , text)

This returns the nth word in text .

version_list := (subst.,, (MAKE_VERSION))
minor_version := (word2, (version_list))
get-minor_version:
# (version_list)  
    # MAKE_VERSION’s minor version is:
(minor_version)

8. $(firstword text)

major_version := (firstword (version_list))

9. $(wordlist start , end , text)

$(call uid_gid, user-name)

uid_gid = (wordlist3,4, (subst :, , (shell grep "^1:” /etc/passwd)))

#

Important Miscellaneous Functions

1. $(sort list)

2. $(shell command)

stdout := (shellechonormalmessage)stderr:= (shell echo error message 1>&2)
RELEASE_TAR := mpwm- (shelldate+RELEASETAR2:= (shell date +mpwm-%F.tar.gz)
START_TIME := (shelldate)CURRENTTIME= (shell date)
shell-value:
# (START_TIME)  
    #
(stdout)
# (stderr)  
    #
(RELEASE_TAR)
# (RELEASE_TAR2)  
    #
(CURRENT_TIME)

#

Filename Functions

1. $(wildcard pattern…)

dot-emacs-exists := (wildcard /.emacs)sources:= (wildcard .c .h)

2. $(dir list…)

给定一个路径字符串path,返回目录部分

source-dirs := (sort (dir /home/nfs/test/myfile.c))
get-dirs:
@echo “the dir is:” $(source-dirs)

3. $(notdir name…)

example 1

给定一个路径字符串path,返回文件名的部分

source-file := (sort (notdir /home/nfs/test/myfile.c))
get-file:
@echo “the filename is:” $(source-file)

example 2

$(call get-java-class-name, file-name)

get-java-class-name = (notdir (subst .java,, 1))javaname= (call get-java-class-name, SDGenerator.java)
get-java:
@echo “java class name is: ” $(javaname)

4. $(suffix name…)

$(call same-suffix, file-list)

same-suffix = (filter1 (words (sort (suffix $1))))

5. $(basename name…)

6. $(addsuffix suffix , name…)

7. $(addprefix prefix , name…)

8. $(join prefix-list , suffix-list)

#

Flow Control

1. $(if condition , then-part , else-part)

(if (filter (MAKEVERSION),3.80),, (error This makefile requires GNU make version 3.80.))

2. $(error text )

3. $(foreach variable , list , body)

VARIABLE_LIST := SOURCES OBJECTS HOME
(foreachi, (VARIABLE_LIST), \
(if ( i),,  (shell echo $i has no value > /dev/stderr)))

#

Less Important Miscellaneous Functions

1. $(strip text)

2. $(origin variable)

3. $(warning text)

#

eval and value

#

Hooking Functions

#

Passing Parameters

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值