Function in Makefile
Function in Makefile
Call function
$( ) or ${ }
example1:
$(subst a, b, $(x))
example2:
comma := ,
empty :=
space := $(empty)$(empty)
foo := a b c
bar := $(subst $(space), $(comma), $(foo))
In example2, the program will change foo from “a b c” to “a,b,c”.
String Function
function name
functon
prototype
subst
Replace with in
$(subst ,,)
patsubst
Replace with
$(patst ,,)
strip
Delete space character at the begin or end of
$(strip )
findstring
Find in
$(findstring ,)
filter
Return words followed the in
$(filter ,)
filter-out
Return words not followed the\pattern> in
$(filter-out ,>)
sort
Sort the words in according to the ascending
$(sort )
word
Get the word from by . is ordinal number.
$(word ,)
wordlist
Take the multiple words out of from to
$(wordlist ,,)
words
Return the quantity of word in
$(word )
firstword
Return the firt word in
$(firtword ) example :
override CFLAGS += $(patsubst %,-I%,$(subst :, ,$(VPATH)))
# VPATH := src:../headers
ret_val : -Isrc -I../headers
File Name Manipulation Function
function name
function
prototype
dir
Return the directory string. If no directory, return ./
$(dir )
notdir
Return the file name without the directory string
$(notdir )
suffix
Return the suffix in
$(suffix )
basename
Return the prefix in
$(basename )
addsuffix
Append the postfix to
$(addsuffix , )
addprefix
Add a prefix before every word in
$(addprefix , )
join
Concatenated strings in and according to the ordinal number
$(join ,)
Others Function
foreach
$( ) or ${ }
example1:
$(subst a, b, $(x))
example2:
comma := ,
empty :=
space := $(empty)$(empty)
foo := a b c
bar := $(subst $(space), $(comma), $(foo))
example :
override CFLAGS += $(patsubst %,-I%,$(subst :, ,$(VPATH)))
# VPATH := src:../headers
ret_val : -Isrc -I../headers
foreach function is similar to for in Unix.The prototype is
$(foreach ,,)
Each time, var take a parameter from , then var will be processed by the regulation defined in . The return string will be split by . For example:
names := a b c d
files := $(foreach n,$(names),$(n).o)
# $(files) := a.o b.o c.o d.o
if
The prototype of function if :
$(if ,,)
If is true, return value is . If not, return .
call
$(call ,,,...,)
example :
# Makefile file
reverse = $(1) $(2)
foo = $(call reverse,a,b)
tryCall:
@echo $(foo)
origin
$(origin )
is the name of variable. Using the ‘$’ is not suitable here. Origin will return different value for different type of variale.
return value
means
undefine
has never be defined!
default
is a default variable.
environment
is a environment varible.
file
was defined in a Makefile file.
command file
was defined by command line.
override
was redefined by overide command.
automatic
is a autimatic variable.
shell
Using the shell command and return what the shell command return.
contents := $(shell cat foo)
files := $(shell echo *.c)
error
$(error )
Print the error info and exit.
$(warning )
Print the warning info and comtinues execution.
Reference
How to write makefile Chen Hao
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Golang 테스트 커버리지를 효율적으로 확인이전 기사에서 테스트 커버리지를 쉘 스크립트로 만들고 그것을 실행하여 확인했습니다. 이번 이를 Dockerfile과 Makefile에 정리해 보다 테스트 커버리지를 확인하기 쉽게 한 메모. 멀티 스테이지 빌드의 st...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.