makefile中函数的使用

override var += -g                                      #通过命令行传递的参数,不能覆盖var的值
sources = f1.c f2.c
define hello
        @echo "test define"
        @echo "test define hello"
endef

test:foo
        $(call hello)                                   #调用define定义的hello语句块。 
        @echo "test"
foo:
        @echo "foo" 
        @echo $(var)                                    #make var=-v ==> -g -v
#函数使用
        @echo $(findstring a,a b c)                     # a $(findstring <find>,<in>) 
        @echo $(patsubst %/,%,test/foo/)                #test/foo
        @echo $(subst lh,LH, lhxlhx)                    #LHxLHx
        @echo $(strip  a b c   )                        #a b c 返回被去掉空格的字符串值
        @echo $(filter %.c %.s,f1.c f2.o f3.s)          #f1.c f3.s
        @echo $(filter-out %.c %.s,f1.c f2.o f3.s)       #f2.o
        @echo $(sort c1 a2 b3)                          #a2 b3 c1
        @echo $(word 2, lhx ai yll)                     #ai
        @echo $(wordlist 2, 3, lhx ai yll)              #ai yll
        @echo $(words lhx ai yll)                       #3
        @echo $(firstword lhx ai yll)                   #lhx
        @echo $(dir src/foo.c hacks)                    #src/ ./
        @echo $(notdir src/foo.c hacks)                 #foo.c hacks
        @echo $(suffix src/foo.c src-1.0/bar.c hacks)   #.c .c
        @echo $(basename src/foo.c src-1.0/bar.c hacks) #src/foo src-1.0/bar hacks
        @echo $(addsuffix .c,foo bar)                   #foo.c bar.c
        @echo $(addprefix src/,foo bar)                 #src/foo src/bar
        @echo $(join aaa bbb , 111 222 333)             #aaa111 bbb222 333
        @echo $(foreach n,a b c,$(n).o)                 #a.o b.o c.o
        @echo $(shell echo "hello")                     #hello
###@echo $(error error is test)                 #Makefile:34: *** error is test.  Stop.
        @echo $(sources:.c=.d)                          #f1.d f2.d  
posted @ 2021-01-28 15:42  刘大侠GG_B  阅读(80)  评论(0编辑  收藏  举报