GNU Make Note

本文深入探讨了GNUMake的基本概念及高级用法,包括phony target的定义与使用、核心自动变量的功能、VPATH指令的应用场景、条件判断语法、宏定义等,并介绍了内置函数的运用技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

GNU Make C1-C2

  1. Makefile: Top-down style

  2. phony target makes reusing commond easily. Sytanx: .PHONY: target_name

  3. 6 Core Automatic Variable for avoiding code dupliaction: p21

    1. $@ target file name

    2. $% filename of an archive member specification

    3. $< filename of first prerequisite

    4. $? prerequisites newer than target

    5. $^ all prerequisites without duplicates

    6. $+ all prerequisites

    7. $* stem of target filename (the portion before the suffix)

  4. VPATH, specify the paths to find prerequisites. if any files has same file name in different paths. It returns first one.  vpath directive is a more precise way to achieve the goal- find right source files: vpath %.c src

  5. suffix rules. .cpp.o :  ==  %.o:%.cpp

  6. implicit ruls: default settings of make. make -p    to print.

  7. useful special target aside PHONY

  8. d file stand for dependency. We use d file when we when to add dependencies without recompile source code. (need to talk to forest)

  9. use ar commond to update achieve file. sample:  ar rv xxx.a  xx.o r means replace. the object in the achieve flle was updated. or,  we can just replace one objet by: xx.a(xx.o):xx.o

C3-C4

  1. two varible type: expand(:=) and recursively expanded variable(=).

  2. ?= set varible only it hasn's been set early

  3. def macro to reuse commonds:

    • define free-space(macro name)

    • xxxxxx

    • endef

  4. condition

    • ifeq $(a), $(b)

    • do something

    • endif

  5. function can be passed arguments. Like bash, $1 stand for the first argument

  6. built in functions(texts):

    1. filter. $(filter pattern... ,text)   sample: $(ui_library): $(filter ui/%.o,$(objects))

    2. replacement. $(patsubst search-pattern,replace-pattern,text)

    3. return text list sparated by whitespace: $(words text)

    4. return nth word in text. $(word n,text)

    5. return a range of texts. $(wordlist start,end,text)

  7. built in function(file name):

    1. return non-duplicated sorted list. sort  $(sort list)

    2. $(shell command)

    3. $(wildcard ./*.cpp) wildcard for file name

    4. $(dir) and $(notdir) handle with path

    5. $(basename) and $(suffix) handle with file name

    6. $(addsuffix) append suffix to names

  8. built in functions(flow control

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

page 74

转载于:https://my.oschina.net/edwardpku/blog/106876

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值