GNU make - functions
  B2JnUQ2gB4jN 2023年11月02日 52 0


$(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)))

#

Less Important Miscellaneous Functions

1. $(strip text)

2. $(origin variable)

3. $(warning text)

#

eval and value

#

Hooking Functions

#

Passing Parameters


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  4crWjjQBqFOy   2023年11月13日   23   0   0 javamavenandroid
  wpWn7yzs0oKF   2023年11月13日   29   0   0 javaapacheHDFS
B2JnUQ2gB4jN