$(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 :=
(filter−out
(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)))