3

[草稿]Makefile学习

 2 years ago
source link: https://cndaqiang.github.io/2020/12/02/makefile/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

[草稿]Makefile学习

  • 换行\
  • 注释用#
  • 默认依赖default: [label]
  • 系统命令前不加@会把命令也输出到屏幕,加@不会输出到屏幕
  • 变量以最终的定义为准
  • 执行命令必须用Tab键,使用空格替换Tab会报错 *** missing separator. Stop.
default: main test
main:
	@echo main $(OBJ)

OBJ= \
obj1 \
obj2 

test:
	@echo test $(OBJ)
OBJ = None
(python37) cndaqiang@mac makefile$ make
main None
test, None
OBJ= \
obj1 \
obj2 

default: main
main:
	@echo $(OBJ)

https://www.cnblogs.com/wanqieddy/archive/2011/09/21/2184257.html

= 是最基本的赋值
:= 是覆盖之前的值
?= 是如果没有被赋值过就赋予等号后面的值
+= 是添加等号后面的值

删除已有元素

https://cloud.tencent.com/developer/ask/62201

default: main
main:
	@echo main $(OBJ)

OBJ= \
obj1 \
obj2 


TMPVAR := $(OBJ)
OBJ = $(filter-out obj1, $(TMPVAR))

排序/删除重复元素

w = z z x x y c x 1 2 \
234 

w += 1 2

cnq:
	@echo $w
	@echo $d

d=$(sort $(w))
(python37) cndaqiang@mac tmp$ make
z z x x y c x 1 2 234 1 2
1 2 234 c x y z

本文首发于我的博客@cndaqiang.
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK